import java.util.Date;\r
import java.util.concurrent.Executor;\r
import java.util.concurrent.Executors;\r
+import java.util.concurrent.ThreadFactory;\r
import java.util.concurrent.atomic.AtomicBoolean;\r
\r
import android.app.ListActivity;\r
import com.hughes.android.dictionary.engine.Dictionary;\r
import com.hughes.android.dictionary.engine.Index;\r
import com.hughes.android.dictionary.engine.PairEntry;\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
+import com.hughes.android.dictionary.engine.TransliteratorManager;\r
import com.hughes.android.util.PersistentObjectCache;\r
\r
public class DictionaryActivity extends ListActivity {\r
\r
// package for test.\r
final Handler uiHandler = new Handler();\r
- private final Executor searchExecutor = Executors.newSingleThreadExecutor();\r
+ private final Executor searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() {\r
+ @Override\r
+ public Thread newThread(Runnable r) {\r
+ return new Thread(r, "searchExecutor");\r
+ }\r
+ });\r
private SearchOperation currentSearchOperation = null;\r
\r
EditText searchText;\r
@Override\r
public void onCreate(Bundle savedInstanceState) {\r
super.onCreate(savedInstanceState);\r
+ Log.d(LOG, "onCreate:" + this);\r
\r
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);\r
\r
return;\r
}\r
\r
+ indexIndex = prefs.getInt(C.INDEX_INDEX, 0) % dictionary.indices.size();\r
+ Log.d(LOG, "Loading index.");\r
+ index = dictionary.indices.get(indexIndex);\r
+ setListAdapter(new IndexAdapter(index));\r
+\r
// Pre-load the collators.\r
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
+ \r
+ TransliteratorManager.init(new TransliteratorManager.Callback() {\r
+ @Override\r
+ public void onTransliteratorReady() {\r
+ uiHandler.post(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ onSearchTextChange(searchText.getText().toString());\r
+ }\r
+ });\r
+ }\r
+ });\r
+ \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
+ \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
+ " is buggy, lookups may not work properly.");\r
}\r
});\r
\r
- indexIndex = prefs.getInt(C.INDEX_INDEX, 0) % dictionary.indices.size();\r
- index = dictionary.indices.get(indexIndex);\r
- setListAdapter(new IndexAdapter(index));\r
- \r
+\r
setContentView(R.layout.dictionary_activity);\r
searchText = (EditText) findViewById(R.id.SearchText);\r
langButton = (Button) findViewById(R.id.LangButton);\r
if (!searchText.isFocused()) {\r
// TODO: don't do this if multi words are entered.\r
final RowBase row = (RowBase) getListAdapter().getItem(position);\r
+ Log.d(LOG, "onItemSelected: " + row.index());\r
final TokenRow tokenRow = row.getTokenRow(true);\r
searchText.setText(tokenRow.getToken());\r
}\r
searchText.removeTextChangedListener(searchTextWatcher);\r
searchText.setText(dest.token);\r
jumpToRow(index.sortedIndexEntries.get(destIndexEntry).startRow);\r
- searchText.removeTextChangedListener(searchTextWatcher);\r
+ searchText.addTextChangedListener(searchTextWatcher);\r
}\r
\r
// --------------------------------------------------------------------------\r
final Index.IndexEntry searchResult = searchOperation.searchResult;\r
Log.d(LOG, "searchFinished: " + searchOperation + ", searchResult=" + searchResult);\r
\r
- jumpToRow(searchResult.startRow);\r
+ currentSearchOperation = null;\r
+\r
+ uiHandler.postDelayed(new Runnable() {\r
+ @Override\r
+ public void run() {\r
+ if (currentSearchOperation == null) {\r
+ jumpToRow(searchResult.startRow);\r
+ } else {\r
+ Log.d(LOG, "More coming, waiting for currentSearchOperation.");\r
+ }\r
+ }\r
+ }, 50);\r
\r
// if (!searchResult.success) {\r
// if (vibrator != null) {\r
// searchText.setSelection(searchResult.longestPrefixString.length());\r
// return;\r
// }\r
+ \r
}\r
\r
private final void jumpToRow(final int row) {\r
private View getView(PairEntry.Row row, ViewGroup parent) {\r
final TableLayout result = new TableLayout(parent.getContext());\r
final PairEntry entry = row.getEntry();\r
- final int rowCount = entry.pairs.length;\r
+ final int rowCount = entry.pairs.size();\r
for (int r = 0; r < rowCount; ++r) {\r
final TableRow tableRow = new TableRow(result.getContext());\r
\r
column2.setWidth(1);\r
\r
// TODO: color words by gender\r
- final String col1Text = index.swapPairEntries ? entry.pairs[r].lang2 : entry.pairs[r].lang1;\r
+ final Pair pair = entry.pairs.get(r);\r
+ final String col1Text = index.swapPairEntries ? pair.lang2 : pair.lang1;\r
column1.setText(col1Text, TextView.BufferType.SPANNABLE);\r
final Spannable col1Spannable = (Spannable) column1.getText();\r
\r
startPos += token.length();\r
}\r
\r
- final String col2Text = index.swapPairEntries ? entry.pairs[r].lang1 : entry.pairs[r].lang2;\r
+ final String col2Text = index.swapPairEntries ? pair.lang1 : pair.lang2;\r
column2.setText(col2Text, TextView.BufferType.NORMAL);\r
\r
result.addView(tableRow);\r