From 8763cf035b9cee4a949953c915d2db92545a7c14 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Fri, 8 Apr 2022 18:01:16 +0000 Subject: [PATCH] Fix an issue where the selected bubble might move offscreen for IME Check if the selected bubble is within the area where the expanded view is and if it's not, cap the amount the bubbles translate so that it remains in view. Fixes a small issue where the padding should be added rather than subtracted (due to changes from ag/17354481) Bug: 227812332 Test: manual - increase IME height, have max bubbles on tablet, select the top-most bubble and bring up the IME => verify that the selected bubble remains on screen and the pointer is connected to the expanded view Change-Id: I251875f13c439564c7db60ded080b8c62aa76cf6 --- .../wm/shell/bubbles/BubblePositioner.java | 21 ++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java index 97e5ee3a35d36..6eb8d8aec417f 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/bubbles/BubblePositioner.java @@ -557,7 +557,7 @@ public class BubblePositioner { } if (showBubblesVertically() && mImeVisible) { - return new PointF(x, getExpandedBubbleYForIme(index, state.numberOfBubbles)); + return new PointF(x, getExpandedBubbleYForIme(index, state)); } return new PointF(x, y); } @@ -567,10 +567,10 @@ public class BubblePositioner { * is showing. * * @param index the index of the bubble in the stack. - * @param numberOfBubbles the total number of bubbles in the stack. + * @param state information about the stack state (# of bubbles, selected bubble). * @return y position of the bubble on-screen when the stack is expanded. */ - private float getExpandedBubbleYForIme(int index, int numberOfBubbles) { + private float getExpandedBubbleYForIme(int index, BubbleStackView.StackViewState state) { final float top = getAvailableRect().top + mExpandedViewPadding; if (!showBubblesVertically()) { // Showing horizontally: align to top @@ -578,10 +578,10 @@ public class BubblePositioner { } // Showing vertically: might need to translate the bubbles above the IME. - // Subtract spacing here to provide a margin between top of IME and bottom of bubble row. - final float bottomHeight = getImeHeight() + mInsets.bottom - (mSpacingBetweenBubbles * 2); + // Add spacing here to provide a margin between top of IME and bottom of bubble row. + final float bottomHeight = getImeHeight() + mInsets.bottom + (mSpacingBetweenBubbles * 2); final float bottomInset = mScreenRect.bottom - bottomHeight; - final float expandedStackSize = getExpandedStackSize(numberOfBubbles); + final float expandedStackSize = getExpandedStackSize(state.numberOfBubbles); final float centerPosition = mPositionRect.centerY(); final float rowBottom = centerPosition + (expandedStackSize / 2f); final float rowTop = centerPosition - (expandedStackSize / 2f); @@ -593,7 +593,7 @@ public class BubblePositioner { if (rowTop - translationY < top) { // Even if we shift the bubbles, they will still overlap with the IME. // Hide the overflow for a lil more space: - final float expandedStackSizeNoO = getExpandedStackSize(numberOfBubbles - 1); + final float expandedStackSizeNoO = getExpandedStackSize(state.numberOfBubbles - 1); final float centerPositionNoO = showBubblesVertically() ? mPositionRect.centerY() : mPositionRect.centerX(); @@ -603,6 +603,13 @@ public class BubblePositioner { rowTopForIme = rowTopNoO - translationY; } } + // Check if the selected bubble is within the appropriate space + final float selectedPosition = rowTopForIme + + (state.selectedIndex * (mBubbleSize + mSpacingBetweenBubbles)); + if (selectedPosition < top) { + // We must always keep the selected bubble in view so we'll have to allow more overlap. + rowTopForIme = top; + } return rowTopForIme + (index * (mBubbleSize + mSpacingBetweenBubbles)); }