From: Reimar Döffinger Date: Sat, 30 Jan 2016 09:36:22 +0000 (+0100) Subject: Merge pull request #26 from Kteby/master X-Git-Url: http://gitweb.fperrin.net/?a=commitdiff_plain;h=56c7d964a83199140532764b9ecf05594a2e8531;hp=-c;p=Dictionary.git Merge pull request #26 from Kteby/master Hide virtual keyboard if searchView text was changed programatically. --- 56c7d964a83199140532764b9ecf05594a2e8531 diff --combined src/com/hughes/android/dictionary/DictionaryActivity.java index e0290b0,c8d99e4..f8cca58 --- a/src/com/hughes/android/dictionary/DictionaryActivity.java +++ b/src/com/hughes/android/dictionary/DictionaryActivity.java @@@ -129,8 -129,6 +129,8 @@@ public class DictionaryActivity extend List rowsToShow = null; // if not null, just show these rows. + final Random rand = new Random(); + final Handler uiHandler = new Handler(); private final Executor searchExecutor = Executors.newSingleThreadExecutor(new ThreadFactory() { @@@ -170,7 -168,7 +170,7 @@@ ImageButton languageButton; SearchView.OnQueryTextListener onQueryTextListener; - MenuItem nextWordMenuItem, previousWordMenuItem; + MenuItem nextWordMenuItem, previousWordMenuItem, randomWordMenuItem; // Never null. private File wordList = null; @@@ -640,6 -638,13 +640,13 @@@ } } + private void hideKeyboard() { + Log.d(LOG, "Hide soft keyboard."); + searchView.clearFocus(); + InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE); + manager.hideSoftInputFromWindow(searchView.getWindowToken(), 0); + } + void updateLangButton() { final LanguageResources languageResources = DictionaryApplication.isoCodeToResources.get(index.shortName); @@@ -777,7 -782,7 +784,7 @@@ } } else { // Down - destIndexEntry = Math.min(tokenRow.referenceIndex + 1, index.sortedIndexEntries.size()); + destIndexEntry = Math.min(tokenRow.referenceIndex + 1, index.sortedIndexEntries.size() - 1); } final Index.IndexEntry dest = index.sortedIndexEntries.get(destIndexEntry); Log.d(LOG, "onUpDownButton, destIndexEntry=" + dest.token); @@@ -786,14 -791,6 +793,14 @@@ defocusSearchText(); } + void onRandomWordButton() { + int destIndexEntry = rand.nextInt(index.sortedIndexEntries.size()); + final Index.IndexEntry dest = index.sortedIndexEntries.get(destIndexEntry); + setSearchText(dest.token, false); + jumpToRow(index.sortedIndexEntries.get(destIndexEntry).startRow); + defocusSearchText(); + } + // -------------------------------------------------------------------------- // Options Menu // -------------------------------------------------------------------------- @@@ -830,15 -827,6 +837,15 @@@ }); } + randomWordMenuItem = menu.add(getString(R.string.randomWord)); + randomWordMenuItem.setOnMenuItemClickListener(new OnMenuItemClickListener() { + @Override + public boolean onMenuItemClick(MenuItem item) { + onRandomWordButton(); + return true; + } + }); + application.onCreateGlobalOptionsMenu(this, menu); { @@@ -1025,7 -1013,7 +1032,7 @@@ getListView().requestFocus(); // Visual indication that a new keystroke will clear the search text. - // Doesn't seem to work unless earchText has focus. + // Doesn't seem to work unless searchText has focus. // searchView.selectAll(); } @@@ -1128,6 -1116,9 +1135,9 @@@ searchView.setIconifiedByDefault(text.length() > 0); searchView.setIconified(false); + // We don't want to show virtual keyboard when we're changing searchView text programatically: + hideKeyboard(); + if (triggerSearch) { onQueryTextListener.onQueryTextChange(text); }