diff options
| author | Adam Powell <adamp@google.com> | 2011-07-27 20:05:14 -0700 |
|---|---|---|
| committer | Adam Powell <adamp@google.com> | 2011-07-27 21:08:28 -0700 |
| commit | ccdd4ee44f8cfbb45b2989cca833895fcc4c4225 (patch) | |
| tree | 834d4578d847dae767765aa8fca9845ca323a64d /core/java/android/widget/SearchView.java | |
| parent | b6f7a27c59fd170b5d7617e43e21bfd8587f234e (diff) | |
Fix bug 5087980 - MenuItem#expandActionView should work from within
onCreateOptionsMenu
Initialize menu presenters early enough to respond to expanding an
action view within onCreateOptionsMenu.
Have SearchView show the IME as an async post to handle attempts to
show it while the UI is still in initial setup.
Change-Id: I77f3a94ed4397737edb5a7a15bf54993b6723f5e
Diffstat (limited to 'core/java/android/widget/SearchView.java')
| -rw-r--r-- | core/java/android/widget/SearchView.java | 32 |
1 files changed, 23 insertions, 9 deletions
diff --git a/core/java/android/widget/SearchView.java b/core/java/android/widget/SearchView.java index 91b19ed19658..8b4d3a9a40d1 100644 --- a/core/java/android/widget/SearchView.java +++ b/core/java/android/widget/SearchView.java @@ -118,6 +118,21 @@ public class SearchView extends LinearLayout implements CollapsibleActionView { private SearchableInfo mSearchable; private Bundle mAppSearchData; + /* + * SearchView can be set expanded before the IME is ready to be shown during + * initial UI setup. The show operation is asynchronous to account for this. + */ + private Runnable mShowImeRunnable = new Runnable() { + public void run() { + InputMethodManager imm = (InputMethodManager) + getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + + if (imm != null) { + imm.showSoftInputUnchecked(0, null); + } + } + }; + // For voice searching private final Intent mVoiceWebSearchIntent; private final Intent mVoiceAppSearchIntent; @@ -650,16 +665,15 @@ public class SearchView extends LinearLayout implements CollapsibleActionView { mSubmitArea.getBackground().setState(focused ? FOCUSED_STATE_SET : EMPTY_STATE_SET); } - private void setImeVisibility(boolean visible) { - InputMethodManager imm = (InputMethodManager) - getContext().getSystemService(Context.INPUT_METHOD_SERVICE); + private void setImeVisibility(final boolean visible) { + if (visible) { + post(mShowImeRunnable); + } else { + removeCallbacks(mShowImeRunnable); + InputMethodManager imm = (InputMethodManager) + getContext().getSystemService(Context.INPUT_METHOD_SERVICE); - // We made sure the IME was displayed, so also make sure it is closed - // when we go away. - if (imm != null) { - if (visible) { - imm.showSoftInputUnchecked(0, null); - } else { + if (imm != null) { imm.hideSoftInputFromWindow(getWindowToken(), 0); } } |
