]> gitweb.fperrin.net Git - Dictionary.git/blob - src/com/hughes/android/dictionary/DictionaryActivity.java
eb907f8150ef02bf9ed4af80d4f6209b77af8918
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
1 // Copyright 2011 Google Inc. All Rights Reserved.\r
2 //\r
3 // Licensed under the Apache License, Version 2.0 (the "License");\r
4 // you may not use this file except in compliance with the License.\r
5 // You may obtain a copy of the License at\r
6 //\r
7 //     http://www.apache.org/licenses/LICENSE-2.0\r
8 //\r
9 // Unless required by applicable law or agreed to in writing, software\r
10 // distributed under the License is distributed on an "AS IS" BASIS,\r
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
12 // See the License for the specific language governing permissions and\r
13 // limitations under the License.\r
14 \r
15 package com.hughes.android.dictionary;\r
16 \r
17 import java.io.File;\r
18 import java.io.FileWriter;\r
19 import java.io.IOException;\r
20 import java.io.PrintWriter;\r
21 import java.io.RandomAccessFile;\r
22 import java.text.SimpleDateFormat;\r
23 import java.util.Arrays;\r
24 import java.util.Collections;\r
25 import java.util.Date;\r
26 import java.util.LinkedHashSet;\r
27 import java.util.List;\r
28 import java.util.Random;\r
29 import java.util.Set;\r
30 import java.util.concurrent.Executor;\r
31 import java.util.concurrent.Executors;\r
32 import java.util.concurrent.ThreadFactory;\r
33 import java.util.concurrent.atomic.AtomicBoolean;\r
34 import java.util.regex.Matcher;\r
35 import java.util.regex.Pattern;\r
36 \r
37 import android.app.Dialog;\r
38 import android.app.ListActivity;\r
39 import android.content.Context;\r
40 import android.content.Intent;\r
41 import android.content.SharedPreferences;\r
42 import android.graphics.Typeface;\r
43 import android.net.Uri;\r
44 import android.os.Bundle;\r
45 import android.os.Handler;\r
46 import android.preference.PreferenceManager;\r
47 import android.text.ClipboardManager;\r
48 import android.text.Editable;\r
49 import android.text.Selection;\r
50 import android.text.Spannable;\r
51 import android.text.TextWatcher;\r
52 import android.text.method.LinkMovementMethod;\r
53 import android.text.style.StyleSpan;\r
54 import android.util.Log;\r
55 import android.util.TypedValue;\r
56 import android.view.ContextMenu;\r
57 import android.view.ContextMenu.ContextMenuInfo;\r
58 import android.view.KeyEvent;\r
59 import android.view.Menu;\r
60 import android.view.MenuItem;\r
61 import android.view.MenuItem.OnMenuItemClickListener;\r
62 import android.view.MotionEvent;\r
63 import android.view.View;\r
64 import android.view.View.OnClickListener;\r
65 import android.view.View.OnLongClickListener;\r
66 import android.view.ViewGroup;\r
67 import android.view.WindowManager;\r
68 import android.view.inputmethod.InputMethodManager;\r
69 import android.widget.AdapterView;\r
70 import android.widget.AdapterView.AdapterContextMenuInfo;\r
71 import android.widget.BaseAdapter;\r
72 import android.widget.Button;\r
73 import android.widget.EditText;\r
74 import android.widget.ImageView;\r
75 import android.widget.LinearLayout;\r
76 import android.widget.ListAdapter;\r
77 import android.widget.ListView;\r
78 import android.widget.TableLayout;\r
79 import android.widget.TableRow;\r
80 import android.widget.TextView;\r
81 import android.widget.Toast;\r
82 \r
83 import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;\r
84 import com.hughes.android.dictionary.engine.Dictionary;\r
85 import com.hughes.android.dictionary.engine.EntrySource;\r
86 import com.hughes.android.dictionary.engine.Index;\r
87 import com.hughes.android.dictionary.engine.Index.IndexEntry;\r
88 import com.hughes.android.dictionary.engine.PairEntry;\r
89 import com.hughes.android.dictionary.engine.PairEntry.Pair;\r
90 import com.hughes.android.dictionary.engine.RowBase;\r
91 import com.hughes.android.dictionary.engine.TokenRow;\r
92 import com.hughes.android.dictionary.engine.TransliteratorManager;\r
93 import com.hughes.android.util.IntentLauncher;\r
94 import com.hughes.android.util.NonLinkClickableSpan;\r
95 \r
96 public class DictionaryActivity extends ListActivity {\r
97 \r
98   static final String LOG = "QuickDic";\r
99 \r
100   private String initialSearchText;\r
101 \r
102   DictionaryApplication application;\r
103   File dictFile = null;\r
104   RandomAccessFile dictRaf = null;\r
105   Dictionary dictionary = null;\r
106   int indexIndex = 0;\r
107   Index index = null;\r
108   List<RowBase> rowsToShow = null;  // if not null, just show these rows.\r
109   \r
110   // package for test.\r
111   final Handler uiHandler = new Handler();\r
112   private final Executor searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {\r
113     @Override\r
114     public Thread newThread(Runnable r) {\r
115       return new Thread(r, "searchExecutor");\r
116     }\r
117   });\r
118   private SearchOperation currentSearchOperation = null;\r
119 \r
120   C.Theme theme = C.Theme.LIGHT;\r
121   int fontSizeSp;\r
122   EditText searchText;\r
123   Button langButton;\r
124 \r
125   // Never null.\r
126   private File wordList = null;\r
127   private boolean saveOnlyFirstSubentry = false;\r
128   private boolean clickOpensContextMenu = false;\r
129 \r
130   // Visible for testing.\r
131   ListAdapter indexAdapter = null;\r
132   \r
133   final SearchTextWatcher searchTextWatcher = new SearchTextWatcher();\r
134   \r
135   /**\r
136    * For some languages, loading the transliterators used in this search takes\r
137    * a long time, so we fire it up on a different thread, and don't invoke it\r
138    * from the main thread until it's already finished once.\r
139    */\r
140   private volatile boolean indexPrepFinished = false;\r
141 \r
142 \r
143 \r
144   public DictionaryActivity() {\r
145   }\r
146   \r
147   public static Intent getLaunchIntent(final File dictFile, final int indexIndex, final String searchToken) {\r
148     final Intent intent = new Intent();\r
149     intent.setClassName(DictionaryActivity.class.getPackage().getName(), DictionaryActivity.class.getName());\r
150     intent.putExtra(C.DICT_FILE, dictFile.getPath());\r
151     intent.putExtra(C.INDEX_INDEX, indexIndex);\r
152     intent.putExtra(C.SEARCH_TOKEN, searchToken);\r
153     return intent;\r
154   }\r
155   \r
156   @Override\r
157   protected void onSaveInstanceState(final Bundle outState) {\r
158     super.onSaveInstanceState(outState);\r
159     Log.d(LOG, "onSaveInstanceState: " + searchText.getText().toString());\r
160     outState.putInt(C.INDEX_INDEX, indexIndex);\r
161     outState.putString(C.SEARCH_TOKEN, searchText.getText().toString());\r
162   }\r
163 \r
164   @Override\r
165   protected void onRestoreInstanceState(final Bundle outState) {\r
166     super.onRestoreInstanceState(outState);\r
167     Log.d(LOG, "onRestoreInstanceState: " + outState.getString(C.SEARCH_TOKEN));\r
168     onCreate(outState);\r
169   }\r
170 \r
171   @Override\r
172   public void onCreate(Bundle savedInstanceState) { \r
173     setTheme(((DictionaryApplication)getApplication()).getSelectedTheme().themeId);\r
174 \r
175     Log.d(LOG, "onCreate:" + this);\r
176     super.onCreate(savedInstanceState);\r
177 \r
178     application = (DictionaryApplication) getApplication();\r
179     theme = application.getSelectedTheme();\r
180     \r
181     final Intent intent = getIntent();\r
182     dictFile = new File(intent.getStringExtra(C.DICT_FILE));\r
183     \r
184     try {\r
185       final String name = application.getDictionaryName(dictFile.getName());\r
186       this.setTitle("QuickDic: " + name);\r
187       dictRaf = new RandomAccessFile(dictFile, "r");\r
188       dictionary = new Dictionary(dictRaf); \r
189     } catch (Exception e) {\r
190       Log.e(LOG, "Unable to load dictionary.", e);\r
191       if (dictRaf != null) {\r
192         try {\r
193           dictRaf.close();\r
194         } catch (IOException e1) {\r
195           Log.e(LOG, "Unable to close dictRaf.", e1);\r
196         }\r
197         dictRaf = null;\r
198       }\r
199       Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()), Toast.LENGTH_LONG).show();\r
200       startActivity(DictionaryManagerActivity.getLaunchIntent());\r
201       finish();\r
202       return;\r
203     }\r
204     indexIndex = intent.getIntExtra(C.INDEX_INDEX, 0);\r
205     if (savedInstanceState != null) {\r
206       indexIndex = savedInstanceState.getInt(C.INDEX_INDEX, indexIndex);\r
207     }\r
208     indexIndex %= dictionary.indices.size();\r
209     Log.d(LOG, "Loading index " + indexIndex);\r
210     index = dictionary.indices.get(indexIndex);\r
211     setListAdapter(new IndexAdapter(index));\r
212     \r
213     // Pre-load the collators.\r
214     new Thread(new Runnable() {\r
215       public void run() {\r
216         final long startMillis = System.currentTimeMillis();\r
217         try {\r
218           TransliteratorManager.init(new TransliteratorManager.Callback() {\r
219             @Override\r
220             public void onTransliteratorReady() {\r
221               uiHandler.post(new Runnable() {\r
222                 @Override\r
223                 public void run() {\r
224                   onSearchTextChange(searchText.getText().toString());\r
225                 }\r
226               });\r
227             }\r
228           });\r
229           \r
230           for (final Index index : dictionary.indices) {\r
231             final String searchToken = index.sortedIndexEntries.get(0).token;\r
232             final IndexEntry entry = index.findExact(searchToken);\r
233             if (!searchToken.equals(entry.token)) {\r
234               Log.e(LOG, "Couldn't find token: " + searchToken + ", " + entry.token);\r
235             }\r
236           }\r
237           indexPrepFinished = true;\r
238         } catch (Exception e) {\r
239           Log.w(LOG, "Exception while prepping.  This can happen if dictionary is closed while search is happening.");\r
240         }\r
241           Log.d(LOG, "Prepping indices took:"\r
242               + (System.currentTimeMillis() - startMillis));\r
243       }\r
244     }).start();\r
245     \r
246     final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);\r
247     \r
248     final String fontSize = prefs.getString(getString(R.string.fontSizeKey), "14");\r
249     try {\r
250       fontSizeSp = Integer.parseInt(fontSize.trim());\r
251     } catch (NumberFormatException e) {\r
252       fontSizeSp = 12;\r
253     }\r
254 \r
255     setContentView(R.layout.dictionary_activity);\r
256     searchText = (EditText) findViewById(R.id.SearchText);\r
257     searchText.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);\r
258     \r
259     langButton = (Button) findViewById(R.id.LangButton);\r
260     \r
261     searchText.requestFocus();\r
262     searchText.addTextChangedListener(searchTextWatcher);\r
263     String text = "";\r
264     if (savedInstanceState != null) {\r
265       text = savedInstanceState.getString(C.SEARCH_TOKEN);\r
266       if (text == null) {\r
267         text = "";\r
268       }\r
269     }\r
270     setSearchText(text, true);\r
271     Log.d(LOG, "Trying to restore searchText=" + text);\r
272     \r
273     final Button clearSearchTextButton = (Button) findViewById(R.id.ClearSearchTextButton);\r
274     clearSearchTextButton.setOnClickListener(new OnClickListener() {\r
275       public void onClick(View v) {\r
276         onClearSearchTextButton(clearSearchTextButton);\r
277       }\r
278     });\r
279     clearSearchTextButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(\r
280         getString(R.string.showClearSearchTextButtonKey), true) ? View.VISIBLE\r
281         : View.GONE);\r
282     \r
283     final Button langButton = (Button) findViewById(R.id.LangButton);\r
284     langButton.setOnClickListener(new OnClickListener() {\r
285       public void onClick(View v) {\r
286         onLanguageButton();\r
287       }\r
288     });\r
289     langButton.setOnLongClickListener(new OnLongClickListener() {\r
290       @Override\r
291       public boolean onLongClick(View v) {\r
292         onLanguageButtonLongClick(v.getContext());\r
293         return true;\r
294       }\r
295     });\r
296     updateLangButton();\r
297     \r
298     final Button upButton = (Button) findViewById(R.id.UpButton);\r
299     upButton.setOnClickListener(new OnClickListener() {\r
300       public void onClick(View v) {\r
301         onUpDownButton(true);\r
302       }\r
303     });\r
304     final Button downButton = (Button) findViewById(R.id.DownButton);\r
305     downButton.setOnClickListener(new OnClickListener() {\r
306       public void onClick(View v) {\r
307         onUpDownButton(false);\r
308       }\r
309     });\r
310 \r
311    getListView().setOnItemSelectedListener(new ListView.OnItemSelectedListener() {\r
312       @Override\r
313       public void onItemSelected(AdapterView<?> adapterView, View arg1, final int position,\r
314           long id) {\r
315         if (!searchText.isFocused()) {\r
316           if (!isFiltered()) {\r
317             final RowBase row = (RowBase) getListAdapter().getItem(position);\r
318             Log.d(LOG, "onItemSelected: " + row.index());\r
319             final TokenRow tokenRow = row.getTokenRow(true);\r
320             searchText.setText(tokenRow.getToken());\r
321           }\r
322         }\r
323       }\r
324 \r
325       @Override\r
326       public void onNothingSelected(AdapterView<?> arg0) {\r
327       }\r
328     });\r
329 \r
330     // ContextMenu.\r
331     registerForContextMenu(getListView());\r
332 \r
333     // Prefs.\r
334     wordList = new File(prefs.getString(getString(R.string.wordListFileKey),\r
335         getString(R.string.wordListFileDefault)));\r
336     saveOnlyFirstSubentry = prefs.getBoolean(getString(R.string.saveOnlyFirstSubentryKey), false);\r
337     clickOpensContextMenu = prefs.getBoolean(getString(R.string.clickOpensContextMenuKey), false);\r
338     //if (prefs.getBoolean(getString(R.string.vibrateOnFailedSearchKey), true)) {\r
339       // vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);\r
340     //}\r
341     Log.d(LOG, "wordList=" + wordList + ", saveOnlyFirstSubentry=" + saveOnlyFirstSubentry);\r
342     \r
343     setDictionaryPrefs(this, dictFile, indexIndex, searchText.getText().toString());\r
344   }\r
345   \r
346   @Override\r
347   protected void onResume() {\r
348     super.onResume();\r
349     if (PreferenceActivity.prefsMightHaveChanged) {\r
350       PreferenceActivity.prefsMightHaveChanged = false;\r
351       finish();\r
352       startActivity(getIntent());\r
353     }\r
354     if (initialSearchText != null) {\r
355       setSearchText(initialSearchText, true);\r
356     }\r
357   }\r
358   \r
359   @Override\r
360   protected void onPause() {\r
361     super.onPause();\r
362   }\r
363   \r
364   private static void setDictionaryPrefs(final Context context,\r
365       final File dictFile, final int indexIndex, final String searchToken) {\r
366     final SharedPreferences.Editor prefs = PreferenceManager.getDefaultSharedPreferences(context).edit();\r
367     prefs.putString(C.DICT_FILE, dictFile.getPath());\r
368     prefs.putInt(C.INDEX_INDEX, indexIndex);\r
369     prefs.putString(C.SEARCH_TOKEN, searchToken);\r
370     prefs.commit();\r
371   }\r
372 \r
373   @Override\r
374   protected void onDestroy() {\r
375     super.onDestroy();\r
376     if (dictRaf == null) {\r
377       return;\r
378     }\r
379 \r
380     final SearchOperation searchOperation = currentSearchOperation;\r
381     currentSearchOperation = null;\r
382 \r
383     // Before we close the RAF, we have to wind the current search down.\r
384     if (searchOperation != null) {\r
385       Log.d(LOG, "Interrupting search to shut down.");\r
386       currentSearchOperation = null;\r
387       searchOperation.interrupted.set(true);\r
388     }\r
389     \r
390     try {\r
391       Log.d(LOG, "Closing RAF.");\r
392       dictRaf.close();\r
393     } catch (IOException e) {\r
394       Log.e(LOG, "Failed to close dictionary", e);\r
395     }\r
396     dictRaf = null;\r
397   }\r
398 \r
399   // --------------------------------------------------------------------------\r
400   // Buttons\r
401   // --------------------------------------------------------------------------\r
402 \r
403   private void onClearSearchTextButton(final Button clearSearchTextButton) {\r
404     setSearchText("", true);\r
405     Log.d(LOG, "Trying to show soft keyboard.");\r
406     final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);\r
407     manager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);\r
408   }\r
409   \r
410   void updateLangButton() {\r
411 //    final LanguageResources languageResources = Language.isoCodeToResources.get(index.shortName);\r
412 //    if (languageResources != null && languageResources.flagId != 0) {\r
413 //      langButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, languageResources.flagId, 0);\r
414 //    } else {\r
415 //      langButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
416       langButton.setText(index.shortName);\r
417 //    }\r
418   }\r
419 \r
420   void onLanguageButton() {\r
421     if (currentSearchOperation != null) {\r
422       currentSearchOperation.interrupted.set(true);\r
423       currentSearchOperation = null;\r
424     }\r
425     changeIndexGetFocusAndResearch((indexIndex + 1)% dictionary.indices.size());\r
426   }\r
427   \r
428   void onLanguageButtonLongClick(final Context context) {\r
429     final Dialog dialog = new Dialog(context);\r
430     dialog.setContentView(R.layout.select_dictionary_dialog);\r
431     dialog.setTitle(R.string.selectDictionary);\r
432 \r
433     final List<DictionaryInfo> installedDicts = ((DictionaryApplication)getApplication()).getUsableDicts();\r
434     ListView listView = (ListView) dialog.findViewById(android.R.id.list);\r
435     listView.setAdapter(new BaseAdapter() {\r
436       @Override\r
437       public View getView(int position, View convertView, ViewGroup parent) {\r
438         final LinearLayout result = new LinearLayout(parent.getContext());\r
439         final DictionaryInfo dictionaryInfo = getItem(position);\r
440           final Button button = new Button(parent.getContext());\r
441           final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);\r
442           button.setText(name);\r
443           final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(), getLaunchIntent(application.getPath(dictionaryInfo.uncompressedFilename), 0, "")) {\r
444             @Override\r
445             protected void onGo() {\r
446               dialog.dismiss();\r
447               DictionaryActivity.this.finish();\r
448             };\r
449           };\r
450           button.setOnClickListener(intentLauncher);\r
451           \r
452           final LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);\r
453           layoutParams.width = 0;\r
454           layoutParams.weight = 1.0f;\r
455           button.setLayoutParams(layoutParams);\r
456 \r
457           result.addView(button);\r
458         return result;\r
459       }\r
460       \r
461       @Override\r
462       public long getItemId(int position) {\r
463         return position;\r
464       }\r
465       \r
466       @Override\r
467       public DictionaryInfo getItem(int position) {\r
468         return installedDicts.get(position);\r
469       }\r
470       \r
471       @Override\r
472       public int getCount() {\r
473         return installedDicts.size();\r
474       }\r
475     });\r
476     \r
477     dialog.show();\r
478   }\r
479 \r
480 \r
481   private void changeIndexGetFocusAndResearch(final int newIndex) {\r
482     indexIndex = newIndex;\r
483     index = dictionary.indices.get(indexIndex);\r
484     indexAdapter = new IndexAdapter(index);\r
485     Log.d(LOG, "changingIndex, newLang=" + index.longName);\r
486     setListAdapter(indexAdapter);\r
487     updateLangButton();\r
488     searchText.requestFocus();  // Otherwise, nothing may happen.\r
489     onSearchTextChange(searchText.getText().toString());\r
490     setDictionaryPrefs(this, dictFile, indexIndex, searchText.getText().toString());\r
491   }\r
492   \r
493   void onUpDownButton(final boolean up) {\r
494     if (isFiltered()) {\r
495       return;\r
496     }\r
497     final int firstVisibleRow = getListView().getFirstVisiblePosition();\r
498     final RowBase row = index.rows.get(firstVisibleRow);\r
499     final TokenRow tokenRow = row.getTokenRow(true);\r
500     final int destIndexEntry;\r
501     if (up) {\r
502       if (row != tokenRow) {\r
503         destIndexEntry = tokenRow.referenceIndex;\r
504       } else {\r
505         destIndexEntry = Math.max(tokenRow.referenceIndex - 1, 0);\r
506       }\r
507     } else {\r
508       // Down\r
509       destIndexEntry = Math.min(tokenRow.referenceIndex + 1, index.sortedIndexEntries.size());\r
510     }\r
511     final Index.IndexEntry dest = index.sortedIndexEntries.get(destIndexEntry);\r
512     Log.d(LOG, "onUpDownButton, destIndexEntry=" + dest.token);\r
513     searchText.removeTextChangedListener(searchTextWatcher);\r
514     searchText.setText(dest.token);\r
515     if (searchText.getLayout() != null) {\r
516       // Surprising, but this can otherwise crash sometimes...\r
517       Selection.moveToRightEdge(searchText.getText(), searchText.getLayout());\r
518     }\r
519     jumpToRow(index.sortedIndexEntries.get(destIndexEntry).startRow);\r
520     searchText.addTextChangedListener(searchTextWatcher);\r
521   }\r
522 \r
523   // --------------------------------------------------------------------------\r
524   // Options Menu\r
525   // --------------------------------------------------------------------------\r
526   \r
527   final Random random = new Random();\r
528   \r
529   @Override\r
530   public boolean onCreateOptionsMenu(final Menu menu) {\r
531     application.onCreateGlobalOptionsMenu(this, menu);\r
532 \r
533     {\r
534       final MenuItem randomWord = menu.add(getString(R.string.randomWord));\r
535       randomWord.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
536         public boolean onMenuItemClick(final MenuItem menuItem) {\r
537           final String word = index.sortedIndexEntries.get(random.nextInt(index.sortedIndexEntries.size())).token;\r
538           setSearchText(word, true);\r
539           return false;\r
540         }\r
541       });\r
542     }\r
543     \r
544     {\r
545       final MenuItem dictionaryList = menu.add(getString(R.string.dictionaryManager));\r
546       dictionaryList.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
547         public boolean onMenuItemClick(final MenuItem menuItem) {\r
548           startActivity(DictionaryManagerActivity.getLaunchIntent());\r
549           finish();\r
550           return false;\r
551         }\r
552       });\r
553     }\r
554 \r
555     {\r
556       final MenuItem aboutDictionary = menu.add(getString(R.string.aboutDictionary));\r
557       aboutDictionary.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
558         public boolean onMenuItemClick(final MenuItem menuItem) {\r
559           final Context context = getListView().getContext();\r
560           final Dialog dialog = new Dialog(context);\r
561           dialog.setContentView(R.layout.about_dictionary_dialog);\r
562           final TextView textView = (TextView) dialog.findViewById(R.id.text);\r
563 \r
564           final String name = application.getDictionaryName(dictFile.getName());\r
565           dialog.setTitle(name);\r
566           \r
567           final StringBuilder builder = new StringBuilder();\r
568           final DictionaryInfo dictionaryInfo = dictionary.getDictionaryInfo();\r
569           dictionaryInfo.uncompressedBytes = dictFile.length();\r
570           if (dictionaryInfo != null) {\r
571             builder.append(dictionaryInfo.dictInfo).append("\n\n");\r
572             builder.append(getString(R.string.dictionaryPath, dictFile.getPath())).append("\n");\r
573             builder.append(getString(R.string.dictionarySize, dictionaryInfo.uncompressedBytes)).append("\n");\r
574             builder.append(getString(R.string.dictionaryCreationTime, dictionaryInfo.creationMillis)).append("\n");\r
575             for (final IndexInfo indexInfo : dictionaryInfo.indexInfos) {\r
576               builder.append("\n");\r
577               builder.append(getString(R.string.indexName, indexInfo.shortName)).append("\n");\r
578               builder.append(getString(R.string.mainTokenCount, indexInfo.mainTokenCount)).append("\n");\r
579             }\r
580             builder.append("\n");\r
581             builder.append(getString(R.string.sources)).append("\n");\r
582             for (final EntrySource source : dictionary.sources) {\r
583               builder.append(getString(R.string.sourceInfo, source.getName(), source.getNumEntries())).append("\n");\r
584             }\r
585           }\r
586 //          } else {\r
587 //            builder.append(getString(R.string.invalidDictionary));\r
588 //          }\r
589           textView.setText(builder.toString());\r
590           \r
591           dialog.show();\r
592           final WindowManager.LayoutParams layoutParams = new WindowManager.LayoutParams();\r
593           layoutParams.width = WindowManager.LayoutParams.FILL_PARENT;\r
594           layoutParams.height = WindowManager.LayoutParams.FILL_PARENT;\r
595           dialog.getWindow().setAttributes(layoutParams);\r
596           return false;\r
597         }\r
598       });\r
599     }\r
600 \r
601     return true;\r
602   }\r
603 \r
604 \r
605   // --------------------------------------------------------------------------\r
606   // Context Menu + clicks\r
607   // --------------------------------------------------------------------------\r
608 \r
609   @Override\r
610   public void onCreateContextMenu(ContextMenu menu, View v,\r
611       ContextMenuInfo menuInfo) {\r
612     AdapterContextMenuInfo adapterContextMenuInfo = (AdapterContextMenuInfo) menuInfo;\r
613     final RowBase row = (RowBase) getListAdapter().getItem(adapterContextMenuInfo.position);\r
614 \r
615     final MenuItem addToWordlist = menu.add(getString(R.string.addToWordList, wordList.getName()));\r
616     addToWordlist.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
617       public boolean onMenuItemClick(MenuItem item) {\r
618         onAppendToWordList(row);\r
619         return false;\r
620       }\r
621     });\r
622 \r
623     final MenuItem copy = menu.add(android.R.string.copy);\r
624     copy.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
625       public boolean onMenuItemClick(MenuItem item) {\r
626         onCopy(row);\r
627         return false;\r
628       }\r
629     });\r
630     \r
631     if (selectedSpannableText != null) {\r
632       final String selectedText = selectedSpannableText;\r
633       final MenuItem searchForSelection = menu.add(getString(R.string.searchForSelection, selectedSpannableText));\r
634       searchForSelection.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
635         public boolean onMenuItemClick(MenuItem item) {\r
636           int indexToUse = -1;\r
637           for (int i = 0; i < dictionary.indices.size(); ++i) {\r
638             final Index index = dictionary.indices.get(i);\r
639             if (indexPrepFinished) {\r
640               System.out.println("Doing index lookup: on " + selectedText);\r
641               final IndexEntry indexEntry = index.findExact(selectedText);\r
642               if (indexEntry != null) {\r
643                 final TokenRow tokenRow = index.rows.get(indexEntry.startRow).getTokenRow(false);\r
644                 if (tokenRow != null && tokenRow.hasMainEntry) {\r
645                   indexToUse = i;\r
646                   break;\r
647                 }\r
648               }\r
649             } else {\r
650               Log.w(LOG, "Skipping findExact on index " + index.shortName);\r
651             }\r
652           }\r
653           if (indexToUse == -1) {\r
654             indexToUse = selectedSpannableIndex;\r
655           }\r
656           final boolean changeIndex = indexIndex != indexToUse;\r
657           setSearchText(selectedText, !changeIndex);  // If we're not changing index, we have to triggerSearch.\r
658           if (changeIndex) {\r
659             changeIndexGetFocusAndResearch(indexToUse);\r
660           }\r
661           // Give focus back to list view because typing is done.\r
662           getListView().requestFocus();\r
663           return false;\r
664         }\r
665       });\r
666     }\r
667     \r
668 \r
669   }\r
670   \r
671   @Override\r
672   protected void onListItemClick(ListView l, View v, int row, long id) {\r
673     defocusSearchText();\r
674     if (clickOpensContextMenu && dictRaf != null) {\r
675       openContextMenu(v);\r
676     }\r
677   }\r
678   \r
679   void onAppendToWordList(final RowBase row) {\r
680     defocusSearchText();\r
681     \r
682     final StringBuilder rawText = new StringBuilder();\r
683     rawText.append(\r
684         new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date()))\r
685         .append("\t");\r
686     rawText.append(index.longName).append("\t");\r
687     rawText.append(row.getTokenRow(true).getToken()).append("\t");\r
688     rawText.append(row.getRawText(saveOnlyFirstSubentry));\r
689     Log.d(LOG, "Writing : " + rawText);\r
690 \r
691     try {\r
692       wordList.getParentFile().mkdirs();\r
693       final PrintWriter out = new PrintWriter(\r
694           new FileWriter(wordList, true));\r
695       out.println(rawText.toString());\r
696       out.close();\r
697     } catch (IOException e) {\r
698       Log.e(LOG, "Unable to append to " + wordList.getAbsolutePath(), e);\r
699       Toast.makeText(this, getString(R.string.failedAddingToWordList, wordList.getAbsolutePath()), Toast.LENGTH_LONG);\r
700     }\r
701     return;\r
702   }\r
703   \r
704   /**\r
705    * Called when user clicks outside of search text, so that they can start\r
706    * typing again immediately.\r
707    */\r
708   void defocusSearchText() {\r
709     //Log.d(LOG, "defocusSearchText");\r
710     // Request focus so that if we start typing again, it clears the text input.\r
711     getListView().requestFocus();\r
712     \r
713     // Visual indication that a new keystroke will clear the search text.\r
714     searchText.selectAll();\r
715   }\r
716 \r
717   void onCopy(final RowBase row) {\r
718     defocusSearchText();\r
719 \r
720     Log.d(LOG, "Copy, row=" + row);\r
721     final StringBuilder result = new StringBuilder();\r
722     result.append(row.getRawText(false));\r
723     final ClipboardManager clipboardManager = (ClipboardManager) getSystemService(Context.CLIPBOARD_SERVICE);\r
724     clipboardManager.setText(result.toString());\r
725     Log.d(LOG, "Copied: " + result);\r
726   }\r
727 \r
728   @Override\r
729   public boolean onKeyDown(final int keyCode, final KeyEvent event) {\r
730     if (event.getUnicodeChar() != 0) {\r
731       if (!searchText.hasFocus()) {\r
732         setSearchText("" + (char) event.getUnicodeChar(), true);\r
733       }\r
734       return true;\r
735     }\r
736     if (keyCode == KeyEvent.KEYCODE_BACK) {\r
737       Log.d(LOG, "Clearing dictionary prefs.");\r
738       // Pretend that we just autolaunched so that we won't do it again.\r
739       DictionaryManagerActivity.lastAutoLaunchMillis = System.currentTimeMillis();\r
740     }\r
741     if (keyCode == KeyEvent.KEYCODE_ENTER) {\r
742       Log.d(LOG, "Trying to hide soft keyboard.");\r
743       final InputMethodManager inputManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);\r
744       inputManager.hideSoftInputFromWindow(this.getCurrentFocus().getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);\r
745       return true;\r
746     }\r
747     return super.onKeyDown(keyCode, event);\r
748   }\r
749 \r
750   private void setSearchText(final String text, final boolean triggerSearch) {\r
751     if (!triggerSearch) {\r
752       getListView().requestFocus();\r
753     }\r
754     searchText.setText(text);\r
755     searchText.requestFocus();\r
756     if (searchText.getLayout() != null) {\r
757       // Surprising, but this can crash when you rotate...\r
758       Selection.moveToRightEdge(searchText.getText(), searchText.getLayout());\r
759     }\r
760     if (triggerSearch) {\r
761       onSearchTextChange(text);\r
762     }\r
763   }\r
764 \r
765 \r
766   // --------------------------------------------------------------------------\r
767   // SearchOperation\r
768   // --------------------------------------------------------------------------\r
769 \r
770   private void searchFinished(final SearchOperation searchOperation) {\r
771     if (searchOperation.interrupted.get()) {\r
772       Log.d(LOG, "Search operation was interrupted: " + searchOperation);\r
773       return;\r
774     }\r
775     if (searchOperation != this.currentSearchOperation) {\r
776       Log.d(LOG, "Stale searchOperation finished: " + searchOperation);\r
777       return;\r
778     }\r
779     \r
780     final Index.IndexEntry searchResult = searchOperation.searchResult;\r
781     Log.d(LOG, "searchFinished: " + searchOperation + ", searchResult=" + searchResult);\r
782 \r
783     currentSearchOperation = null;\r
784     uiHandler.postDelayed(new Runnable() {\r
785       @Override\r
786       public void run() {\r
787         if (currentSearchOperation == null) {\r
788           if (searchResult != null) {\r
789             if (isFiltered()) {\r
790               clearFiltered();\r
791             }\r
792             jumpToRow(searchResult.startRow);\r
793           } else if (searchOperation.multiWordSearchResult != null) {\r
794             // Multi-row search....\r
795             setFiltered(searchOperation);\r
796           } else {\r
797             throw new IllegalStateException("This should never happen.");\r
798           }\r
799         } else {\r
800           Log.d(LOG, "More coming, waiting for currentSearchOperation.");\r
801         }\r
802       }\r
803     }, 20);\r
804     \r
805   }\r
806   \r
807   private final void jumpToRow(final int row) {\r
808     setSelection(row);\r
809     getListView().setSelected(true);\r
810   }\r
811 \r
812   static final Pattern WHITESPACE = Pattern.compile("\\s+");\r
813   final class SearchOperation implements Runnable {\r
814     \r
815     final AtomicBoolean interrupted = new AtomicBoolean(false);\r
816     final String searchText;\r
817     List<String> searchTokens;  // filled in for multiWord.\r
818     final Index index;\r
819     \r
820     long searchStartMillis;\r
821 \r
822     Index.IndexEntry searchResult;\r
823     List<RowBase> multiWordSearchResult;\r
824     \r
825     boolean done = false;\r
826     \r
827     SearchOperation(final String searchText, final Index index) {\r
828       this.searchText = searchText.trim();\r
829       this.index = index;\r
830     }\r
831     \r
832     public String toString() {\r
833       return String.format("SearchOperation(%s,%s)", searchText, interrupted.toString());\r
834     }\r
835 \r
836     @Override\r
837     public void run() {\r
838       try {\r
839         searchStartMillis = System.currentTimeMillis();\r
840         final String[] searchTokenArray = WHITESPACE.split(searchText);\r
841         if (searchTokenArray.length == 1) {\r
842           searchResult = index.findInsertionPoint(searchText, interrupted);\r
843         } else {\r
844           searchTokens = Arrays.asList(searchTokenArray);\r
845           multiWordSearchResult = index.multiWordSearch(searchTokens, interrupted);\r
846         }\r
847         Log.d(LOG, "searchText=" + searchText + ", searchDuration="\r
848             + (System.currentTimeMillis() - searchStartMillis) + ", interrupted="\r
849             + interrupted.get());\r
850         if (!interrupted.get()) {\r
851           uiHandler.post(new Runnable() {\r
852             @Override\r
853             public void run() {            \r
854               searchFinished(SearchOperation.this);\r
855             }\r
856           });\r
857         }\r
858       } catch (Exception e) {\r
859         Log.e(LOG, "Failure during search (can happen during Activity close.");\r
860       } finally {\r
861         synchronized (this) {\r
862           done = true;\r
863           this.notifyAll();\r
864         }\r
865       }\r
866     }\r
867   }\r
868 \r
869   \r
870   // --------------------------------------------------------------------------\r
871   // IndexAdapter\r
872   // --------------------------------------------------------------------------\r
873 \r
874   final class IndexAdapter extends BaseAdapter {\r
875     \r
876     final Index index;\r
877     final List<RowBase> rows;\r
878     final Set<String> toHighlight;\r
879 \r
880     IndexAdapter(final Index index) {\r
881       this.index = index;\r
882       rows = index.rows;\r
883       this.toHighlight = null;\r
884     }\r
885 \r
886     IndexAdapter(final Index index, final List<RowBase> rows, final List<String> toHighlight) {\r
887       this.index = index;\r
888       this.rows = rows;\r
889       this.toHighlight = new LinkedHashSet<String>(toHighlight);\r
890     }\r
891 \r
892     @Override\r
893     public int getCount() {\r
894       return rows.size();\r
895     }\r
896 \r
897     @Override\r
898     public RowBase getItem(int position) {\r
899       return rows.get(position);\r
900     }\r
901 \r
902     @Override\r
903     public long getItemId(int position) {\r
904       return getItem(position).index();\r
905     }\r
906 \r
907     @Override\r
908     public TableLayout getView(int position, View convertView, ViewGroup parent) {\r
909       final TableLayout result;\r
910       if (convertView instanceof TableLayout) {\r
911         result = (TableLayout) convertView;\r
912         result.removeAllViews();\r
913       } else {\r
914         result = new TableLayout(parent.getContext());\r
915       }\r
916       final RowBase row = getItem(position);\r
917       if (row instanceof PairEntry.Row) {\r
918         return getView(position, (PairEntry.Row) row, parent, result);\r
919       } else if (row instanceof TokenRow) {\r
920         return getView((TokenRow) row, parent, result);\r
921       } else {\r
922         throw new IllegalArgumentException("Unsupported Row type: " + row.getClass());\r
923       }\r
924     }\r
925 \r
926     private TableLayout getView(final int position, PairEntry.Row row, ViewGroup parent, final TableLayout result) {\r
927       final PairEntry entry = row.getEntry();\r
928       final int rowCount = entry.pairs.size();\r
929       \r
930       final TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();\r
931       layoutParams.weight = 0.5f;\r
932       \r
933       for (int r = 0; r < rowCount; ++r) {\r
934         final TableRow tableRow = new TableRow(result.getContext());\r
935 \r
936         final TextView col1 = new TextView(tableRow.getContext());\r
937         final TextView col2 = new TextView(tableRow.getContext());\r
938 \r
939         // Set the columns in the table.\r
940         if (r > 0) {\r
941           final TextView bullet = new TextView(tableRow.getContext());\r
942           bullet.setText(" • ");\r
943           tableRow.addView(bullet);\r
944         }\r
945         tableRow.addView(col1, layoutParams);\r
946         final TextView margin = new TextView(tableRow.getContext());\r
947         margin.setText(" ");\r
948         tableRow.addView(margin);\r
949         if (r > 0) {\r
950           final TextView bullet = new TextView(tableRow.getContext());\r
951           bullet.setText(" • ");\r
952           tableRow.addView(bullet);\r
953         }\r
954         tableRow.addView(col2, layoutParams);\r
955         col1.setWidth(1);\r
956         col2.setWidth(1);\r
957         \r
958         // Set what's in the columns.\r
959 \r
960         final Pair pair = entry.pairs.get(r);\r
961         final String col1Text = index.swapPairEntries ? pair.lang2 : pair.lang1;\r
962         final String col2Text = index.swapPairEntries ? pair.lang1 : pair.lang2;\r
963         \r
964         col1.setText(col1Text, TextView.BufferType.SPANNABLE);\r
965         col2.setText(col2Text, TextView.BufferType.SPANNABLE);\r
966         \r
967         // Bold the token instances in col1.\r
968         final Set<String> toBold = toHighlight != null ? this.toHighlight : Collections.singleton(row.getTokenRow(true).getToken());\r
969         final Spannable col1Spannable = (Spannable) col1.getText();\r
970         for (final String token : toBold) {\r
971           int startPos = 0;\r
972           while ((startPos = col1Text.indexOf(token, startPos)) != -1) {\r
973             col1Spannable.setSpan(new StyleSpan(Typeface.BOLD), startPos,\r
974                 startPos + token.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);\r
975             startPos += token.length();\r
976           }\r
977         }\r
978         \r
979         createTokenLinkSpans(col1, col1Spannable, col1Text);\r
980         createTokenLinkSpans(col2, (Spannable) col2.getText(), col2Text);\r
981         \r
982         col1.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);\r
983         col2.setTextSize(TypedValue.COMPLEX_UNIT_SP, fontSizeSp);\r
984         // col2.setBackgroundResource(theme.otherLangBg);\r
985         \r
986         if (index.swapPairEntries) {\r
987           col2.setOnLongClickListener(textViewLongClickListenerIndex0);\r
988           col1.setOnLongClickListener(textViewLongClickListenerIndex1);\r
989         } else {\r
990           col1.setOnLongClickListener(textViewLongClickListenerIndex0);\r
991           col2.setOnLongClickListener(textViewLongClickListenerIndex1);\r
992         }\r
993         \r
994         result.addView(tableRow);\r
995       }\r
996 \r
997       // Because we have a Button inside a ListView row:\r
998       // http://groups.google.com/group/android-developers/browse_thread/thread/3d96af1530a7d62a?pli=1\r
999       result.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);\r
1000       result.setClickable(true);\r
1001       result.setFocusable(true);\r
1002       result.setLongClickable(true);\r
1003       result.setBackgroundResource(android.R.drawable.menuitem_background);\r
1004       result.setOnClickListener(new TextView.OnClickListener() {\r
1005         @Override\r
1006         public void onClick(View v) {\r
1007           DictionaryActivity.this.onListItemClick(getListView(), v, position, position);\r
1008         }\r
1009       });\r
1010 \r
1011       return result;\r
1012     }\r
1013 \r
1014     private TableLayout getView(TokenRow row, ViewGroup parent, final TableLayout result) {\r
1015       final Context context = parent.getContext();\r
1016       final TextView textView = new TextView(context);\r
1017       textView.setText(row.getToken());\r
1018       // Doesn't work:\r
1019       //textView.setTextColor(android.R.color.secondary_text_light);\r
1020       textView.setTextAppearance(context, theme.tokenRowFg);\r
1021       textView.setTextSize(TypedValue.COMPLEX_UNIT_SP, 5 * fontSizeSp / 4);\r
1022       \r
1023       final TableRow tableRow = new TableRow(result.getContext());\r
1024       tableRow.addView(textView);\r
1025       tableRow.setBackgroundResource(row.hasMainEntry ? theme.tokenRowMainBg : theme.tokenRowOtherBg);\r
1026       result.addView(tableRow);\r
1027       return result;\r
1028     }\r
1029     \r
1030   }\r
1031 \r
1032   static final Pattern CHAR_DASH = Pattern.compile("['\\p{L}\\p{M}\\p{N}]+");\r
1033 \r
1034   private void createTokenLinkSpans(final TextView textView, final Spannable spannable, final String text) {\r
1035     // Saw from the source code that LinkMovementMethod sets the selection!\r
1036     // http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/2.3.1_r1/android/text/method/LinkMovementMethod.java#LinkMovementMethod\r
1037     textView.setMovementMethod(LinkMovementMethod.getInstance());\r
1038     final Matcher matcher = CHAR_DASH.matcher(text);\r
1039     while (matcher.find()) {\r
1040       spannable.setSpan(new NonLinkClickableSpan(), matcher.start(), matcher.end(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);\r
1041     }\r
1042   }\r
1043   \r
1044 \r
1045   String selectedSpannableText = null;\r
1046   int selectedSpannableIndex = -1;\r
1047 \r
1048   @Override\r
1049   public boolean onTouchEvent(MotionEvent event) {\r
1050     selectedSpannableText = null;\r
1051     selectedSpannableIndex = -1;\r
1052     return super.onTouchEvent(event);\r
1053   }\r
1054 \r
1055   private class TextViewLongClickListener implements OnLongClickListener {\r
1056     final int index;\r
1057     \r
1058     private TextViewLongClickListener(final int index) {\r
1059       this.index = index;\r
1060     }\r
1061 \r
1062     @Override\r
1063     public boolean onLongClick(final View v) {\r
1064       final TextView textView = (TextView) v;\r
1065       final int start = textView.getSelectionStart();\r
1066       final int end = textView.getSelectionEnd();\r
1067       if (start >= 0 &&  end >= 0) {\r
1068         selectedSpannableText = textView.getText().subSequence(start, end).toString();\r
1069         selectedSpannableIndex = index;\r
1070       }\r
1071       return false;\r
1072     }\r
1073   }\r
1074   final TextViewLongClickListener textViewLongClickListenerIndex0 = new TextViewLongClickListener(0);\r
1075   final TextViewLongClickListener textViewLongClickListenerIndex1 = new TextViewLongClickListener(1);\r
1076   \r
1077 \r
1078   // --------------------------------------------------------------------------\r
1079   // SearchText\r
1080   // --------------------------------------------------------------------------\r
1081 \r
1082   void onSearchTextChange(final String text) {\r
1083     if ("thadolina".equals(text)) {\r
1084       final Dialog dialog = new Dialog(getListView().getContext());\r
1085       dialog.setContentView(R.layout.thadolina_dialog);\r
1086       dialog.setTitle("Ti amo, amore mio!");\r
1087       final ImageView imageView = (ImageView) dialog.findViewById(R.id.thadolina_image);\r
1088       imageView.setOnClickListener(new OnClickListener() {\r
1089         @Override\r
1090         public void onClick(View v) {\r
1091           final Intent intent = new Intent(Intent.ACTION_VIEW);\r
1092           intent.setData(Uri.parse("https://sites.google.com/site/cfoxroxvday/vday2012"));\r
1093           startActivity(intent);\r
1094         }\r
1095       });\r
1096       dialog.show();\r
1097     }\r
1098     if (dictRaf == null) {\r
1099       Log.d(LOG, "searchText changed during shutdown, doing nothing.");\r
1100       return;\r
1101     }\r
1102     if (!searchText.isFocused()) {\r
1103       Log.d(LOG, "searchText changed without focus, doing nothing.");\r
1104       return;\r
1105     }\r
1106     Log.d(LOG, "onSearchTextChange: " + text);    \r
1107     if (currentSearchOperation != null) {\r
1108       Log.d(LOG, "Interrupting currentSearchOperation.");\r
1109       currentSearchOperation.interrupted.set(true);\r
1110     }\r
1111     currentSearchOperation = new SearchOperation(text, index);\r
1112     searchExecutor.execute(currentSearchOperation);\r
1113   }\r
1114   \r
1115   private class SearchTextWatcher implements TextWatcher {\r
1116     public void afterTextChanged(final Editable searchTextEditable) {\r
1117       if (searchText.hasFocus()) {\r
1118         Log.d(LOG, "Search text changed with focus: " + searchText.getText());\r
1119         // If they were typing to cause the change, update the UI.\r
1120         onSearchTextChange(searchText.getText().toString());\r
1121       }\r
1122     }\r
1123 \r
1124     public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,\r
1125         int arg3) {\r
1126     }\r
1127 \r
1128     public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {\r
1129     }\r
1130   }\r
1131 \r
1132   // --------------------------------------------------------------------------\r
1133   // Filtered results.\r
1134   // --------------------------------------------------------------------------\r
1135 \r
1136   boolean isFiltered() {\r
1137     return rowsToShow != null;\r
1138   }\r
1139 \r
1140   void setFiltered(final SearchOperation searchOperation) {\r
1141     ((Button) findViewById(R.id.UpButton)).setEnabled(false);\r
1142     ((Button) findViewById(R.id.DownButton)).setEnabled(false);\r
1143     rowsToShow = searchOperation.multiWordSearchResult;\r
1144     setListAdapter(new IndexAdapter(index, rowsToShow, searchOperation.searchTokens));\r
1145   }\r
1146 \r
1147   void clearFiltered() {\r
1148     ((Button) findViewById(R.id.UpButton)).setEnabled(true);\r
1149     ((Button) findViewById(R.id.DownButton)).setEnabled(true);\r
1150     setListAdapter(new IndexAdapter(index));\r
1151     rowsToShow = null;\r
1152   }\r
1153 \r
1154 }\r