import android.widget.TextView;
import android.widget.Toast;
-import com.hughes.android.dictionary.Dictionary.IndexEntry;
-import com.hughes.android.dictionary.Dictionary.LanguageData;
-import com.hughes.android.dictionary.Dictionary.Row;
+import com.hughes.android.dictionary.engine.Dictionary;
import com.hughes.android.dictionary.engine.Language;
import com.ibm.icu.text.Collator;
private boolean prefsMightHaveChanged = true;
// Never null.
- private File wordList;
+ private File wordList = null;
private RandomAccessFile dictRaf = null;
private Dictionary dictionary = null;
private boolean saveOnlyFirstSubentry = false;
// Visible for testing.
- LanguageListAdapter languageList = null;
+ IndexAdapter indexAdapter = null;
private SearchOperation searchOperation = null;
public DictionaryActivity() {
searchText = (EditText) findViewById(R.id.SearchText);
langButton = (Button) findViewById(R.id.LangButton);
- Log.d(LOG, "adding text changed listener");
searchText.addTextChangedListener(new SearchTextWatcher());
getListView().setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
Log.d(LOG, "Read dictionary millis: " + (System.currentTimeMillis() - startMillis));
} catch (IOException e) {
Log.e(LOG, "Couldn't open dictionary.", e);
- this.startActivity(new Intent(this, NoDictionaryActivity.class));
+
+ this.startActivity(new asdfIntent(this, DictionaryEditActivity.class));
finish();
- throw new Exception(e);
}
final byte lang = prefs.getInt(PREF_DICT_ACTIVE_LANG, SimpleEntry.LANG1) == SimpleEntry.LANG1 ? SimpleEntry.LANG1
: SimpleEntry.LANG2;
- languageList = new LanguageListAdapter(dictionary.languageDatas[lang]);
- setListAdapter(languageList);
+ indexAdapter = new IndexAdapter(dictionary.languageDatas[lang]);
+ setListAdapter(indexAdapter);
prefsMightHaveChanged = false;
}
Log.d(LOG, "onPause:" + this);
final Editor prefs = PreferenceManager.getDefaultSharedPreferences(this)
.edit();
- prefs.putInt(PREF_DICT_ACTIVE_LANG, languageList.languageData.lang);
+ prefs.putInt(PREF_DICT_ACTIVE_LANG, indexAdapter.languageData.lang);
prefs.putString(PREF_ACTIVE_SEARCH_TEXT, searchText.getText().toString());
prefs.commit();
}
return;
}
waitForSearchEnd();
- languageList = null;
+ indexAdapter = null;
setListAdapter(null);
Log.d(LOG, "setListAdapter finished.");
dictionary = null;
}
public String getSelectedRowRawText(final boolean onlyFirstSubentry) {
- final Row row = languageList.languageData.rows.get(getSelectedRow());
- return languageList.languageData.rowToString(row, onlyFirstSubentry);
+ final Row row = indexAdapter.languageData.rows.get(getSelectedRow());
+ return indexAdapter.languageData.rowToString(row, onlyFirstSubentry);
}
// ----------------------------------------------------------------
public boolean onPrepareOptionsMenu(final Menu menu) {
switchLanguageMenuItem.setTitle(getString(R.string.switchToLanguage,
dictionary.languageDatas[SimpleEntry
- .otherLang(languageList.languageData.lang)].language.symbol));
+ .otherLang(indexAdapter.languageData.lang)].language.symbol));
return super.onPrepareOptionsMenu(menu);
}
void updateLangButton() {
- langButton.setText(languageList.languageData.language.symbol);
+ langButton.setText(indexAdapter.languageData.language.symbol);
}
// ----------------------------------------------------------------
void onLanguageButton() {
waitForSearchEnd();
- languageList = new LanguageListAdapter(
- dictionary.languageDatas[(languageList.languageData == dictionary.languageDatas[0]) ? 1
+ indexAdapter = new IndexAdapter(
+ dictionary.languageDatas[(indexAdapter.languageData == dictionary.languageDatas[0]) ? 1
: 0]);
- Log.d(LOG, "onLanguageButton, newLang=" + languageList.languageData.language.symbol);
- setListAdapter(languageList);
+ Log.d(LOG, "onLanguageButton, newLang=" + indexAdapter.languageData.language.symbol);
+ setListAdapter(indexAdapter);
updateLangButton();
onSearchTextChange(searchText.getText().toString());
}
void onUpButton() {
- final int destRowIndex = languageList.languageData.getPrevTokenRow(getSelectedRow());
+ final int destRowIndex = indexAdapter.languageData.getPrevTokenRow(getSelectedRow());
Log.d(LOG, "onUpButton, destRowIndex=" + destRowIndex);
- jumpToRow(languageList, destRowIndex);
+ jumpToRow(indexAdapter, destRowIndex);
}
void onDownButton() {
- final int destRowIndex = languageList.languageData.getNextTokenRow(getSelectedRow());
+ final int destRowIndex = indexAdapter.languageData.getNextTokenRow(getSelectedRow());
Log.d(LOG, "onDownButton, destRowIndex=" + destRowIndex);
- jumpToRow(languageList, destRowIndex);
+ jumpToRow(indexAdapter, destRowIndex);
}
void onAppendToWordList() {
return;
}
final StringBuilder rawText = new StringBuilder();
- final String word = languageList.languageData.getIndexEntryForRow(row).word;
+ final String word = indexAdapter.languageData.getIndexEntryForRow(row).word;
rawText.append(
new SimpleDateFormat("yyyy.MM.dd HH:mm:ss").format(new Date()))
.append("\t");
void onSearchTextChange(final String searchText) {
Log.d(LOG, "onSearchTextChange: " + searchText);
synchronized (this) {
- searchOperation = new SearchOperation(languageList, searchText.trim(), searchOperation);
+ searchOperation = new SearchOperation(indexAdapter, searchText.trim(), searchOperation);
searchExecutor.execute(searchOperation);
}
}
}
- private void jumpToRow(final LanguageListAdapter dictionaryListAdapter,
+ private void jumpToRow(final IndexAdapter dictionaryListAdapter,
final int rowIndex) {
Log.d(LOG, "jumpToRow: " + rowIndex);
- if (dictionaryListAdapter != this.languageList) {
+ if (dictionaryListAdapter != this.indexAdapter) {
Log.w(LOG, "skipping jumpToRow for old list adapter: " + rowIndex);
return;
}
final int selectedRowIndex = getSelectedRow();
if (!searchText.hasFocus()) {
if (selectedRowIndex >= 0) {
- final String word = languageList.languageData
+ final String word = indexAdapter.languageData
.getIndexEntryForRow(selectedRowIndex).word;
if (!word.equals(searchText.getText().toString())) {
Log.d(LOG, "updateSearchText: setText: " + word);
context.startActivity(intent);
}
- class LanguageListAdapter extends BaseAdapter {
+ class IndexAdapter extends BaseAdapter {
// Visible for testing.
final LanguageData languageData;
- LanguageListAdapter(final LanguageData languageData) {
+ IndexAdapter(final LanguageData languageData) {
this.languageData = languageData;
}
private final class SearchOperation implements Runnable {
SearchOperation previousSearchOperation;
- final LanguageListAdapter listAdapter;
+ final IndexAdapter listAdapter;
final LanguageData languageData;
final String searchText;
final AtomicBoolean interrupted = new AtomicBoolean(false);
boolean searchFinished = false;
- SearchOperation(final LanguageListAdapter listAdapter,
+ SearchOperation(final IndexAdapter listAdapter,
final String searchText, final SearchOperation previousSearchOperation) {
this.listAdapter = listAdapter;
this.languageData = listAdapter.languageData;