]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
go
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index 666339838b45c1455cd2819a000b40c4f9bfc610..5e251b7f234cc1c207fa9f1c79f3b591d808a04f 100644 (file)
@@ -80,6 +80,8 @@ public class DictionaryActivity extends ListActivity {
 \r
   // Visible for testing.\r
   ListAdapter indexAdapter = null;\r
+  \r
+  final SearchTextWatcher searchTextWatcher = new SearchTextWatcher();\r
 \r
   //private Vibrator vibrator = null;\r
   \r
@@ -127,6 +129,14 @@ public class DictionaryActivity extends ListActivity {
       dictionary = new Dictionary(dictRaf); \r
     } catch (Exception e) {\r
       Log.e(LOG, "Unable to load dictionary.", e);\r
+      if (dictRaf != null) {\r
+        try {\r
+          dictRaf.close();\r
+        } catch (IOException e1) {\r
+          Log.e(LOG, "Unable to close dictRaf.", e1);\r
+        }\r
+        dictRaf = null;\r
+      }\r
       Toast.makeText(this, getString(R.string.invalidDictionary, "", e.getMessage()), Toast.LENGTH_LONG);\r
       startActivity(DictionaryEditActivity.getIntent(dictIndex));\r
       finish();\r
@@ -137,7 +147,9 @@ public class DictionaryActivity extends ListActivity {
     searchExecutor.execute(new Runnable() {\r
       public void run() {\r
         final long startMillis = System.currentTimeMillis();\r
+        Log.d(LOG, "Constructing index for lang=" + index.sortLanguage.getSymbol());\r
         for (final Index index : dictionary.indices) {\r
+          Log.d(LOG, "Starting collator load for lang=" + index.sortLanguage.getSymbol());\r
           final com.ibm.icu.text.Collator c = index.sortLanguage.getCollator();\r
           if (c.compare("pre-print", "preppy") >= 0) {\r
             Log.e(LOG, c.getClass()\r
@@ -158,7 +170,7 @@ public class DictionaryActivity extends ListActivity {
     langButton = (Button) findViewById(R.id.LangButton);\r
     \r
     searchText.requestFocus();\r
-    searchText.addTextChangedListener(new SearchTextWatcher());\r
+    searchText.addTextChangedListener(searchTextWatcher);\r
     searchText.setText(prefs.getString(C.SEARCH_TOKEN, ""));\r
     Log.d(LOG, "Trying to restore searchText=" + searchText.getText());\r
     \r
@@ -237,6 +249,9 @@ public class DictionaryActivity extends ListActivity {
   @Override\r
   protected void onDestroy() {\r
     super.onDestroy();\r
+    if (dictRaf == null) {\r
+      return;\r
+    }\r
     setDictionaryPrefs(this, dictIndex, indexIndex, searchText.getText().toString());\r
     try {\r
       dictRaf.close();\r
@@ -292,11 +307,12 @@ public class DictionaryActivity extends ListActivity {
       // Down\r
       destIndexEntry = Math.min(tokenRow.referenceIndex + 1, index.sortedIndexEntries.size());\r
     }\r
-    \r
     final Index.IndexEntry dest = index.sortedIndexEntries.get(destIndexEntry);\r
-    searchText.setText(dest.token);\r
     Log.d(LOG, "onUpDownButton, destIndexEntry=" + dest.token);\r
-    //jumpToRow(index.sortedIndexEntries.get(destIndexEntry).startRow);\r
+    searchText.removeTextChangedListener(searchTextWatcher);\r
+    searchText.setText(dest.token);\r
+    jumpToRow(index.sortedIndexEntries.get(destIndexEntry).startRow);\r
+    searchText.removeTextChangedListener(searchTextWatcher);\r
   }\r
 \r
   // --------------------------------------------------------------------------\r
@@ -597,6 +613,7 @@ public class DictionaryActivity extends ListActivity {
 \r
   void onSearchTextChange(final String text) {\r
     if (!searchText.isFocused()) {\r
+      Log.d(LOG, "searchText changed without focus, doing nothing.");\r
       return;\r
     }\r
     Log.d(LOG, "onSearchTextChange: " + text);    \r