]> 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 a1521fa2fecae8db0c4d9367576dc1812e97249d..5e251b7f234cc1c207fa9f1c79f3b591d808a04f 100644 (file)
@@ -18,7 +18,6 @@ import android.content.SharedPreferences;
 import android.graphics.Typeface;\r
 import android.os.Bundle;\r
 import android.os.Handler;\r
-import android.os.Vibrator;\r
 import android.preference.PreferenceManager;\r
 import android.text.ClipboardManager;\r
 import android.text.Editable;\r
@@ -27,16 +26,17 @@ import android.text.TextWatcher;
 import android.text.style.StyleSpan;\r
 import android.util.Log;\r
 import android.view.ContextMenu;\r
+import android.view.ContextMenu.ContextMenuInfo;\r
 import android.view.KeyEvent;\r
 import android.view.Menu;\r
 import android.view.MenuItem;\r
-import android.view.View;\r
-import android.view.ViewGroup;\r
-import android.view.ContextMenu.ContextMenuInfo;\r
 import android.view.MenuItem.OnMenuItemClickListener;\r
+import android.view.View;\r
 import android.view.View.OnClickListener;\r
+import android.view.ViewGroup;\r
 import android.view.inputmethod.InputMethodManager;\r
 import android.widget.AdapterView;\r
+import android.widget.AdapterView.AdapterContextMenuInfo;\r
 import android.widget.BaseAdapter;\r
 import android.widget.Button;\r
 import android.widget.EditText;\r
@@ -46,7 +46,6 @@ import android.widget.TableLayout;
 import android.widget.TableRow;\r
 import android.widget.TextView;\r
 import android.widget.Toast;\r
-import android.widget.AdapterView.AdapterContextMenuInfo;\r
 \r
 import com.hughes.android.dictionary.engine.Dictionary;\r
 import com.hughes.android.dictionary.engine.Index;\r
@@ -81,8 +80,10 @@ 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
+  //private Vibrator vibrator = null;\r
   \r
   public DictionaryActivity() {\r
   }\r
@@ -128,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
@@ -138,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
@@ -159,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
@@ -219,7 +230,7 @@ public class DictionaryActivity extends ListActivity {
         getString(R.string.wordListFileDefault)));\r
     saveOnlyFirstSubentry = prefs.getBoolean(getString(R.string.saveOnlyFirstSubentryKey), false);\r
     if (prefs.getBoolean(getString(R.string.vibrateOnFailedSearchKey), true)) {\r
-      vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);\r
+      // vibrator = (Vibrator) getSystemService(Context.VIBRATOR_SERVICE);\r
     }\r
     Log.d(LOG, "wordList=" + wordList + ", saveOnlyFirstSubentry=" + saveOnlyFirstSubentry);\r
   }\r
@@ -238,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
@@ -293,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
@@ -439,7 +454,7 @@ public class DictionaryActivity extends ListActivity {
     final Index.IndexEntry searchResult = searchOperation.searchResult;\r
     Log.d(LOG, "searchFinished: " + searchOperation + ", searchResult=" + searchResult);\r
 \r
-    jumpToRow(searchResult.longestPrefix.startRow);\r
+    jumpToRow(searchResult.startRow);\r
     \r
 //    if (!searchResult.success) {\r
 //      if (vibrator != null) {\r
@@ -598,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