From 41bb4953dad33b56b6d039d5bc87a574a0b70fe9 Mon Sep 17 00:00:00 2001 From: Yohei Yukawa Date: Tue, 26 May 2015 11:42:43 -0700 Subject: Rely on IMM#focusOut() to close input session. Historically we have been doing nothing in IMM#focusOut(). Problem of ignoring IMM#focusOut() may not be obvious as long as IMM#focusIn() is called immediately after IMM#focusOut(). In some particular situations, however, IMM can fall into an inconsistent state where the software keyboard continues to be shown even when there is no text input field. As reported in b.android.com/171190 or Bug 20820914, we can easily reproduce that inconsistent state by removing a focused EditText from the parent view while the IME still keeps an active connection to the EditText. This CL tries to address such a situation by staring using IMM#focusOut() as another trigger to check IME focus. Note that this CL has no effect if IMM#focusOut was called after the current window losed the focus. It is supposed to be taken care of in subsequent CLs for Bug 20612313. This CL depends on Id6afc8fc64512225578c62557b96c7dc2e969adf. Bug: 20612313 Change-Id: Ib1b037594ebbb4ad4cf2d59e21c7a8ca9d8dc930 --- .../android/view/inputmethod/InputMethodManager.java | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/core/java/android/view/inputmethod/InputMethodManager.java b/core/java/android/view/inputmethod/InputMethodManager.java index f61e372..3f7bad6 100644 --- a/core/java/android/view/inputmethod/InputMethodManager.java +++ b/core/java/android/view/inputmethod/InputMethodManager.java @@ -1306,16 +1306,12 @@ public final class InputMethodManager { if (DEBUG) Log.v(TAG, "focusOut: " + view + " mServedView=" + mServedView + " winFocus=" + view.hasWindowFocus()); - if (mServedView != view) { - // The following code would auto-hide the IME if we end up - // with no more views with focus. This can happen, however, - // whenever we go into touch mode, so it ends up hiding - // at times when we don't really want it to. For now it - // seems better to just turn it all off. - if (false && view.hasWindowFocus()) { - mNextServedView = null; - scheduleCheckFocusLocked(view); - } + // CAVEAT: We have ignored focusOut event in Android L MR-1 and prior. Need special + // care when changing the logic here because there are so many cases to be taken into + // consideration, e.g., WindowManager.LayoutParams.SOFT_INPUT_* flags. + if (mServedView == view && view.hasWindowFocus()) { + mNextServedView = null; + scheduleCheckFocusLocked(view); } } } -- cgit v1.1