From 28907bcbd62a84569876509e8218f8bc5f9b5a3e Mon Sep 17 00:00:00 2001 From: mpodolian Date: Mon, 25 Nov 2024 11:40:35 -0800 Subject: [PATCH] Set bubble bar aligned to QSB Change logic to updated bubble bar alignment with the QSB vertical center for 3 buttons navigation mode. Fixes: 378400160 Flag: com.android.wm.shell.enable_bubble_bar Test: PersistentBubbleStashControllerTest Test: TransientBubbleStashControllerTest Test: Manual. Set the buttons navigation mode and observe that the bubble bar is centered with the QSB when the QSB is not aligned with the hotseat. Then, switch to gestures navigation mode and observe that the bubble bar is centered with the hotseat when the QSB is not aligned with the hotseat. Change-Id: I57a32ac5bde7a7055b54a89727429424e5c0ca4f --- .../taskbar/TaskbarActivityContext.java | 8 ++- .../taskbar/bubbles/BubbleBarView.java | 4 ++ .../bubbles/BubbleBarViewController.java | 5 ++ .../bubbles/stashing/BubbleStashController.kt | 4 +- .../PersistentBubbleStashController.kt | 8 +-- .../TransientBubbleStashController.kt | 8 +-- .../PersistentBubbleStashControllerTest.kt | 2 +- .../TransientBubbleStashControllerTest.kt | 2 +- src/com/android/launcher3/DeviceProfile.java | 68 +++++++++++++------ src/com/android/launcher3/Hotseat.java | 12 ++-- 10 files changed, 81 insertions(+), 40 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index 8149f8139c..2df520aa86 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -301,7 +301,8 @@ public class TaskbarActivityContext extends BaseTaskbarContext { BubbleStashController bubbleStashController = isTransientTaskbar ? new TransientBubbleStashController(dimensionsProvider, this) : new PersistentBubbleStashController(dimensionsProvider); - bubbleStashController.setHotseatVerticalCenter(launcherDp.getHotseatVerticalCenter()); + bubbleStashController.setBubbleBarVerticalCenterForHome( + launcherDp.getBubbleBarVerticalCenterForHome()); bubbleControllersOptional = Optional.of(new BubbleControllers( new BubbleBarController(this, bubbleBarView), new BubbleBarViewController(this, bubbleBarView, bubbleBarContainer), @@ -369,8 +370,9 @@ public class TaskbarActivityContext extends BaseTaskbarContext { applyDeviceProfile(launcherDp); mControllers.taskbarOverlayController.updateLauncherDeviceProfile(launcherDp); mControllers.bubbleControllers.ifPresent(bubbleControllers -> { - int hotseatVertCenter = launcherDp.getHotseatVerticalCenter(); - bubbleControllers.bubbleStashController.setHotseatVerticalCenter(hotseatVertCenter); + int bubbleBarVerticalCenter = launcherDp.getBubbleBarVerticalCenterForHome(); + bubbleControllers.bubbleStashController + .setBubbleBarVerticalCenterForHome(bubbleBarVerticalCenter); }); AbstractFloatingView.closeAllOpenViewsExcept(this, false, TYPE_REBIND_SAFE); // Reapply fullscreen to take potential new screen size into account. diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java index 833be61315..aab0c44f94 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java @@ -1307,6 +1307,10 @@ public class BubbleBarView extends FrameLayout { return getBubbleBarCollapsedHeight() + mPointerSize; } + float getArrowHeight() { + return mPointerSize; + } + float getBubbleBarCollapsedHeight() { // the pointer is invisible when collapsed return getScaledIconSize() + mBubbleBarPadding * 2; diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index fd08078109..3c146b7222 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -447,6 +447,11 @@ public class BubbleBarViewController { return mBarView.getBubbleBarCollapsedHeight(); } + /** Returns the bubble bar arrow height.*/ + public float getBubbleBarArrowHeight() { + return mBarView.getArrowHeight(); + } + /** * @see BubbleBarView#getRelativePivotX() */ diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt index d9589bbf12..b91718e217 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt @@ -121,8 +121,8 @@ interface BubbleStashController { /** Set a bubble bar location */ fun setBubbleBarLocation(bubbleBarLocation: BubbleBarLocation) - /** Set the hotseat vertical center that bubble bar will align with. */ - fun setHotseatVerticalCenter(hotseatVerticalCenter: Int) + /** Set the bubble bar vertical center for launcher home. */ + fun setBubbleBarVerticalCenterForHome(verticalCenter: Int) /** * Stashes the bubble bar (transform to the handle view), or just shrink width of the expanded diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashController.kt index 45f55688ef..31f17c4f65 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashController.kt @@ -47,7 +47,7 @@ class PersistentBubbleStashController( private lateinit var bubbleBarAlphaAnimator: MultiPropertyFactory.MultiProperty private lateinit var bubbleBarScaleAnimator: AnimatedFloat private lateinit var controllersAfterInitAction: ControllersAfterInitAction - private var hotseatVerticalCenter: Int = 0 + private var verticalCenterForHome: Int = 0 override var launcherState: BubbleLauncherState = BubbleLauncherState.IN_APP set(state) { @@ -97,7 +97,7 @@ class PersistentBubbleStashController( override val bubbleBarTranslationYForHotseat: Float get() { val bubbleBarHeight = bubbleBarViewController.bubbleBarCollapsedHeight - return -hotseatVerticalCenter + bubbleBarHeight / 2 + return -verticalCenterForHome + bubbleBarHeight / 2 } override val bubbleBarTranslationY: Float @@ -159,8 +159,8 @@ class PersistentBubbleStashController( animatorSet.setDuration(BAR_STASH_DURATION).start() } - override fun setHotseatVerticalCenter(hotseatVerticalCenter: Int) { - this.hotseatVerticalCenter = hotseatVerticalCenter + override fun setBubbleBarVerticalCenterForHome(verticalCenter: Int) { + verticalCenterForHome = verticalCenter } override fun showBubbleBarImmediate() = showBubbleBarImmediate(bubbleBarTranslationY) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt index 22d504f864..cb7fefc9b4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt @@ -78,7 +78,7 @@ class TransientBubbleStashController( context.resources.getDimensionPixelSize(R.dimen.bubblebar_stashed_size) / 2f private var animator: AnimatorSet? = null - private var hotseatVerticalCenter: Int = 0 + private var verticalCenterForHome: Int = 0 override var isStashed: Boolean = false @VisibleForTesting set @@ -124,7 +124,7 @@ class TransientBubbleStashController( override val bubbleBarTranslationYForHotseat: Float get() { val bubbleBarHeight = bubbleBarViewController.bubbleBarCollapsedHeight - return -hotseatVerticalCenter + bubbleBarHeight / 2 + return -verticalCenterForHome + bubbleBarHeight / 2 } override val bubbleBarTranslationYForTaskbar: Float = @@ -182,8 +182,8 @@ class TransientBubbleStashController( .start() } - override fun setHotseatVerticalCenter(hotseatVerticalCenter: Int) { - this.hotseatVerticalCenter = hotseatVerticalCenter + override fun setBubbleBarVerticalCenterForHome(verticalCenter: Int) { + verticalCenterForHome = verticalCenter } override fun showBubbleBarImmediate() { diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashControllerTest.kt index f795ab1a7d..4b9c7214bb 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashControllerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashControllerTest.kt @@ -76,7 +76,7 @@ class PersistentBubbleStashControllerTest { PersistentBubbleStashController(DefaultDimensionsProvider()) setUpBubbleBarView() setUpBubbleBarController() - persistentTaskBarStashController.setHotseatVerticalCenter(HOTSEAT_VERTICAL_CENTER) + persistentTaskBarStashController.setBubbleBarVerticalCenterForHome(HOTSEAT_VERTICAL_CENTER) persistentTaskBarStashController.init( taskbarInsetsController, bubbleBarViewController, diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashControllerTest.kt index 1bbd12a3be..5a64b685e9 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashControllerTest.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashControllerTest.kt @@ -109,7 +109,7 @@ class TransientBubbleStashControllerTest { setUpStashedHandleView() setUpBubbleStashedHandleViewController() PhysicsAnimatorTestUtils.prepareForTest() - mTransientBubbleStashController.setHotseatVerticalCenter(HOTSEAT_VERTICAL_CENTER) + mTransientBubbleStashController.setBubbleBarVerticalCenterForHome(HOTSEAT_VERTICAL_CENTER) mTransientBubbleStashController.init( taskbarInsetsController, bubbleBarViewController, diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 09225e7924..9b6fe4e826 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -1861,13 +1861,15 @@ public class DeviceProfile { * the bubble bar. * *

Does not check for visible bubbles persistence, so caller should call - * {@link #shouldAdjustHotseatForBubbleBar} first. + * {@link #shouldAdjustHotseatOrQsbForBubbleBar} first. * *

If there's no adjustment needed, this method returns {@code 0}. - * @see #shouldAdjustHotseatForBubbleBar(Context, boolean) + * @see #shouldAdjustHotseatOrQsbForBubbleBar(Context, boolean) */ public float getHotseatAdjustedBorderSpaceForBubbleBar(Context context) { - if (!shouldAdjustHotseatForBubbleBar(context)) return 0; + if (shouldAlignBubbleBarWithQSB() || !shouldAdjustHotseatOrQsbForBubbleBar(context)) { + return 0; + } // The adjustment is shrinking the hotseat's width by 1 icon on either side. int iconsWidth = iconSizePx * numShownHotseatIcons + hotseatBorderSpace * (numShownHotseatIcons - 1); @@ -1880,27 +1882,37 @@ public class DeviceProfile { * Returns the hotseat icon translation X for the cellX index. * *

Does not check for visible bubbles persistence, so caller should call - * {@link #shouldAdjustHotseatForBubbleBar} first. + * {@link #shouldAdjustHotseatOrQsbForBubbleBar} first. * *

If there's no adjustment needed, this method returns {@code 0}. - * @see #shouldAdjustHotseatForBubbleBar(Context, boolean) + * @see #shouldAdjustHotseatOrQsbForBubbleBar(Context, boolean) */ public float getHotseatAdjustedTranslation(Context context, int cellX) { - if (!shouldAdjustHotseatForBubbleBar(context)) return 0; float borderSpace = getHotseatAdjustedBorderSpaceForBubbleBar(context); + if (borderSpace == 0) return borderSpace; float borderSpaceDelta = borderSpace - hotseatBorderSpace; return iconSizePx + cellX * borderSpaceDelta; } - /** Returns whether hotseat should be adjusted for the bubble bar. */ - public boolean shouldAdjustHotseatForBubbleBar(Context context, boolean hasBubbles) { - return hasBubbles && shouldAdjustHotseatForBubbleBar(context); + /** Returns whether hotseat or QSB should be adjusted for the bubble bar. */ + public boolean shouldAdjustHotseatOrQsbForBubbleBar(Context context, boolean hasBubbles) { + return hasBubbles && shouldAdjustHotseatOrQsbForBubbleBar(context); } - private boolean shouldAdjustHotseatForBubbleBar(Context context) { - // only need to adjust if bubble bar is enabled, when QSB is on top of the hotseat and - // there's not enough space for the bubble bar to the right of the hotseat. - return !isQsbInline && getHotseatLayoutPadding(context).right <= mBubbleBarSpaceThresholdPx; + /** Returns whether hotseat should be adjusted for the bubble bar. */ + public boolean shouldAdjustHotseatForBubbleBar(Context context, boolean hasBubbles) { + return shouldAlignBubbleBarWithHotseat() + && shouldAdjustHotseatOrQsbForBubbleBar(context, hasBubbles); + } + + /** Returns whether hotseat or QSB should be adjusted for the bubble bar. */ + public boolean shouldAdjustHotseatOrQsbForBubbleBar(Context context) { + // only need to adjust if QSB is on top of the hotseat and there's not enough space for the + // bubble bar to either side of the hotseat. + if (isQsbInline) return false; + Rect hotseatPadding = getHotseatLayoutPadding(context); + int hotseatMinHorizontalPadding = Math.min(hotseatPadding.left, hotseatPadding.right); + return hotseatMinHorizontalPadding <= mBubbleBarSpaceThresholdPx; } /** @@ -2055,15 +2067,29 @@ public class DeviceProfile { } /** - * Returns the number of pixels the hotseat icons vertical center is translated from the bottom - * of the screen. + * Returns the number of pixels the hotseat icons or QSB vertical center is translated from the + * bottom of the screen. */ - public int getHotseatVerticalCenter() { - return hotseatBarSizePx - - (isQsbInline ? 0 : hotseatQsbVisualHeight) - - hotseatQsbSpace - - (hotseatCellHeightPx / 2) - + ((hotseatCellHeightPx - iconSizePx) / 2); + public int getBubbleBarVerticalCenterForHome() { + if (shouldAlignBubbleBarWithHotseat()) { + return hotseatBarSizePx + - (isQsbInline ? 0 : hotseatQsbVisualHeight) + - hotseatQsbSpace + - (hotseatCellHeightPx / 2) + + ((hotseatCellHeightPx - iconSizePx) / 2); + } else { + return hotseatBarSizePx - (hotseatQsbVisualHeight / 2); + } + } + + /** Returns whether bubble bar should be aligned with the hotseat. */ + public boolean shouldAlignBubbleBarWithQSB() { + return !shouldAlignBubbleBarWithHotseat(); + } + + /** Returns whether bubble bar should be aligned with the hotseat. */ + public boolean shouldAlignBubbleBarWithHotseat() { + return isQsbInline || isGestureMode; } /** diff --git a/src/com/android/launcher3/Hotseat.java b/src/com/android/launcher3/Hotseat.java index b2ccba431c..6be809869c 100644 --- a/src/com/android/launcher3/Hotseat.java +++ b/src/com/android/launcher3/Hotseat.java @@ -186,9 +186,10 @@ public class Hotseat extends CellLayout implements Insettable { */ public void adjustForBubbleBar(boolean isBubbleBarVisible) { DeviceProfile dp = mActivity.getDeviceProfile(); - float adjustedBorderSpace = dp.getHotseatAdjustedBorderSpaceForBubbleBar(getContext()); - boolean shouldAdjustHotseat = isBubbleBarVisible - && Float.compare(adjustedBorderSpace, 0f) != 0; + boolean shouldAdjust = isBubbleBarVisible + && dp.shouldAdjustHotseatOrQsbForBubbleBar(getContext()); + boolean shouldAdjustHotseat = shouldAdjust + && dp.shouldAlignBubbleBarWithHotseat(); ShortcutAndWidgetContainer icons = getShortcutsAndWidgets(); // update the translation provider for future layout passes of hotseat icons. if (shouldAdjustHotseat) { @@ -209,9 +210,12 @@ public class Hotseat extends CellLayout implements Insettable { animatorSet.play(ObjectAnimator.ofFloat(child, VIEW_TRANSLATE_X, tx)); } } + //TODO(b/381109832) refactor & simplify adjustment logic + boolean shouldAdjustQsb = + shouldAdjustHotseat || (shouldAdjust && dp.shouldAlignBubbleBarWithQSB()); if (mQsb instanceof HorizontalInsettableView horizontalInsettableQsb) { final float currentInsetFraction = horizontalInsettableQsb.getHorizontalInsets(); - final float targetInsetFraction = shouldAdjustHotseat + final float targetInsetFraction = shouldAdjustQsb ? (float) dp.iconSizePx / dp.hotseatQsbWidth : 0; ValueAnimator qsbAnimator = ValueAnimator.ofFloat(currentInsetFraction, targetInsetFraction);