]> gitweb.fperrin.net Git - Dictionary.git/blobdiff - src/com/hughes/android/dictionary/DictionaryActivity.java
go
[Dictionary.git] / src / com / hughes / android / dictionary / DictionaryActivity.java
old mode 100755 (executable)
new mode 100644 (file)
index daa79dd..7f156cf
-package com.hughes.android.dictionary;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.OutputStream;
-import java.io.RandomAccessFile;
-import java.util.concurrent.Executor;
-import java.util.concurrent.Executors;
-import java.util.concurrent.atomic.AtomicBoolean;
-
-import android.app.ListActivity;
-import android.content.Intent;
-import android.graphics.Typeface;
-import android.os.Bundle;
-import android.os.Handler;
-import android.text.Editable;
-import android.text.Spannable;
-import android.text.TextWatcher;
-import android.text.style.StyleSpan;
-import android.util.Log;
-import android.view.ContextMenu;
-import android.view.KeyEvent;
-import android.view.Menu;
-import android.view.MenuItem;
-import android.view.View;
-import android.view.ViewGroup;
-import android.view.ContextMenu.ContextMenuInfo;
-import android.view.MenuItem.OnMenuItemClickListener;
-import android.view.View.OnClickListener;
-import android.widget.AdapterView;
-import android.widget.BaseAdapter;
-import android.widget.Button;
-import android.widget.EditText;
-import android.widget.ListView;
-import android.widget.TableLayout;
-import android.widget.TableRow;
-import android.widget.TextView;
-import android.widget.AdapterView.OnItemLongClickListener;
-import android.widget.AdapterView.OnItemSelectedListener;
-
-import com.hughes.android.dictionary.Dictionary.IndexEntry;
-import com.hughes.android.dictionary.Dictionary.LanguageData;
-import com.hughes.android.dictionary.Dictionary.Row;
-
-public class DictionaryActivity extends ListActivity {
-
-  private RandomAccessFile dictRaf = null;
-  private Dictionary dictionary = null;
-  private LanguageData activeLangaugeData = null;
-
-  private File wordList = new File("/sdcard/wordList.txt");
-
-  final Handler uiHandler = new Handler();
-
-  private Executor searchExecutor = Executors.newSingleThreadExecutor();
-  private SearchOperation searchOperation = null;
-  // private List<Entry> entries = Collections.emptyList();
-  private DictionaryListAdapter dictionaryListAdapter = new DictionaryListAdapter();
-  private int selectedRowIndex = -1;
-  private int selectedTokenRowIndex = -1;
-  
-  private final Intent aboutIntent = new Intent().setClassName(AboutActivity.class.getPackage().getName(), AboutActivity.class.getCanonicalName());
-
-  /** Called when the activity is first created. */
-  @Override
-  public void onCreate(Bundle savedInstanceState) {
-    Log.d("THAD", "onCreate");
-    super.onCreate(savedInstanceState);
-
-    try {
-      dictRaf = new RandomAccessFile("/sdcard/de-en.dict", "r");
-      dictionary = new Dictionary(dictRaf);
-      activeLangaugeData = dictionary.languageDatas[Entry.LANG1];
-    } catch (Exception e) {
-      throw new RuntimeException(e);
-    }
-
-    setContentView(R.layout.main);
-
-    getSearchText().addTextChangedListener(new DictionaryTextWatcher());
-
-    setListAdapter(dictionaryListAdapter);
-
-    onSearchTextChange("");
-    
-    // Language button.
-    final Button langButton = (Button) findViewById(R.id.LangButton);
-    langButton.setOnClickListener(new OnClickListener() {
-      public void onClick(View v) {
-        switchLanguage();
-      }});
-    updateLangButton();
-
-    final Button upButton = (Button) findViewById(R.id.UpButton);
-    upButton.setOnClickListener(new OnClickListener() {
-      public void onClick(View v) {
-        final int destRowIndex;
-        final Row tokenRow = activeLangaugeData.rows.get(selectedTokenRowIndex);
-        assert tokenRow.isToken();
-        final int prevTokenIndex = tokenRow.getIndex() - 1;
-        if (selectedRowIndex == selectedTokenRowIndex && selectedRowIndex > 0) {
-          destRowIndex = activeLangaugeData.sortedIndex.get(prevTokenIndex).startRow;
-        } else {
-          destRowIndex = selectedTokenRowIndex;
-        }
-        jumpToRow(destRowIndex);
-      }});
-    final Button downButton = (Button) findViewById(R.id.DownButton);
-    downButton.setOnClickListener(new OnClickListener() {
-      public void onClick(View v) {
-        final Row tokenRow = activeLangaugeData.rows.get(selectedTokenRowIndex);
-        assert tokenRow.isToken();
-        final int nextTokenIndex = tokenRow.getIndex() + 1;
-        final int destRowIndex;
-        if (nextTokenIndex < activeLangaugeData.sortedIndex.size()) {
-          destRowIndex = activeLangaugeData.sortedIndex.get(nextTokenIndex).startRow;
-        } else {
-          destRowIndex = activeLangaugeData.rows.size() - 1;
-        }
-        jumpToRow(destRowIndex);
-      }});
-
-    // ContextMenu.
-    registerForContextMenu(getListView());
-
-    // ItemSelectedListener.
-    getListView().setOnItemSelectedListener(new OnItemSelectedListener() {
-      public void onItemSelected(AdapterView<?> arg0, View arg1, int rowIndex,
-          long arg3) {
-        Log.d("THAD", "onItemSelected: " + rowIndex);
-        selectedRowIndex = rowIndex;
-        selectedTokenRowIndex = activeLangaugeData.getIndexEntryForRow(rowIndex).startRow;
-        updateSearchText();
-      }
-
-      public void onNothingSelected(AdapterView<?> arg0) {
-      }});
-    
-
-    // LongClickListener.
-    getListView().setOnItemLongClickListener((new OnItemLongClickListener() {
-      public boolean onItemLongClick(AdapterView<?> arg0, View arg1, int rowIndex,
-          long arg3) {
-        selectedRowIndex = rowIndex;
-        return false;
-      }
-    }));
-  }
-  
-  public String getSelectedRowText() {
-    return activeLangaugeData.rowToString(activeLangaugeData.rows.get(selectedRowIndex));
-  }
-  
-  public EditText getSearchText() {
-    return (EditText) findViewById(R.id.SearchText);
-  }
-  
-  // ----------------------------------------------------------------
-  // OptionsMenu
-  // ----------------------------------------------------------------
-
-  private MenuItem switchLanguageMenuItem = null;
-  
-  @Override
-  public boolean onCreateOptionsMenu(final Menu menu) {
-    switchLanguageMenuItem = menu.add("Switch to language.");
-    switchLanguageMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener(){
-      public boolean onMenuItemClick(final MenuItem menuItem) {
-        switchLanguage();
-        return false;
-      }});
-
-    final MenuItem about = menu.add("About...");
-    about.setOnMenuItemClickListener(new OnMenuItemClickListener(){
-      public boolean onMenuItemClick(final MenuItem menuItem) {
-        startActivity(aboutIntent);
-        return false;
-      }});
-
-    return true;
-  }
-  
-  @Override
-  public boolean onPrepareOptionsMenu(final Menu menu) {
-    switchLanguageMenuItem.setTitle(String.format("Switch to %s", dictionary.languageDatas[Entry.otherLang(activeLangaugeData.lang)].language.symbol));
-    return super.onPrepareOptionsMenu(menu);
-  }
-
-  void switchLanguage() {
-    activeLangaugeData = dictionary.languageDatas[(activeLangaugeData == dictionary.languageDatas[0]) ? 1 : 0];
-    selectedRowIndex = 0;
-    selectedTokenRowIndex = 0;
-    updateLangButton();
-    dictionaryListAdapter.notifyDataSetChanged();
-    onSearchTextChange(getSearchText().getText().toString());
-  }
-  
-  void updateLangButton() {
-    final Button langButton = (Button) findViewById(R.id.LangButton);
-    langButton.setText(activeLangaugeData.language.symbol);
-  }
-  
-  // ----------------------------------------------------------------
-  // ContextMenu
-  // ----------------------------------------------------------------
-  
-  @Override
-  public void onCreateContextMenu(ContextMenu menu, View v,
-      ContextMenuInfo menuInfo) {
-    if (selectedRowIndex == -1) {
-      return;
-    }
-    final MenuItem addToWordlist = menu.add("Add to wordlist: " + wordList.getName());
-    addToWordlist.setOnMenuItemClickListener(new OnMenuItemClickListener() {
-      public boolean onMenuItemClick(MenuItem item) {
-        final String rawText = getSelectedRowText();
-        Log.d("THAD", "Writing : " + rawText);
-        try {
-          final OutputStream out = new FileOutputStream(wordList, true);
-          out.write((rawText + "\n").getBytes());
-          out.close();
-        } catch (IOException e) {
-          throw new RuntimeException(e);
-        }
-        return false;
-      }
-    });
-  }
-  
-  @Override
-  public boolean onKeyDown(int keyCode, KeyEvent event) {
-    if (event.getUnicodeChar() != 0) {
-      final EditText searchText = getSearchText();
-      if (!searchText.hasFocus()) {
-        searchText.setText("" + (char)event.getUnicodeChar());
-        onSearchTextChange(searchText.getText().toString());
-        searchText.requestFocus();
-      }
-      return true;
-    }
-    return super.onKeyDown(keyCode, event);
-  }
-
-  @Override
-  protected void onListItemClick(ListView l, View v, int row, long id) {
-    selectedRowIndex = row;
-    Log.d("THAD", "Clicked: " + getSelectedRowText());
-    openContextMenu(getListView());
-  }
-
-  void onSearchTextChange(final String searchText) {
-    Log.d("THAD", "onSearchTextChange: " + searchText);
-    if (searchOperation != null) {
-      searchOperation.interrupted.set(true);
-    }
-    searchOperation = new SearchOperation(searchText);
-    searchExecutor.execute(searchOperation);
-  }
-  
-  private void jumpToRow(final int rowIndex) {
-    Log.d("THAD", "jumpToRow: " + rowIndex);
-    selectedRowIndex = rowIndex;
-    selectedTokenRowIndex = activeLangaugeData.getIndexEntryForRow(rowIndex).startRow;
-    getListView().setSelection(rowIndex);
-    getListView().setSelected(true);  // TODO: is this doing anything?
-    updateSearchText();
-  }
-
-  private void updateSearchText() {
-    final EditText searchText = getSearchText();
-    if (!searchText.hasFocus()) {
-      // TODO: Not so nice:
-      final String word = activeLangaugeData.getIndexEntryForRow(selectedRowIndex).word;
-      if (!word.equals(searchText.getText().toString())) {
-        Log.d("THAD", "updateSearchText: setText: " + word);
-        searchText.setText(word);
-      }
-    }
-  }
-
-  private final class SearchOperation implements Runnable {
-    final String searchText;
-    final AtomicBoolean interrupted = new AtomicBoolean(false);
-
-    public SearchOperation(final String searchText) {
-      this.searchText = searchText;
-    }
-
-    public void run() {
-      Log.d("THAD", "SearchOperation: " + searchText);
-      final int indexLocation = activeLangaugeData.lookup(searchText, interrupted);
-      if (interrupted.get()) {
-        return;
-      }
-      final IndexEntry indexEntry = activeLangaugeData.sortedIndex
-          .get(indexLocation);
-      uiHandler.post(new Runnable() {
-        public void run() {
-          jumpToRow(indexEntry.startRow);
-        }
-      });
-    }
-  }
-
-  private class DictionaryListAdapter extends BaseAdapter {
-
-    public int getCount() {
-      return activeLangaugeData.rows.size();
-    }
-
-    public Dictionary.Row getItem(int rowIndex) {
-      assert rowIndex < activeLangaugeData.rows.size();
-      return activeLangaugeData.rows.get(rowIndex);
-    }
-
-    public long getItemId(int rowIndex) {
-      return rowIndex;
-    }
-
-    public View getView(final int rowIndex, final View convertView,
-        final ViewGroup parent) {
-      final Row row = getItem(rowIndex);
-      
-      // Token row.
-      if (row.isToken()) {
-        TextView result = null;
-        if (convertView instanceof TextView) {
-          result = (TextView) convertView;
-        } else {
-          result = new TextView(parent.getContext());
-        }
-//        result.setBackgroundColor(Color.WHITE);
-        result.setText(activeLangaugeData.rowToString(row));
-        result.setTextAppearance(parent.getContext(),
-            android.R.style.TextAppearance_Large);
-        result.setClickable(false);
-        return result;
-      }
-
-      // Entry row(s).
-      final TableLayout result = new TableLayout(parent.getContext());
-
-      final Entry entry = dictionary.entries.get(row.getIndex());
-      final int rowCount = entry.getRowCount();
-      for (int r = 0; r < rowCount; ++r) {
-        final TableRow tableRow = new TableRow(result.getContext());
-//        if (r > 0) {
-//          tableRow.setBackgroundColor(Color.DKGRAY);  
-//        }
-        
-        TextView column1 = new TextView(tableRow.getContext());
-        TextView column2 = new TextView(tableRow.getContext());
-        final TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();
-        layoutParams.weight = 0.5f;
-        
-        if (r>0){
-          final TextView spacer = new TextView(tableRow.getContext());
-          spacer.setText(r == 0 ? "\95 " : " \95 ");
-          tableRow.addView(spacer);
-        }
-        tableRow.addView(column1, layoutParams);
-        if (r>0){
-          final TextView spacer = new TextView(tableRow.getContext());
-          spacer.setText(r == 0 ? "\95 " : " \95 ");
-          tableRow.addView(spacer);
-        }
-        tableRow.addView(column2, layoutParams);
-        
-        column1.setWidth(1);
-        column2.setWidth(1);
-        // column1.setTextAppearance(parent.getContext(), android.R.style.Text);
-        
-        // TODO: highlight query word in entries.
-        final String col1Text = entry.getAllText(activeLangaugeData.lang)[r]; 
-        column1.setText(col1Text, TextView.BufferType.SPANNABLE);
-        final Spannable col1Spannable = (Spannable) column1.getText();
-        int startPos = 0;
-        final String token = activeLangaugeData.getIndexEntryForRow(rowIndex).word;
-        while ((startPos = col1Text.indexOf(token, startPos)) != -1) {
-          col1Spannable.setSpan(new StyleSpan(Typeface.BOLD), startPos, startPos + token.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);
-         startPos += token.length();
-        }
-        
-        column2.setText(entry.getAllText(Entry.otherLang(activeLangaugeData.lang))[r], TextView.BufferType.NORMAL);
-        
-        result.addView(tableRow);
-      }
-      
-      return result;
-    }
-  }  // DictionaryListAdapter
-
-  private class DictionaryTextWatcher implements TextWatcher {
-    public void afterTextChanged(Editable searchText) {
-      if (getSearchText().hasFocus()) {
-        onSearchTextChange(searchText.toString());
-      }
-    }
-
-    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
-        int arg3) {
-    }
-
-    public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
-    }
-  }
-
-}
\ No newline at end of file
+package com.hughes.android.dictionary;\r
+\r
+import java.io.File;\r
+import java.io.IOException;\r
+import java.io.RandomAccessFile;\r
+import java.util.concurrent.Executor;\r
+import java.util.concurrent.Executors;\r
+import java.util.concurrent.atomic.AtomicBoolean;\r
+\r
+import android.app.ListActivity;\r
+import android.content.Intent;\r
+import android.graphics.Typeface;\r
+import android.os.Bundle;\r
+import android.os.Handler;\r
+import android.preference.PreferenceManager;\r
+import android.text.Editable;\r
+import android.text.Spannable;\r
+import android.text.TextWatcher;\r
+import android.text.style.StyleSpan;\r
+import android.util.Log;\r
+import android.view.View;\r
+import android.view.ViewGroup;\r
+import android.view.View.OnClickListener;\r
+import android.widget.BaseAdapter;\r
+import android.widget.Button;\r
+import android.widget.EditText;\r
+import android.widget.ListAdapter;\r
+import android.widget.TableLayout;\r
+import android.widget.TableRow;\r
+import android.widget.TextView;\r
+\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.RowBase;\r
+import com.hughes.android.dictionary.engine.TokenRow;\r
+import com.hughes.android.util.PersistentObjectCache;\r
+\r
+public class DictionaryActivity extends ListActivity {\r
+\r
+  static final String LOG = "QuickDic";\r
+\r
+  RandomAccessFile dictRaf = null;\r
+  Dictionary dictionary = null;\r
+  int indexIndex = 0;\r
+  Index index = null;\r
+  \r
+  // package for test.\r
+  final Handler uiHandler = new Handler();\r
+  private final Executor searchExecutor = Executors.newSingleThreadExecutor();\r
+  private SearchOperation currentSearchOperation = null;\r
+\r
+  EditText searchText;\r
+  Button langButton;\r
+\r
+  // Never null.\r
+  private File wordList = null;\r
+  private boolean saveOnlyFirstSubentry = false;\r
+\r
+  // Visible for testing.\r
+  ListAdapter indexAdapter = null;\r
+\r
+  \r
+  public static Intent getIntent(final int dictIndex, final int indexIndex, final String searchToken) {\r
+    final Intent intent = new Intent();\r
+    intent.setClassName(DictionaryActivity.class.getPackage().getName(), DictionaryActivity.class.getName());\r
+    intent.putExtra(C.DICT_INDEX, dictIndex);\r
+    intent.putExtra(C.INDEX_INDEX, indexIndex);\r
+    intent.putExtra(C.SEARCH_TOKEN, searchToken);\r
+    return intent;\r
+  }\r
+\r
+  @Override\r
+  public void onCreate(Bundle savedInstanceState) {\r
+    super.onCreate(savedInstanceState);\r
+    \r
+    PersistentObjectCache.init(this);\r
+    QuickDicConfig quickDicConfig = PersistentObjectCache.init(\r
+        this).read(C.DICTIONARY_CONFIGS, QuickDicConfig.class);\r
+    \r
+    final Intent intent = getIntent();\r
+    \r
+    final DictionaryConfig dictionaryConfig = quickDicConfig.dictionaryConfigs.get(intent.getIntExtra(C.DICT_INDEX, 0));\r
+    try {\r
+      dictRaf = new RandomAccessFile(dictionaryConfig.localFile, "r");\r
+      dictionary = new Dictionary(dictRaf); \r
+    } catch (IOException e) {\r
+      Log.e(LOG, "Unable to load dictionary.", e);\r
+      // TODO: Start up the editor.\r
+      finish();\r
+      return;\r
+    }\r
+    \r
+    indexIndex = intent.getIntExtra(C.INDEX_INDEX, 0);\r
+    index = dictionary.indices.get(indexIndex);\r
+    setListAdapter(new IndexAdapter(index));\r
+    \r
+    setContentView(R.layout.dictionary_activity);\r
+    searchText = (EditText) findViewById(R.id.SearchText);\r
+    langButton = (Button) findViewById(R.id.LangButton);\r
+    \r
+    searchText.addTextChangedListener(new SearchTextWatcher());\r
+    \r
+    \r
+    final Button clearSearchTextButton = (Button) findViewById(R.id.ClearSearchTextButton);\r
+    clearSearchTextButton.setOnClickListener(new OnClickListener() {\r
+      public void onClick(View v) {\r
+        //onClearSearchTextButton(clearSearchTextButton);\r
+      }\r
+    });\r
+    clearSearchTextButton.setVisibility(PreferenceManager.getDefaultSharedPreferences(this).getBoolean(\r
+        getString(R.string.showClearSearchTextButtonKey), true) ? View.VISIBLE\r
+        : View.GONE);\r
+    \r
+    final Button langButton = (Button) findViewById(R.id.LangButton);\r
+    langButton.setOnClickListener(new OnClickListener() {\r
+      public void onClick(View v) {\r
+        onLanguageButton();\r
+      }\r
+    });\r
+    \r
+    final Button upButton = (Button) findViewById(R.id.UpButton);\r
+    upButton.setOnClickListener(new OnClickListener() {\r
+      public void onClick(View v) {\r
+        //onUpButton();\r
+      }\r
+    });\r
+    final Button downButton = (Button) findViewById(R.id.DownButton);\r
+    downButton.setOnClickListener(new OnClickListener() {\r
+      public void onClick(View v) {\r
+        //onDownButton();\r
+      }\r
+    });\r
+\r
+    // ContextMenu.\r
+    registerForContextMenu(getListView());\r
+\r
+    updateLangButton();\r
+\r
+  }\r
+  \r
+  void updateLangButton() {\r
+    langButton.setText(index.shortName.toUpperCase());\r
+  }\r
+\r
+\r
+  \r
+  \r
+  void onLanguageButton() {\r
+    // TODO: synchronized, stop search.\r
+    \r
+    indexIndex = (indexIndex + 1) % dictionary.indices.size();\r
+    index = dictionary.indices.get(indexIndex);\r
+    indexAdapter = new IndexAdapter(index);\r
+    Log.d(LOG, "onLanguageButton, newLang=" + index.longName);\r
+    setListAdapter(indexAdapter);\r
+    updateLangButton();\r
+    onSearchTextChange(searchText.getText().toString());\r
+  }\r
+  \r
+  // --------------------------------------------------------------------------\r
+  // SearchOperation\r
+  // --------------------------------------------------------------------------\r
+\r
+  private void searchFinished(final SearchOperation searchOperation) {\r
+    if (searchOperation == this.currentSearchOperation) {\r
+      setSelection(searchOperation.tokenRow.index());\r
+      getListView().setSelected(true);\r
+    }\r
+  }\r
+\r
+  final class SearchOperation implements Runnable {\r
+    \r
+    final AtomicBoolean interrupted = new AtomicBoolean(false);\r
+    final String searchText;\r
+    final Index index;\r
+    \r
+    boolean failed = false;\r
+    TokenRow tokenRow;\r
+    \r
+    SearchOperation(final String searchText, final Index index) {\r
+      this.searchText = searchText.trim();\r
+      this.index = index;\r
+    }\r
+\r
+    @Override\r
+    public void run() {\r
+      tokenRow = index.findInsertionPoint(searchText, interrupted);\r
+      failed = false; // TODO\r
+      if (!interrupted.get()) {\r
+        uiHandler.post(new Runnable() {\r
+          @Override\r
+          public void run() {            \r
+            searchFinished(SearchOperation.this);\r
+          }\r
+        });\r
+      }\r
+    }\r
+  }\r
+\r
+  \r
+  // --------------------------------------------------------------------------\r
+  // IndexAdapter\r
+  // --------------------------------------------------------------------------\r
+\r
+  static final class IndexAdapter extends BaseAdapter {\r
+    \r
+    final Index index;\r
+\r
+    IndexAdapter(final Index index) {\r
+      this.index = index;\r
+    }\r
+\r
+    @Override\r
+    public int getCount() {\r
+      return index.rows.size();\r
+    }\r
+\r
+    @Override\r
+    public Object getItem(int position) {\r
+      return index.rows.get(position);\r
+    }\r
+\r
+    @Override\r
+    public long getItemId(int position) {\r
+      return position;\r
+    }\r
+\r
+    @Override\r
+    public View getView(int position, View convertView, ViewGroup parent) {\r
+      final RowBase row = index.rows.get(position);\r
+      if (row instanceof PairEntry.Row) {\r
+        return getView((PairEntry.Row) row, parent);\r
+      } else if (row instanceof TokenRow) {\r
+        return getView((TokenRow) row, parent);\r
+      } else {\r
+        throw new IllegalArgumentException("Unsupported Row type: " + row.getClass());\r
+      }\r
+    }\r
+\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
+      for (int r = 0; r < rowCount; ++r) {\r
+        final TableRow tableRow = new TableRow(result.getContext());\r
+\r
+        TextView column1 = new TextView(tableRow.getContext());\r
+        TextView column2 = new TextView(tableRow.getContext());\r
+        final TableRow.LayoutParams layoutParams = new TableRow.LayoutParams();\r
+        layoutParams.weight = 0.5f;\r
+\r
+        if (r > 0) {\r
+          final TextView spacer = new TextView(tableRow.getContext());\r
+          spacer.setText(" • ");\r
+          tableRow.addView(spacer);\r
+        }\r
+        tableRow.addView(column1, layoutParams);\r
+        if (r > 0) {\r
+          final TextView spacer = new TextView(tableRow.getContext());\r
+          spacer.setText(" • ");\r
+          tableRow.addView(spacer);\r
+        }\r
+        tableRow.addView(column2, layoutParams);\r
+\r
+        column1.setWidth(1);\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
+        column1.setText(col1Text, TextView.BufferType.SPANNABLE);\r
+        final Spannable col1Spannable = (Spannable) column1.getText();\r
+        \r
+        int startPos = 0;\r
+        final String token = row.getTokenRow(true).getToken();\r
+        while ((startPos = col1Text.indexOf(token, startPos)) != -1) {\r
+          col1Spannable.setSpan(new StyleSpan(Typeface.BOLD), startPos,\r
+              startPos + token.length(), Spannable.SPAN_INCLUSIVE_EXCLUSIVE);\r
+          startPos += token.length();\r
+        }\r
+\r
+        final String col2Text = index.swapPairEntries ? entry.pairs[r].lang1 : entry.pairs[r].lang2;\r
+        column2.setText(col2Text, TextView.BufferType.NORMAL);\r
+\r
+        result.addView(tableRow);\r
+      }\r
+\r
+      return result;\r
+    }\r
+\r
+    private View getView(TokenRow row, ViewGroup parent) {\r
+      final TextView textView = new TextView(parent.getContext());\r
+      textView.setText(row.getToken());\r
+      textView.setTextSize(20);\r
+      return textView;\r
+    }\r
+    \r
+  }\r
+\r
+  // --------------------------------------------------------------------------\r
+  // SearchText\r
+  // --------------------------------------------------------------------------\r
+\r
+  void onSearchTextChange(final String searchText) {\r
+    Log.d(LOG, "onSearchTextChange: " + searchText);\r
+    if (currentSearchOperation != null) {\r
+      currentSearchOperation.interrupted.set(true);\r
+    }\r
+    currentSearchOperation = new SearchOperation(searchText, index);\r
+    searchExecutor.execute(currentSearchOperation);\r
+  }\r
+  \r
+  private class SearchTextWatcher implements TextWatcher {\r
+    public void afterTextChanged(final Editable searchTextEditable) {\r
+      Log.d(LOG, "Search text changed: " + searchText.getText());\r
+      if (searchText.hasFocus()) {\r
+        // If they were typing to cause the change, update the UI.\r
+        onSearchTextChange(searchText.getText().toString());\r
+      }\r
+    }\r
+\r
+    public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,\r
+        int arg3) {\r
+    }\r
+\r
+    public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {\r
+    }\r
+  }\r
+\r
+}\r