]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
Faster multi search, exact search, moved Normalization around.
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
index f79b13f49a8558c67cf4ef106fc507dc979d46ef..c8753a793d94ce9afcad858c4782c85164e757d1 100644 (file)
@@ -56,13 +56,13 @@ import android.view.ContextMenu.ContextMenuInfo;
 import android.view.KeyEvent;\r
 import android.view.Menu;\r
 import android.view.MenuItem;\r
-import android.view.WindowManager;\r
 import android.view.MenuItem.OnMenuItemClickListener;\r
 import android.view.MotionEvent;\r
 import android.view.View;\r
 import android.view.View.OnClickListener;\r
 import android.view.View.OnLongClickListener;\r
 import android.view.ViewGroup;\r
+import android.view.WindowManager;\r
 import android.view.inputmethod.InputMethodManager;\r
 import android.widget.AdapterView;\r
 import android.widget.AdapterView.AdapterContextMenuInfo;\r
@@ -79,8 +79,10 @@ import android.widget.Toast;
 \r
 import com.hughes.android.dictionary.DictionaryInfo.IndexInfo;\r
 import com.hughes.android.dictionary.engine.Dictionary;\r
+import com.hughes.android.dictionary.engine.EntrySource;\r
 import com.hughes.android.dictionary.engine.Index;\r
 import com.hughes.android.dictionary.engine.PairEntry;\r
+import com.hughes.android.dictionary.engine.Index.IndexEntry;\r
 import com.hughes.android.dictionary.engine.PairEntry.Pair;\r
 import com.hughes.android.dictionary.engine.RowBase;\r
 import com.hughes.android.dictionary.engine.TokenRow;\r
@@ -91,7 +93,9 @@ import com.hughes.android.util.NonLinkClickableSpan;
 public class DictionaryActivity extends ListActivity {\r
 \r
   static final String LOG = "QuickDic";\r
-  \r
+\r
+  private String initialSearchText;\r
+\r
   DictionaryApplication application;\r
   File dictFile = null;\r
   RandomAccessFile dictRaf = null;\r
@@ -125,6 +129,7 @@ public class DictionaryActivity extends ListActivity {
   \r
   final SearchTextWatcher searchTextWatcher = new SearchTextWatcher();\r
 \r
+\r
   public DictionaryActivity() {\r
   }\r
   \r
@@ -140,17 +145,21 @@ public class DictionaryActivity extends ListActivity {
   @Override\r
   protected void onSaveInstanceState(final Bundle outState) {\r
     super.onSaveInstanceState(outState);\r
+    Log.d(LOG, "onSaveInstanceState: " + searchText.getText().toString());\r
     outState.putString(C.SEARCH_TOKEN, searchText.getText().toString());\r
   }\r
 \r
   @Override\r
   protected void onRestoreInstanceState(final Bundle outState) {\r
     super.onRestoreInstanceState(outState);\r
-    setSearchText(outState.getString(C.SEARCH_TOKEN));\r
+    Log.d(LOG, "onRestoreInstanceState: " + outState.getString(C.SEARCH_TOKEN));\r
+    initialSearchText = outState.getString(C.SEARCH_TOKEN);\r
   }\r
 \r
   @Override\r
-  public void onCreate(Bundle savedInstanceState) {    \r
+  public void onCreate(Bundle savedInstanceState) { \r
+    setTheme(((DictionaryApplication)getApplication()).getSelectedTheme().themeId);\r
+\r
     Log.d(LOG, "onCreate:" + this);\r
     super.onCreate(savedInstanceState);\r
 \r
@@ -323,6 +332,9 @@ public class DictionaryActivity extends ListActivity {
       finish();\r
       startActivity(getIntent());\r
     }\r
+    if (initialSearchText != null) {\r
+      setSearchText(initialSearchText);\r
+    }\r
   }\r
   \r
   @Override\r
@@ -395,7 +407,13 @@ public class DictionaryActivity extends ListActivity {
   }\r
   \r
   void updateLangButton() {\r
-    langButton.setText(index.shortName);\r
+//    final LanguageResources languageResources = Language.isoCodeToResources.get(index.shortName);\r
+//    if (languageResources != null && languageResources.flagId != 0) {\r
+//      langButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, languageResources.flagId, 0);\r
+//    } else {\r
+//      langButton.setCompoundDrawablesWithIntrinsicBounds(0, 0, 0, 0);\r
+      langButton.setText(index.shortName);\r
+//    }\r
   }\r
 \r
   void onLanguageButton() {\r
@@ -418,15 +436,10 @@ public class DictionaryActivity extends ListActivity {
       public View getView(int position, View convertView, ViewGroup parent) {\r
         final LinearLayout result = new LinearLayout(parent.getContext());\r
         final DictionaryInfo dictionaryInfo = getItem(position);\r
-        for (int i = 0; i < dictionaryInfo.indexInfos.size(); ++i) {\r
-          final IndexInfo indexInfo = dictionaryInfo.indexInfos.get(i);\r
           final Button button = new Button(parent.getContext());\r
-          String name = application.getLanguageName(indexInfo.shortName);\r
-          if (name == null) {\r
-            name = indexInfo.shortName;\r
-          }\r
+          final String name = application.getDictionaryName(dictionaryInfo.uncompressedFilename);\r
           button.setText(name);\r
-          final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(), getLaunchIntent(application.getPath(dictionaryInfo.uncompressedFilename), i, "")) {\r
+          final IntentLauncher intentLauncher = new IntentLauncher(parent.getContext(), getLaunchIntent(application.getPath(dictionaryInfo.uncompressedFilename), 0, "")) {\r
             @Override\r
             protected void onGo() {\r
               dialog.dismiss();\r
@@ -441,7 +454,6 @@ public class DictionaryActivity extends ListActivity {
           button.setLayoutParams(layoutParams);\r
 \r
           result.addView(button);\r
-        }\r
         return result;\r
       }\r
       \r
@@ -536,7 +548,8 @@ public class DictionaryActivity extends ListActivity {
           dialog.setTitle(name);\r
           \r
           final StringBuilder builder = new StringBuilder();\r
-          final DictionaryInfo dictionaryInfo = Dictionary.getDictionaryInfo(dictFile);\r
+          final DictionaryInfo dictionaryInfo = dictionary.getDictionaryInfo();\r
+          dictionaryInfo.uncompressedBytes = dictFile.length();\r
           if (dictionaryInfo != null) {\r
             builder.append(dictionaryInfo.dictInfo).append("\n\n");\r
             builder.append(getString(R.string.dictionaryPath, dictFile.getPath())).append("\n");\r
@@ -547,6 +560,11 @@ public class DictionaryActivity extends ListActivity {
               builder.append(getString(R.string.indexName, indexInfo.shortName)).append("\n");\r
               builder.append(getString(R.string.mainTokenCount, indexInfo.mainTokenCount)).append("\n");\r
             }\r
+            builder.append("\n");\r
+            builder.append(getString(R.string.sources)).append("\n");\r
+            for (final EntrySource source : dictionary.sources) {\r
+              builder.append(getString(R.string.sourceInfo, source.getName(), source.getNumEntries())).append("\n");\r
+            }\r
           } else {\r
             builder.append(getString(R.string.invalidDictionary));\r
           }\r
@@ -597,8 +615,21 @@ public class DictionaryActivity extends ListActivity {
       final MenuItem searchForSelection = menu.add(getString(R.string.searchForSelection, selectedSpannableText));\r
       searchForSelection.setOnMenuItemClickListener(new OnMenuItemClickListener() {\r
         public boolean onMenuItemClick(MenuItem item) {\r
-          if (indexIndex != selectedSpannableIndex) {\r
-            changeIndex(selectedSpannableIndex);\r
+          int indexToUse = -1;\r
+          for (int i = 0; i < dictionary.indices.size(); ++i) {\r
+            final Index index = dictionary.indices.get(i);\r
+            final IndexEntry indexEntry = index.findExact(selectedText); \r
+            final TokenRow tokenRow = index.rows.get(indexEntry.startRow).getTokenRow(false);\r
+            if (tokenRow != null && tokenRow.hasMainEntry) {\r
+              indexToUse = i;\r
+              break;\r
+            }\r
+          }\r
+          if (indexToUse == -1) {\r
+            indexToUse = selectedSpannableIndex;\r
+          }\r
+          if (indexIndex != indexToUse) {\r
+            changeIndex(indexToUse);\r
           }\r
           setSearchText(selectedText);\r
           return false;\r
@@ -691,7 +722,10 @@ public class DictionaryActivity extends ListActivity {
     searchText.setText(text);\r
     searchText.requestFocus();\r
     onSearchTextChange(searchText.getText().toString());\r
-    Selection.moveToRightEdge(searchText.getText(), searchText.getLayout());\r
+    if (searchText.getLayout() != null) {\r
+      // Surprising, but this can crash when you rotate...\r
+      Selection.moveToRightEdge(searchText.getText(), searchText.getLayout());\r
+    }\r
   }\r
 \r
 \r