+ outState.putStringArrayList(C.SEARCH_HISTORY, searchHistory);
+ }
+
+ private int getMatchLen(String search, Index.IndexEntry e) {
+ if (e == null) return 0;
+ for (int i = 0; i < search.length(); ++i) {
+ String a = search.substring(0, i + 1);
+ String b = e.token.substring(0, i + 1);
+ if (!a.equalsIgnoreCase(b))
+ return i;
+ }
+ return search.length();
+ }
+
+ private void dictionaryOpenFail(Exception e) {
+ Log.e(LOG, "Unable to load dictionary.", e);
+ if (dictRaf != null) {
+ indexAdapter = null;
+ setListAdapter(null);
+ try {
+ dictRaf.close();
+ } catch (IOException e1) {
+ Log.e(LOG, "Unable to close dictRaf.", e1);
+ }
+ dictRaf = null;
+ }
+ if (!isFinishing())
+ Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()),
+ Toast.LENGTH_LONG).show();
+ startActivity(DictionaryManagerActivity.getLaunchIntent(getApplicationContext()));
+ finish();
+ }
+
+ private void saveSearchHistory() {
+ final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
+ final SharedPreferences.Editor ed = prefs.edit();
+ for (int i = 0; i < searchHistory.size(); i++) {
+ ed.putString("history" + i, searchHistory.get(i));
+ }
+ ed.remove("history" + searchHistory.size());
+ ed.apply();
+ }
+
+ private void addToSearchHistory(String text) {
+ if (text == null || text.isEmpty()) return;
+ int exists = searchHistory.indexOf(text);
+ if (exists >= 0) searchHistory.remove(exists);
+ else if (searchHistory.size() >= MAX_SEARCH_HISTORY) searchHistory.remove(searchHistory.size() - 1);
+ searchHistory.add(0, text);
+ searchHistoryCursor = new MatrixCursor(new String[] {"_id", "search"});
+ for (int i = 0; i < searchHistory.size(); i++) {
+ final Object[] row = {i, searchHistory.get(i)};
+ searchHistoryCursor.addRow(row);
+ }
+ if (searchView.getSuggestionsAdapter().getCursor() != null) {
+ searchView.getSuggestionsAdapter().swapCursor(searchHistoryCursor);
+ searchView.getSuggestionsAdapter().notifyDataSetChanged();
+ }