From 33319db63e4cd624f3e7d76e7a149a0461eb8877 Mon Sep 17 00:00:00 2001 From: Mady Mellor Date: Wed, 2 Aug 2023 15:12:16 -0700 Subject: [PATCH] Modify the default position of bubbles on tablet to be centered If we don't have a previous bubble position we use a default spot. On phone we use an offset from the top of the device and place bubbles based on that. This was also being used for tablet. This CL modifies the behavior so that we'll center bubbles along the edge for the default position on tablet. This makes them a little more reachable for the larger screen size. Bug: 283910436 Test: atest BubblePositionerTest Change-Id: Ifc1a889809ea1be53e71c920e86e923b3cf98805 --- .../wm/shell/bubbles/BubblePositioner.java | 28 +++++++++++++------ .../shell/bubbles/BubblePositionerTest.java | 14 ++++++++-- 2 files changed, 32 insertions(+), 10 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 ee6996d3d23d8..2c100653dae0a 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 @@ -661,14 +661,26 @@ public class BubblePositioner { final boolean startOnLeft = mContext.getResources().getConfiguration().getLayoutDirection() != LAYOUT_DIRECTION_RTL; - final float startingVerticalOffset = mContext.getResources().getDimensionPixelOffset( - R.dimen.bubble_stack_starting_offset_y); - // TODO: placement bug here because mPositionRect doesn't handle the overhanging edge - return new BubbleStackView.RelativeStackPosition( - startOnLeft, - startingVerticalOffset / mPositionRect.height()) - .getAbsolutePositionInRegion(getAllowableStackPositionRegion( - 1 /* default starts with 1 bubble */)); + final RectF allowableStackPositionRegion = getAllowableStackPositionRegion( + 1 /* default starts with 1 bubble */); + if (isLargeScreen()) { + // We want the stack to be visually centered on the edge, so we need to base it + // of a rect that includes insets. + final float desiredY = mScreenRect.height() / 2f - (mBubbleSize / 2f); + final float offset = desiredY / mScreenRect.height(); + return new BubbleStackView.RelativeStackPosition( + startOnLeft, + offset) + .getAbsolutePositionInRegion(allowableStackPositionRegion); + } else { + final float startingVerticalOffset = mContext.getResources().getDimensionPixelOffset( + R.dimen.bubble_stack_starting_offset_y); + // TODO: placement bug here because mPositionRect doesn't handle the overhanging edge + return new BubbleStackView.RelativeStackPosition( + startOnLeft, + startingVerticalOffset / mPositionRect.height()) + .getAbsolutePositionInRegion(allowableStackPositionRegion); + } } /** diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblePositionerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblePositionerTest.java index 5f7239702d31a..139724f709c70 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblePositionerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/bubbles/BubblePositionerTest.java @@ -209,9 +209,19 @@ public class BubblePositionerTest extends ShellTestCase { * {@link BubbleStackView.RelativeStackPosition}. */ private float getDefaultYPosition() { - final float desiredY = mContext.getResources().getDimensionPixelOffset( + final boolean isTablet = mPositioner.isLargeScreen(); + + // On tablet the position is centered, on phone it is an offset from the top. + final float desiredY = isTablet + ? mPositioner.getScreenRect().height() / 2f - (mPositioner.getBubbleSize() / 2f) + : mContext.getResources().getDimensionPixelOffset( R.dimen.bubble_stack_starting_offset_y); - float offsetPercent = desiredY / mPositioner.getAvailableRect().height(); + // Since we're visually centering the bubbles on tablet, use total screen height rather + // than the available height. + final float height = isTablet + ? mPositioner.getScreenRect().height() + : mPositioner.getAvailableRect().height(); + float offsetPercent = desiredY / height; offsetPercent = Math.max(0f, Math.min(1f, offsetPercent)); final RectF allowableStackRegion = mPositioner.getAllowableStackPositionRegion(1 /* bubbleCount */);