public void onCreate(Bundle savedInstanceState) {
Log.d(LOG, "onCreate:" + this);
super.onCreate(savedInstanceState);
-
+
final SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(this);
// Don't auto-launch if this fails.
- prefs.edit().remove(C.INDEX_SHORT_NAME).commit();
+ prefs.edit().remove(C.DICT_FILE).commit();
setTheme(((DictionaryApplication) getApplication()).getSelectedTheme().themeId);
if(intent.getStringExtra(C.DICT_FILE) == null && (from != null || to != null))
{
Log.d(LOG, "DictSearch: from: " + from + " to " + to);
- List<DictionaryInfo> dicts = application.getDictionariesOnDevice();
+ List<DictionaryInfo> dicts = application.getDictionariesOnDevice(null);
for(DictionaryInfo info : dicts)
{
boolean hasFrom = from == null;
break;
}
}
- indexIndex %= dictionary.indices.size();
Log.d(LOG, "Loading index " + indexIndex);
index = dictionary.indices.get(indexIndex);
setListAdapter(new IndexAdapter(index));
// Cache some prefs.
wordList = new File(prefs.getString(getString(R.string.wordListFileKey),
- getString(R.string.wordListFileDefault)));
+ new File(application.getDictDir(), "wordList.txt").getAbsolutePath()));
saveOnlyFirstSubentry = prefs.getBoolean(getString(R.string.saveOnlyFirstSubentryKey),
false);
clickOpensContextMenu = prefs.getBoolean(getString(R.string.clickOpensContextMenuKey),
setDictionaryPrefs(this, dictFile, index.shortName, searchView.getQuery().toString());
updateLangButton();
+ searchView.requestFocus();
}
private void onCreateSetupActionBarAndSearchView() {
searchView = new SearchView(getSupportActionBar().getThemedContext());
searchView.setIconifiedByDefault(false);
- // searchView.setIconified(false); // puts the magifying glass in the
+ // searchView.setIconified(false); // puts the magnifying glass in the
// wrong place.
searchView.setQueryHint(getString(R.string.searchText));
searchView.setSubmitButtonEnabled(false);
}
};
searchView.setOnQueryTextListener(onQueryTextListener);
+ searchView.setFocusable(true);
searchHintIcon = (ImageView) searchView.findViewById(R.id.abs__search_mag_icon);
searchHintIcon.setOnClickListener(new OnClickListener() {
// --------------------------------------------------------------------------
private void showKeyboard() {
-// searchText.postDelayed(new Runnable() {
-// @Override
-// public void run() {
-// Log.d(LOG, "Trying to show soft keyboard.");
-// final boolean searchTextHadFocus = searchText.hasFocus();
-// searchText.requestFocus();
-// final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
-// manager.showSoftInput(searchText, InputMethodManager.SHOW_IMPLICIT);
-// if (!searchTextHadFocus) {
-// defocusSearchText();
-// }
-// }}, 100);
+ // For some reason, this doesn't always work the first time.
+ // One way to replicate the problem:
+ // Press the "task switch" button repeatedly to pause and resume
+ for (int delay = 1; delay <= 101; delay += 100) {
+ searchView.postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ Log.d(LOG, "Trying to show soft keyboard.");
+ final boolean searchTextHadFocus = searchView.hasFocus();
+ searchView.requestFocusFromTouch();
+ final InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
+ manager.showSoftInput(searchView, InputMethodManager.SHOW_IMPLICIT);
+ if (!searchTextHadFocus) {
+ defocusSearchText();
+ }
+ }}, delay);
+ }
}
void updateLangButton() {
}
void onLanguageButtonClick() {
+ if (dictionary.indices.size() == 1) {
+ // No need to work to switch indices.
+ return;
+ }
if (currentSearchOperation != null) {
currentSearchOperation.interrupted.set(true);
currentSearchOperation = null;
}
- setIndexAndSearchText((indexIndex + 1) % dictionary.indices.size(), searchView.getQuery().toString());
+ setIndexAndSearchText((indexIndex + 1) % dictionary.indices.size(),
+ searchView.getQuery().toString());
}
void onLanguageButtonLongClick(final Context context) {
dialog.setContentView(R.layout.select_dictionary_dialog);
dialog.setTitle(R.string.selectDictionary);
- final List<DictionaryInfo> installedDicts = application.getDictionariesOnDevice();
+ final List<DictionaryInfo> installedDicts = application.getDictionariesOnDevice(null);
ListView listView = (ListView) dialog.findViewById(android.R.id.list);
final Button button = new Button(listView.getContext());
application.onCreateGlobalOptionsMenu(this, menu);
{
- final MenuItem dictionaryList = menu.add(getString(R.string.dictionaryManager));
- dictionaryList.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
- dictionaryList.setOnMenuItemClickListener(new OnMenuItemClickListener() {
+ final MenuItem dictionaryManager = menu.add(getString(R.string.dictionaryManager));
+ dictionaryManager.setShowAsAction(MenuItem.SHOW_AS_ACTION_NEVER);
+ dictionaryManager.setOnMenuItemClickListener(new OnMenuItemClickListener() {
public boolean onMenuItemClick(final MenuItem menuItem) {
startActivity(DictionaryManagerActivity.getLaunchIntent());
finish();
if (indexToUse == -1) {
indexToUse = defaultIndexToUse;
}
- setIndexAndSearchText(indexToUse, selectedText);
+ // Without this extra delay, the call to jumpToRow that this
+ // invokes doesn't always actually have any effect.
+ final int actualIndexToUse = indexToUse;
+ getListView().postDelayed(new Runnable() {
+ @Override
+ public void run() {
+ setIndexAndSearchText(actualIndexToUse, selectedText);
+ }
+ }, 100);
}
/**
if (event.getUnicodeChar() != 0) {
if (!searchView.hasFocus()) {
setSearchText("" + (char) event.getUnicodeChar(), true);
+ searchView.requestFocus();
}
- searchView.requestFocus();
return true;
}
if (keyCode == KeyEvent.KEYCODE_BACK) {
}
private void setSearchText(final String text, final boolean triggerSearch) {
- if (!triggerSearch) {
- searchView.setOnQueryTextListener(null);
- }
+ Log.d(LOG, "setSearchText, text=" + text + ", triggerSearch=" + triggerSearch);
+ // Disable the listener, because sometimes it doesn't work.
+ searchView.setOnQueryTextListener(null);
searchView.setQuery(text, false);
moveCursorToRight();
- if (!triggerSearch) {
- searchView.setOnQueryTextListener(onQueryTextListener);
- } else {
+ searchView.setOnQueryTextListener(onQueryTextListener);
+ if (triggerSearch) {
onQueryTextListener.onQueryTextChange(text);
}
}