diff --git a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java index 065646ad39..9e12670433 100644 --- a/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java +++ b/quickstep/src/com/android/launcher3/taskbar/TaskbarLauncherStateController.java @@ -57,6 +57,7 @@ import com.android.launcher3.anim.AnimatedFloat; import com.android.launcher3.anim.AnimatorListeners; import com.android.launcher3.config.FeatureFlags; import com.android.launcher3.statemanager.StateManager; +import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.BubbleLauncherState; import com.android.launcher3.uioverrides.QuickstepLauncher; import com.android.launcher3.util.DisplayController; import com.android.launcher3.util.MultiPropertyFactory.MultiProperty; @@ -473,8 +474,12 @@ public class TaskbarLauncherStateController { boolean onOverview = mLauncherState == LauncherState.OVERVIEW; boolean hotseatIconsVisible = isInLauncher && mLauncherState.areElementsVisible( mLauncher, HOTSEAT_ICONS); - controllers.bubbleStashController.setBubblesShowingOnHome(hotseatIconsVisible); - controllers.bubbleStashController.setBubblesShowingOnOverview(onOverview); + BubbleLauncherState state = onOverview + ? BubbleLauncherState.OVERVIEW + : hotseatIconsVisible + ? BubbleLauncherState.HOME + : BubbleLauncherState.IN_APP; + controllers.bubbleStashController.setLauncherState(state); }); TaskbarStashController stashController = mControllers.taskbarStashController; 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 9721792540..a78890b371 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt @@ -56,14 +56,29 @@ interface BubbleStashController { fun runAfterInit(action: Runnable) } + /** Launcher states bubbles cares about */ + enum class BubbleLauncherState { + /* When launcher is in overview */ + OVERVIEW, + /* When launcher is on home */ + HOME, + /* We're in an app */ + IN_APP, + } + + /** The current launcher state */ + var launcherState: BubbleLauncherState + /** Whether bubble bar is currently stashed */ val isStashed: Boolean /** Whether launcher enters or exits the home page. */ - var isBubblesShowingOnHome: Boolean + val isBubblesShowingOnHome: Boolean + get() = launcherState == BubbleLauncherState.HOME /** Whether launcher enters or exits the overview page. */ - var isBubblesShowingOnOverview: Boolean + val isBubblesShowingOnOverview: Boolean + get() = launcherState == BubbleLauncherState.OVERVIEW /** Updated when sysui locked state changes, when locked, bubble bar is not shown. */ var isSysuiLocked: Boolean 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 7d6f7adbbf..722dfe7637 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentBubbleStashController.kt @@ -26,6 +26,7 @@ import com.android.launcher3.anim.AnimatedFloat import com.android.launcher3.taskbar.TaskbarInsetsController import com.android.launcher3.taskbar.bubbles.BubbleBarViewController import com.android.launcher3.taskbar.bubbles.BubbleStashedHandleViewController +import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.BubbleLauncherState import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.Companion.BAR_STASH_DURATION import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.Companion.BAR_TRANSLATION_DURATION import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.ControllersAfterInitAction @@ -45,29 +46,21 @@ class PersistentBubbleStashController( private lateinit var bubbleBarScaleAnimator: AnimatedFloat private lateinit var controllersAfterInitAction: ControllersAfterInitAction - override var isBubblesShowingOnHome: Boolean = false - set(onHome) { - if (field == onHome) return - field = onHome + override var launcherState: BubbleLauncherState = BubbleLauncherState.IN_APP + set(state) { + if (field == state) return + val transitionFromHome = field == BubbleLauncherState.HOME + field = state if (!bubbleBarViewController.hasBubbles()) { // if there are no bubbles, there's nothing to show, so just return. return } - if (onHome) { - // When transition to home we should show collapse the bubble bar - updateExpandedState(expand = false) - } - animateBubbleBarY() - bubbleBarViewController.onBubbleBarConfigurationChanged(/* animate= */ true) - } - - override var isBubblesShowingOnOverview: Boolean = false - set(onOverview) { - if (field == onOverview) return - field = onOverview - if (!onOverview) { - // When transition from overview we should show collapse the bubble bar - updateExpandedState(expand = false) + // If we're transitioning anywhere, bubble bar should be collapsed + updateExpandedState(expand = false) + if (transitionFromHome || field == BubbleLauncherState.HOME) { + // If we're transitioning to or from home, animate the Y because we're in hotseat + // on home but in persistent taskbar elsewhere so the position is different. + animateBubbleBarY() } bubbleBarViewController.onBubbleBarConfigurationChanged(/* animate= */ true) } 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 74e3c00c55..fe3db302a3 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt @@ -36,6 +36,7 @@ import com.android.launcher3.taskbar.TaskbarStashController.TASKBAR_STASH_ALPHA_ import com.android.launcher3.taskbar.TaskbarStashController.TRANSIENT_TASKBAR_STASH_ALPHA_DURATION import com.android.launcher3.taskbar.bubbles.BubbleBarViewController import com.android.launcher3.taskbar.bubbles.BubbleStashedHandleViewController +import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.BubbleLauncherState import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.Companion.BAR_STASH_DURATION import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.Companion.BAR_TRANSLATION_DURATION import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.ControllersAfterInitAction @@ -81,36 +82,26 @@ class TransientBubbleStashController( override var isStashed: Boolean = false @VisibleForTesting set - override var isBubblesShowingOnHome: Boolean = false - set(onHome) { - if (field == onHome) return - field = onHome + override var launcherState: BubbleLauncherState = BubbleLauncherState.IN_APP + set(state) { + if (field == state) return + field = state if (!bubbleBarViewController.hasBubbles()) { // if there are no bubbles, there's nothing to show, so just return. return } - if (onHome) { - updateStashedAndExpandedState(stash = false, expand = false) - // When transitioning from app to home we need to animate the bubble bar + if (field == BubbleLauncherState.HOME) { + // When to home we need to animate the bubble bar // here to align with hotseat center. animateBubbleBarYToHotseat() - } else if (!bubbleBarViewController.isExpanded) { - updateStashedAndExpandedState(stash = true, expand = false) - } - bubbleBarViewController.onBubbleBarConfigurationChanged(/* animate= */ true) - } - - override var isBubblesShowingOnOverview: Boolean = false - set(onOverview) { - if (field == onOverview) return - field = onOverview - if (onOverview) { + } else if (field == BubbleLauncherState.OVERVIEW) { // When transitioning to overview we need to animate the bubble bar to align with // the taskbar bottom. animateBubbleBarYToTaskbar() - } else { - updateStashedAndExpandedState(stash = true, expand = false) } + // Only stash if we're in an app, otherwise we're in home or overview where we should + // be un-stashed + updateStashedAndExpandedState(field == BubbleLauncherState.IN_APP, expand = false) bubbleBarViewController.onBubbleBarConfigurationChanged(/* animate= */ true) } 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 4106a2c9a6..5dc78a9934 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 @@ -27,6 +27,7 @@ import com.android.launcher3.anim.AnimatedFloat import com.android.launcher3.taskbar.TaskbarInsetsController import com.android.launcher3.taskbar.bubbles.BubbleBarView import com.android.launcher3.taskbar.bubbles.BubbleBarViewController +import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.BubbleLauncherState import com.android.launcher3.util.MultiValueAlpha import com.google.common.truth.Truth.assertThat import org.junit.Before @@ -85,12 +86,12 @@ class PersistentBubbleStashControllerTest { fun setBubblesShowingOnHomeUpdatedToFalse_barPositionYUpdated_controllersNotified() { // Given bubble bar is on home and has bubbles whenever(bubbleBarViewController.hasBubbles()).thenReturn(false) - persistentTaskBarStashController.isBubblesShowingOnHome = true + persistentTaskBarStashController.launcherState = BubbleLauncherState.HOME whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) // When switch out of the home screen getInstrumentation().runOnMainSync { - persistentTaskBarStashController.isBubblesShowingOnHome = false + persistentTaskBarStashController.launcherState = BubbleLauncherState.IN_APP } // Then translation Y is animating and the bubble bar controller is notified @@ -110,7 +111,7 @@ class PersistentBubbleStashControllerTest { // When switch to home screen getInstrumentation().runOnMainSync { - persistentTaskBarStashController.isBubblesShowingOnHome = true + persistentTaskBarStashController.launcherState = BubbleLauncherState.HOME } // Then translation Y is animating and the bubble bar controller is notified @@ -127,11 +128,11 @@ class PersistentBubbleStashControllerTest { @Test fun setBubblesShowingOnOverviewUpdatedToFalse_controllersNotified() { // Given bubble bar is on overview - persistentTaskBarStashController.isBubblesShowingOnOverview = true + persistentTaskBarStashController.launcherState = BubbleLauncherState.OVERVIEW clearInvocations(bubbleBarViewController) // When switch out of the overview screen - persistentTaskBarStashController.isBubblesShowingOnOverview = false + persistentTaskBarStashController.launcherState = BubbleLauncherState.IN_APP // Then bubble bar controller is notified verify(bubbleBarViewController).onBubbleBarConfigurationChanged(/* animate= */ true) @@ -140,7 +141,7 @@ class PersistentBubbleStashControllerTest { @Test fun setBubblesShowingOnOverviewUpdatedToTrue_controllersNotified() { // When switch to the overview screen - persistentTaskBarStashController.isBubblesShowingOnOverview = true + persistentTaskBarStashController.launcherState = BubbleLauncherState.OVERVIEW // Then bubble bar controller is notified verify(bubbleBarViewController).onBubbleBarConfigurationChanged(/* animate= */ true) @@ -150,7 +151,7 @@ class PersistentBubbleStashControllerTest { fun isSysuiLockedSwitchedToFalseForOverview_unlockAnimationIsShown() { // Given screen is locked and bubble bar has bubbles persistentTaskBarStashController.isSysuiLocked = true - persistentTaskBarStashController.isBubblesShowingOnOverview = true + persistentTaskBarStashController.launcherState = BubbleLauncherState.OVERVIEW whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) // When switch to the overview screen @@ -211,14 +212,14 @@ class PersistentBubbleStashControllerTest { fun bubbleBarTranslationYForTaskbar() { // Give bubble bar is on home whenever(bubbleBarViewController.hasBubbles()).thenReturn(false) - persistentTaskBarStashController.isBubblesShowingOnHome = true + persistentTaskBarStashController.launcherState = BubbleLauncherState.HOME // Then bubbleBarTranslationY would be HOTSEAT_TRANSLATION_Y assertThat(persistentTaskBarStashController.bubbleBarTranslationY) .isEqualTo(HOTSEAT_TRANSLATION_Y) // Give bubble bar is not on home - persistentTaskBarStashController.isBubblesShowingOnHome = false + persistentTaskBarStashController.launcherState = BubbleLauncherState.IN_APP // Then bubbleBarTranslationY would be TASK_BAR_TRANSLATION_Y assertThat(persistentTaskBarStashController.bubbleBarTranslationY) 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 d4a3b3aee9..38951c39f5 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 @@ -33,6 +33,7 @@ import com.android.launcher3.taskbar.bubbles.BubbleBarView import com.android.launcher3.taskbar.bubbles.BubbleBarViewController import com.android.launcher3.taskbar.bubbles.BubbleStashedHandleViewController import com.android.launcher3.taskbar.bubbles.BubbleView +import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.BubbleLauncherState import com.android.launcher3.util.MultiValueAlpha import com.android.wm.shell.shared.animation.PhysicsAnimator import com.android.wm.shell.shared.animation.PhysicsAnimatorTestUtils @@ -119,7 +120,7 @@ class TransientBubbleStashControllerTest { // When switch out of the home screen getInstrumentation().runOnMainSync { - mTransientBubbleStashController.isBubblesShowingOnHome = true + mTransientBubbleStashController.launcherState = BubbleLauncherState.HOME } // Then BubbleBarView is animating, BubbleBarViewController controller is notified @@ -137,12 +138,12 @@ class TransientBubbleStashControllerTest { @Test fun setBubblesShowingOnOverviewUpdatedToTrue_barPositionYUpdated_controllersNotified() { - // Given bubble bar is on home and has bubbles + // Given bubble bar is on overview and has bubbles whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) // When switch out of the home screen getInstrumentation().runOnMainSync { - mTransientBubbleStashController.isBubblesShowingOnOverview = true + mTransientBubbleStashController.launcherState = BubbleLauncherState.OVERVIEW } // Then BubbleBarView is animating, BubbleBarViewController controller is notified @@ -158,6 +159,27 @@ class TransientBubbleStashControllerTest { assertThat(bubbleBarView.translationY).isEqualTo(TASK_BAR_TRANSLATION_Y) } + @Test + fun setBubblesShowingOnOverviewUpdatedToTrue_unstashes() { + // Given bubble bar is stashed with bubbles + whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) + + getInstrumentation().runOnMainSync { + mTransientBubbleStashController.updateStashedAndExpandedState( + stash = true, + expand = false, + ) + } + assertThat(mTransientBubbleStashController.isStashed).isTrue() + + // Move to overview + getInstrumentation().runOnMainSync { + mTransientBubbleStashController.launcherState = BubbleLauncherState.OVERVIEW + } + // No longer stashed in overview + assertThat(mTransientBubbleStashController.isStashed).isFalse() + } + @Test fun updateStashedAndExpandedState_stashAndCollapse_bubbleBarHidden_stashedHandleShown() { // Given bubble bar has bubbles and not stashed @@ -200,7 +222,7 @@ class TransientBubbleStashControllerTest { // Given screen is locked and bubble bar has bubbles getInstrumentation().runOnMainSync { mTransientBubbleStashController.isSysuiLocked = true - mTransientBubbleStashController.isBubblesShowingOnOverview = true + mTransientBubbleStashController.launcherState = BubbleLauncherState.OVERVIEW whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) } advanceTimeBy(BubbleStashController.BAR_TRANSLATION_DURATION)