From f230eee2ffdf2366474ca1da8aebd89df486d73e Mon Sep 17 00:00:00 2001 From: mpodolian Date: Tue, 15 Oct 2024 17:14:06 -0700 Subject: [PATCH] Updated bubble bar position to be center aligned with the hotseat Added a method to the device profile to calculate the vertical center of the hotseat icons. Simplified the logic for positioning the bubble bar. Test: TransientBubbleStashControllerTest Test: PersistentBubbleStashControllerTest Test: Visual. Go to home page, check that bubble bar is vertically center aligned with the hotseat Bug: 345491493 Flag: com.android.wm.shell.enable_bubble_bar Change-Id: I52f1b94de79f6c912f43a88fcc5c884e20e56310 --- .../taskbar/TaskbarActivityContext.java | 6 +++++- .../bubbles/stashing/BubbleStashController.kt | 11 ++++------- .../DeviceProfileDimensionsProviderAdapter.kt | 10 +++------- .../stashing/PersistentBubbleStashController.kt | 17 ++++++++++------- .../stashing/TransientBubbleStashController.kt | 11 +++++++---- .../PersistentBubbleStashControllerTest.kt | 4 +++- .../bubbles/stashing/StashingTestUtils.kt | 8 -------- .../TransientBubbleStashControllerTest.kt | 2 ++ src/com/android/launcher3/DeviceProfile.java | 12 ++++++++++++ 9 files changed, 46 insertions(+), 35 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java index f3741b21db..6f1e96f3c8 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarActivityContext.java @@ -297,6 +297,7 @@ public class TaskbarActivityContext extends BaseTaskbarContext { BubbleStashController bubbleStashController = isTransientTaskbar ? new TransientBubbleStashController(dimensionsProvider, this) : new PersistentBubbleStashController(dimensionsProvider); + bubbleStashController.setHotseatVerticalCenter(launcherDp.getHotseatVerticalCenter()); bubbleControllersOptional = Optional.of(new BubbleControllers( new BubbleBarController(this, bubbleBarView), new BubbleBarViewController(this, bubbleBarView, bubbleBarContainer), @@ -362,8 +363,11 @@ public class TaskbarActivityContext extends BaseTaskbarContext { /** Updates {@link DeviceProfile} instances for any Taskbar windows. */ public void updateDeviceProfile(DeviceProfile launcherDp) { applyDeviceProfile(launcherDp); - mControllers.taskbarOverlayController.updateLauncherDeviceProfile(launcherDp); + mControllers.bubbleControllers.ifPresent(bubbleControllers -> { + int hotseatVertCenter = launcherDp.getHotseatVerticalCenter(); + bubbleControllers.bubbleStashController.setHotseatVerticalCenter(hotseatVertCenter); + }); AbstractFloatingView.closeAllOpenViewsExcept(this, false, TYPE_REBIND_SAFE); // Reapply fullscreen to take potential new screen size into account. setTaskbarWindowFullscreen(mIsFullscreen); 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 a78890b371..831faa16b4 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt @@ -42,12 +42,6 @@ interface BubbleStashController { /** Provides taskbar height in pixels. */ fun getTaskbarHeight(): Int - - /** Provides hotseat bottom space in pixels. */ - fun getHotseatBottomSpace(): Int - - /** Provides hotseat height in pixels. */ - fun getHotseatHeight(): Int } /** Execute passed action only after controllers are initiated. */ @@ -94,7 +88,7 @@ interface BubbleStashController { taskbarInsetsController: TaskbarInsetsController, bubbleBarViewController: BubbleBarViewController, bubbleStashedHandleViewController: BubbleStashedHandleViewController?, - controllersAfterInitAction: ControllersAfterInitAction + controllersAfterInitAction: ControllersAfterInitAction, ) /** Shows the bubble bar at [bubbleBarTranslationY] position immediately without animation. */ @@ -127,6 +121,9 @@ 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) + /** * Stashes the bubble bar (transform to the handle view), or just shrink width of the expanded * bubble bar based on the controller implementation. diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/DeviceProfileDimensionsProviderAdapter.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/DeviceProfileDimensionsProviderAdapter.kt index a55763b417..886b9f02c2 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/DeviceProfileDimensionsProviderAdapter.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/DeviceProfileDimensionsProviderAdapter.kt @@ -27,13 +27,9 @@ import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.Task class DeviceProfileDimensionsProviderAdapter( private val taskbarActivityContext: TaskbarActivityContext ) : TaskbarHotseatDimensionsProvider { - override fun getTaskbarBottomSpace(): Int = deviceProfile().taskbarBottomMargin + override fun getTaskbarBottomSpace(): Int = taskbarDp().taskbarBottomMargin - override fun getTaskbarHeight(): Int = deviceProfile().taskbarHeight + override fun getTaskbarHeight(): Int = taskbarDp().taskbarHeight - override fun getHotseatBottomSpace(): Int = deviceProfile().hotseatBarBottomSpacePx - - override fun getHotseatHeight(): Int = deviceProfile().hotseatCellHeightPx - - private fun deviceProfile(): DeviceProfile = taskbarActivityContext.deviceProfile + private fun taskbarDp(): DeviceProfile = taskbarActivityContext.deviceProfile } 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 722dfe7637..c117ad45e5 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashController.kt @@ -36,7 +36,7 @@ import com.android.wm.shell.shared.animation.PhysicsAnimator import com.android.wm.shell.shared.bubbles.BubbleBarLocation class PersistentBubbleStashController( - private val taskbarHotseatDimensionsProvider: TaskbarHotseatDimensionsProvider, + private val taskbarHotseatDimensionsProvider: TaskbarHotseatDimensionsProvider ) : BubbleStashController { private lateinit var taskbarInsetsController: TaskbarInsetsController @@ -45,6 +45,7 @@ class PersistentBubbleStashController( private lateinit var bubbleBarAlphaAnimator: MultiPropertyFactory.MultiProperty private lateinit var bubbleBarScaleAnimator: AnimatedFloat private lateinit var controllersAfterInitAction: ControllersAfterInitAction + private var hotseatVerticalCenter: Int = 0 override var launcherState: BubbleLauncherState = BubbleLauncherState.IN_APP set(state) { @@ -92,17 +93,15 @@ class PersistentBubbleStashController( override val bubbleBarTranslationYForHotseat: Float get() { - val hotseatBottomSpace = taskbarHotseatDimensionsProvider.getHotseatBottomSpace() - val hotseatCellHeight = taskbarHotseatDimensionsProvider.getHotseatHeight() - val bubbleBarHeight: Float = bubbleBarViewController.bubbleBarCollapsedHeight - return -hotseatBottomSpace - (hotseatCellHeight - bubbleBarHeight) / 2 + val bubbleBarHeight = bubbleBarViewController.bubbleBarCollapsedHeight + return -hotseatVerticalCenter + bubbleBarHeight / 2 } override fun init( taskbarInsetsController: TaskbarInsetsController, bubbleBarViewController: BubbleBarViewController, bubbleStashedHandleViewController: BubbleStashedHandleViewController?, - controllersAfterInitAction: ControllersAfterInitAction + controllersAfterInitAction: ControllersAfterInitAction, ) { this.taskbarInsetsController = taskbarInsetsController this.bubbleBarViewController = bubbleBarViewController @@ -119,13 +118,17 @@ class PersistentBubbleStashController( animatorSet.playTogether( bubbleBarScaleAnimator.animateToValue(1f), bubbleBarTranslationYAnimator.animateToValue(bubbleBarTranslationY), - bubbleBarAlphaAnimator.animateToValue(1f) + bubbleBarAlphaAnimator.animateToValue(1f), ) } updateTouchRegionOnAnimationEnd(animatorSet) animatorSet.setDuration(BAR_STASH_DURATION).start() } + override fun setHotseatVerticalCenter(hotseatVerticalCenter: Int) { + this.hotseatVerticalCenter = hotseatVerticalCenter + } + override fun showBubbleBarImmediate() = showBubbleBarImmediate(bubbleBarTranslationY) override fun showBubbleBarImmediate(bubbleBarTranslationY: Float) { 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 9e7d1c4602..fbeecaa643 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt @@ -78,6 +78,7 @@ class TransientBubbleStashController( context.resources.getDimensionPixelSize(R.dimen.bubblebar_stashed_size) / 2f private var animator: AnimatorSet? = null + private var hotseatVerticalCenter: Int = 0 override var isStashed: Boolean = false @VisibleForTesting set @@ -118,10 +119,8 @@ class TransientBubbleStashController( override val bubbleBarTranslationYForHotseat: Float get() { - val hotseatBottomSpace = taskbarHotseatDimensionsProvider.getHotseatBottomSpace() - val hotseatCellHeight = taskbarHotseatDimensionsProvider.getHotseatHeight() - val bubbleBarHeight: Float = bubbleBarViewController.bubbleBarCollapsedHeight - return -hotseatBottomSpace - (hotseatCellHeight - bubbleBarHeight) / 2 + val bubbleBarHeight = bubbleBarViewController.bubbleBarCollapsedHeight + return -hotseatVerticalCenter + bubbleBarHeight / 2 } override val bubbleBarTranslationYForTaskbar: Float = @@ -176,6 +175,10 @@ class TransientBubbleStashController( .start() } + override fun setHotseatVerticalCenter(hotseatVerticalCenter: Int) { + this.hotseatVerticalCenter = hotseatVerticalCenter + } + override fun showBubbleBarImmediate() { showBubbleBarImmediate(bubbleBarTranslationY) } 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 5dc78a9934..00b42bc950 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 @@ -48,6 +48,7 @@ class PersistentBubbleStashControllerTest { companion object { const val BUBBLE_BAR_HEIGHT = 100f + const val HOTSEAT_VERTICAL_CENTER = 95 const val HOTSEAT_TRANSLATION_Y = -45f const val TASK_BAR_TRANSLATION_Y = -5f } @@ -74,11 +75,12 @@ class PersistentBubbleStashControllerTest { PersistentBubbleStashController(DefaultDimensionsProvider()) setUpBubbleBarView() setUpBubbleBarController() + persistentTaskBarStashController.setHotseatVerticalCenter(HOTSEAT_VERTICAL_CENTER) persistentTaskBarStashController.init( taskbarInsetsController, bubbleBarViewController, null, - ImmediateAction() + ImmediateAction(), ) } diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/StashingTestUtils.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/StashingTestUtils.kt index 0f8a2c3eb0..96c2f4554f 100644 --- a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/StashingTestUtils.kt +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/StashingTestUtils.kt @@ -23,21 +23,13 @@ class ImmediateAction : BubbleStashController.ControllersAfterInitAction { class DefaultDimensionsProvider( private val taskBarBottomSpace: Int = TASKBAR_BOTTOM_SPACE, private val taskBarHeight: Int = TASKBAR_HEIGHT, - private val hotseatBottomSpace: Int = HOTSEAT_BOTTOM_SPACE, - private val hotseatHeight: Int = HOTSEAT_HEIGHT ) : BubbleStashController.TaskbarHotseatDimensionsProvider { override fun getTaskbarBottomSpace(): Int = taskBarBottomSpace override fun getTaskbarHeight(): Int = taskBarHeight - override fun getHotseatBottomSpace(): Int = hotseatBottomSpace - - override fun getHotseatHeight(): Int = hotseatHeight - companion object { const val TASKBAR_BOTTOM_SPACE = 0 const val TASKBAR_HEIGHT = 110 - const val HOTSEAT_BOTTOM_SPACE = 20 - const val HOTSEAT_HEIGHT = 150 } } 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 8b277e792d..64416ddea0 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 @@ -60,6 +60,7 @@ class TransientBubbleStashControllerTest { companion object { const val TASKBAR_BOTTOM_SPACE = 5 + const val HOTSEAT_VERTICAL_CENTER = 95 const val BUBBLE_BAR_WIDTH = 200 const val BUBBLE_BAR_HEIGHT = 100 const val HOTSEAT_TRANSLATION_Y = -45f @@ -108,6 +109,7 @@ class TransientBubbleStashControllerTest { setUpStashedHandleView() setUpBubbleStashedHandleViewController() PhysicsAnimatorTestUtils.prepareForTest() + mTransientBubbleStashController.setHotseatVerticalCenter(HOTSEAT_VERTICAL_CENTER) mTransientBubbleStashController.init( taskbarInsetsController, bubbleBarViewController, diff --git a/src/com/android/launcher3/DeviceProfile.java b/src/com/android/launcher3/DeviceProfile.java index 886255094f..92f6fab07e 100644 --- a/src/com/android/launcher3/DeviceProfile.java +++ b/src/com/android/launcher3/DeviceProfile.java @@ -2018,6 +2018,18 @@ public class DeviceProfile { } } + /** + * Returns the number of pixels the hotseat icons vertical center is translated from the bottom + * of the screen. + */ + public int getHotseatVerticalCenter() { + return hotseatBarSizePx + - (isQsbInline ? 0 : hotseatQsbVisualHeight) + - hotseatQsbSpace + - (hotseatCellHeightPx / 2) + + ((hotseatCellHeightPx - iconSizePx) / 2); + } + /** * Returns the number of pixels the taskbar is translated from the bottom of the screen. */