From 26c8b3ae7f01e8a28658e23e2a0d525dd7b9bdf9 Mon Sep 17 00:00:00 2001 From: Gilles Debunne Date: Wed, 12 Oct 2011 14:06:58 -0700 Subject: [PATCH] Bug 5420741: exception when rotating device while suggestion popup is visible The suggestion popup window was not dismissed on orientation change. This is triggered by onDetachedFromWindow. However, this method is also called when the suggestion popup window pops up. A new flag detects that case to dismiss the popup unless it has expressly been asked to show up. Still errors in the log after that change, I assume related to the window manager. Change-Id: Ia515fc576ddf2127b2f9863cc2652aeb619fff6e --- core/java/android/widget/TextView.java | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index de16d61b08e55..7bd4709a65554 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8205,6 +8205,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } hideControllers(); + if (mSuggestionsPopupWindow != null) { + mSuggestionsPopupWindow.onParentLostFocus(); + } } startStopMarquee(hasWindowFocus); @@ -9545,6 +9548,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener private SuggestionInfo[] mSuggestionInfos; private int mNumberOfSuggestions; private boolean mCursorWasVisibleBeforeSuggestions; + private boolean mIsShowingUp = false; private SuggestionAdapter mSuggestionsAdapter; private final Comparator mSuggestionSpanComparator; private final HashMap mSpansLengths; @@ -9600,6 +9604,14 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } } + public boolean isShowingUp() { + return mIsShowingUp; + } + + public void onParentLostFocus() { + mIsShowingUp = false; + } + private class SuggestionInfo { int suggestionStart, suggestionEnd; // range of actual suggestion within text SuggestionSpan suggestionSpan; // the SuggestionSpan that this TextView represents @@ -9703,6 +9715,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener updateSuggestions(); mCursorWasVisibleBeforeSuggestions = mCursorVisible; setCursorVisible(false); + mIsShowingUp = true; super.show(); } @@ -11113,6 +11126,10 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } private void hideCursorControllers() { + if (mSuggestionsPopupWindow != null && !mSuggestionsPopupWindow.isShowingUp()) { + // Should be done before hide insertion point controller since it triggers a show of it + mSuggestionsPopupWindow.hide(); + } hideInsertionPointCursorController(); stopSelectionActionMode(); }