diff --git a/core/java/android/widget/TextView.java b/core/java/android/widget/TextView.java index 1ed016dce16de..dc8b52f874f49 100644 --- a/core/java/android/widget/TextView.java +++ b/core/java/android/widget/TextView.java @@ -8243,6 +8243,9 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener } hideControllers(); + if (mSuggestionsPopupWindow != null) { + mSuggestionsPopupWindow.onParentLostFocus(); + } } startStopMarquee(hasWindowFocus); @@ -9618,6 +9621,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; @@ -9673,6 +9677,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 @@ -9776,6 +9788,7 @@ public class TextView extends View implements ViewTreeObserver.OnPreDrawListener updateSuggestions(); mCursorWasVisibleBeforeSuggestions = mCursorVisible; setCursorVisible(false); + mIsShowingUp = true; super.show(); } @@ -11188,6 +11201,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(); }