setDictionaryPrefs(this, dictFile, index.shortName, searchView.getQuery().toString());
updateLangButton();
+ searchView.requestFocus();
}
private void onCreateSetupActionBarAndSearchView() {
}
};
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) {
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);
}
}