diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index 45e6199057..9270f68f92 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -250,7 +250,7 @@ public class BubbleBarViewController { return mBubbleBarTranslationY; } - float getBubbleBarCollapsedHeight() { + public float getBubbleBarCollapsedHeight() { return mBarView.getBubbleBarCollapsedHeight(); } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt new file mode 100644 index 0000000000..e42b6d6769 --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/BubbleStashController.kt @@ -0,0 +1,202 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.taskbar.bubbles.stashing + +import android.view.InsetsController +import android.view.MotionEvent +import android.view.View +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.BubbleStashedHandleViewController +import com.android.wm.shell.common.bubbles.BubbleBarLocation +import com.android.wm.shell.shared.animation.PhysicsAnimator +import java.io.PrintWriter + +/** StashController that defines stashing behaviour for the taskbar modes. */ +interface BubbleStashController { + + /** + * Abstraction on the task bar activity context to only provide the dimensions required for + * [BubbleBarView] translation Y computation. + */ + interface TaskbarHotseatDimensionsProvider { + + /** Provides taskbar bottom space in pixels. */ + fun getTaskbarBottomSpace(): Int + + /** 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. */ + interface ControllersAfterInitAction { + /** Execute action after controllers are initiated. */ + fun runAfterInit(action: () -> Unit) + } + + /** Whether bubble bar is currently stashed */ + val isStashed: Boolean + + /** Whether launcher enters or exits the home page. */ + var isBubblesShowingOnHome: Boolean + + /** Whether launcher enters or exits the overview page. */ + var isBubblesShowingOnOverview: Boolean + + /** Updated when sysui locked state changes, when locked, bubble bar is not shown. */ + var isSysuiLocked: Boolean + + /** Whether there is a transient taskbar mode */ + val isTransientTaskBar: Boolean + + /** Whether stash control has a handle view */ + val hasHandleView: Boolean + + /** Initialize controller */ + fun init( + taskbarInsetsController: TaskbarInsetsController, + bubbleBarViewController: BubbleBarViewController, + bubbleStashedHandleViewController: BubbleStashedHandleViewController?, + controllersAfterInitAction: ControllersAfterInitAction + ) + + /** Sets stashed and expanded state of the bubble bar */ + fun updateStashedAndExpandedState(stash: Boolean = false, expand: Boolean = false) + + /** + * Shows the bubble bar at [getBubbleBarTranslationY] position immediately without animation. + */ + fun showBubbleBarImmediate() + + /** Shows the bubble bar at [bubbleBarTranslationY] position immediately without animation. */ + fun showBubbleBarImmediate(bubbleBarTranslationY: Float) + + /** Stashes the bubble bar immediately without animation. */ + fun stashBubbleBarImmediate() + + /** Returns the touchable height of the bubble bar based on it's stashed state. */ + fun getTouchableHeight(): Int + + /** Whether bubble bar is currently visible */ + fun isBubbleBarVisible(): Boolean + + /** + * Updates the values of the internal animators after the new bubble animation was interrupted + * + * @param isStashed whether the current state should be stashed + * @param bubbleBarTranslationY the current bubble bar translation. this is only used if the + * bubble bar is showing to ensure that the stash animator runs smoothly. + */ + fun onNewBubbleAnimationInterrupted(isStashed: Boolean, bubbleBarTranslationY: Float) + + /** Checks whether the motion event is over the stash handle or bubble bar. */ + fun isEventOverBubbleBarViews(ev: MotionEvent): Boolean + + /** Set a bubble bar location */ + fun setBubbleBarLocation(bubbleBarLocation: BubbleBarLocation) + + /** + * Stashes the bubble bar (transform to the handle view), or just shrink width of the expanded + * bubble bar based on the controller implementation. + */ + fun stashBubbleBar() { + updateStashedAndExpandedState(stash = true, expand = false) + } + + /** Shows the bubble bar, and expands bubbles depending on [expandBubbles]. */ + fun showBubbleBar(expandBubbles: Boolean) { + updateStashedAndExpandedState(stash = false, expandBubbles) + } + + // TODO(b/354218264): Move to BubbleBarViewAnimator + /** + * The difference on the Y axis between the center of the handle and the center of the bubble + * bar. + */ + fun getSlideInAnimationDistanceY(): Float + + // TODO(b/354218264): Move to BubbleBarViewAnimator + /** The distance the handle moves as part of the new bubble animation. */ + fun getStashedHandleTranslationForNewBubbleAnimation(): Float + + // TODO(b/354218264): Move to BubbleBarViewAnimator + /** Returns the [PhysicsAnimator] for the stashed handle view. */ + fun getStashedHandlePhysicsAnimator(): PhysicsAnimator? + + // TODO(b/354218264): Move to BubbleBarViewAnimator + /** Notifies taskbar that it should update its touchable region. */ + fun updateTaskbarTouchRegion() + + // TODO(b/354218264): Move to BubbleBarViewAnimator + /** Set the translation Y for the stashed handle. */ + fun setHandleTranslationY(translationY: Float) + + /** + * Returns bubble bar Y position according to [isBubblesShowingOnHome] and + * [isBubblesShowingOnOverview] values. Default implementation only analyse + * [isBubblesShowingOnHome] and return translationY to align with the hotseat vertical center. + * For Other cases align bubbles with the taskbar. + */ + val bubbleBarTranslationY: Float + get() = + if (isBubblesShowingOnHome) { + bubbleBarTranslationYForHotseat + } else { + bubbleBarTranslationYForTaskbar + } + + /** Translation Y to align the bubble bar with the hotseat. */ + val bubbleBarTranslationYForTaskbar: Float + + /** Return translation Y to align the bubble bar with the taskbar. */ + val bubbleBarTranslationYForHotseat: Float + + /** Dumps the state of BubbleStashController. */ + fun dump(pw: PrintWriter) { + pw.println("Bubble stash controller state:") + pw.println(" isStashed: $isStashed") + pw.println(" isBubblesShowingOnOverview: $isBubblesShowingOnOverview") + pw.println(" isBubblesShowingOnHome: $isBubblesShowingOnHome") + pw.println(" isSysuiLocked: $isSysuiLocked") + } + + companion object { + /** How long to stash/unstash. */ + const val BAR_STASH_DURATION = InsetsController.ANIMATION_DURATION_RESIZE.toLong() + + /** How long to translate Y coordinate of the BubbleBar. */ + const val BAR_TRANSLATION_DURATION = 300L + + /** The scale bubble bar animates to when being stashed. */ + const val STASHED_BAR_SCALE = 0.5f + + /** Creates new instance of [BubbleStashController] */ + @JvmStatic + fun newInstance( + taskbarHotseatDimensionsProvider: TaskbarHotseatDimensionsProvider + ): BubbleStashController { + return PersistentTaskbarStashController(taskbarHotseatDimensionsProvider) + } + } +} diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentTaskbarStashController.kt b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentTaskbarStashController.kt new file mode 100644 index 0000000000..4a05a5ebfc --- /dev/null +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentTaskbarStashController.kt @@ -0,0 +1,223 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.taskbar.bubbles.stashing + +import android.animation.Animator +import android.animation.AnimatorListenerAdapter +import android.animation.AnimatorSet +import android.view.MotionEvent +import android.view.View +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.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 +import com.android.launcher3.taskbar.bubbles.stashing.BubbleStashController.TaskbarHotseatDimensionsProvider +import com.android.launcher3.util.MultiPropertyFactory +import com.android.wm.shell.common.bubbles.BubbleBarLocation +import com.android.wm.shell.shared.animation.PhysicsAnimator + +class PersistentTaskbarStashController( + private val taskbarHotseatDimensionsProvider: TaskbarHotseatDimensionsProvider, +) : BubbleStashController { + + private lateinit var taskbarInsetsController: TaskbarInsetsController + private lateinit var bubbleBarViewController: BubbleBarViewController + private lateinit var bubbleBarTranslationYAnimator: AnimatedFloat + private lateinit var bubbleBarAlphaAnimator: MultiPropertyFactory.MultiProperty + private lateinit var bubbleBarScaleAnimator: AnimatedFloat + private lateinit var controllersAfterInitAction: ControllersAfterInitAction + + override var isBubblesShowingOnHome: Boolean = false + set(onHome) { + if (field == onHome) return + field = onHome + 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 + updateStashedAndExpandedState(stash = false, 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 + updateStashedAndExpandedState(stash = false, expand = false) + } + bubbleBarViewController.onBubbleBarConfigurationChanged(/* animate= */ true) + } + + override var isSysuiLocked: Boolean = false + set(isLocked) { + if (field == isLocked) return + field = isLocked + if (!isLocked && bubbleBarViewController.hasBubbles()) { + animateAfterUnlock() + } + } + + override var isTransientTaskBar: Boolean = false + + /** When the bubble bar is shown for the persistent task bar, there is no handle view. */ + override val hasHandleView: Boolean = false + + /** For persistent task bar we never stash the bubble bar */ + override val isStashed: Boolean = false + + override val bubbleBarTranslationYForTaskbar: Float + get() { + val taskbarBottomMargin = taskbarHotseatDimensionsProvider.getTaskbarBottomSpace() + val bubbleBarHeight: Float = bubbleBarViewController.bubbleBarCollapsedHeight + val taskbarHeight = taskbarHotseatDimensionsProvider.getTaskbarHeight() + return -taskbarBottomMargin - (taskbarHeight - bubbleBarHeight) / 2f + } + + override val bubbleBarTranslationYForHotseat: Float + get() { + val hotseatBottomSpace = taskbarHotseatDimensionsProvider.getHotseatBottomSpace() + val hotseatCellHeight = taskbarHotseatDimensionsProvider.getHotseatHeight() + val bubbleBarHeight: Float = bubbleBarViewController.bubbleBarCollapsedHeight + return -hotseatBottomSpace - (hotseatCellHeight - bubbleBarHeight) / 2 + } + + override fun init( + taskbarInsetsController: TaskbarInsetsController, + bubbleBarViewController: BubbleBarViewController, + bubbleStashedHandleViewController: BubbleStashedHandleViewController?, + controllersAfterInitAction: ControllersAfterInitAction + ) { + this.taskbarInsetsController = taskbarInsetsController + this.bubbleBarViewController = bubbleBarViewController + this.controllersAfterInitAction = controllersAfterInitAction + bubbleBarTranslationYAnimator = bubbleBarViewController.bubbleBarTranslationY + bubbleBarAlphaAnimator = bubbleBarViewController.bubbleBarAlpha.get(0) + bubbleBarScaleAnimator = bubbleBarViewController.bubbleBarScale + } + + private fun animateAfterUnlock() { + val animatorSet = AnimatorSet() + if (isBubblesShowingOnHome || isBubblesShowingOnOverview) { + animatorSet.playTogether( + bubbleBarScaleAnimator.animateToValue(1f), + bubbleBarTranslationYAnimator.animateToValue(bubbleBarTranslationY), + bubbleBarAlphaAnimator.animateToValue(1f) + ) + } + updateTouchRegionOnAnimationEnd(animatorSet) + animatorSet.setDuration(BAR_STASH_DURATION).start() + } + + override fun updateStashedAndExpandedState(stash: Boolean, expand: Boolean) { + if (bubbleBarViewController.isHiddenForNoBubbles) { + // If there are no bubbles the bar is invisible, nothing to do here. + return + } + if (bubbleBarViewController.isExpanded != expand) { + bubbleBarViewController.isExpanded = expand + } + } + + override fun showBubbleBarImmediate() = showBubbleBarImmediate(bubbleBarTranslationY) + + override fun showBubbleBarImmediate(bubbleBarTranslationY: Float) { + bubbleBarTranslationYAnimator.updateValue(bubbleBarTranslationY) + bubbleBarAlphaAnimator.setValue(1f) + bubbleBarScaleAnimator.updateValue(1f) + } + + override fun setBubbleBarLocation(bubbleBarLocation: BubbleBarLocation) { + // When the bubble bar is shown for the persistent task bar, there is no handle view, so no + // operation is performed. + } + + override fun stashBubbleBarImmediate() { + // When the bubble bar is shown for the persistent task bar, there is no handle view, so no + // operation is performed. + } + + /** If bubble bar is visible return bubble bar height, 0 otherwise */ + override fun getTouchableHeight() = + if (isBubbleBarVisible()) { + bubbleBarViewController.bubbleBarCollapsedHeight.toInt() + } else { + 0 + } + + override fun isBubbleBarVisible(): Boolean = bubbleBarViewController.hasBubbles() + + override fun onNewBubbleAnimationInterrupted(isStashed: Boolean, bubbleBarTranslationY: Float) { + showBubbleBarImmediate(bubbleBarTranslationY) + } + + override fun isEventOverBubbleBarViews(ev: MotionEvent): Boolean = + bubbleBarViewController.isEventOverAnyItem(ev) + + override fun getSlideInAnimationDistanceY(): Float { + // distance from the bottom of the screen and the bubble bar center. + return -bubbleBarViewController.bubbleBarCollapsedHeight / 2f + } + + /** When the bubble bar is shown for the persistent task bar, there is no handle view. */ + override fun getStashedHandleTranslationForNewBubbleAnimation(): Float = 0f + + /** When the bubble bar is shown for the persistent task bar, there is no handle view. */ + override fun getStashedHandlePhysicsAnimator(): PhysicsAnimator? = null + + override fun updateTaskbarTouchRegion() { + taskbarInsetsController.onTaskbarOrBubblebarWindowHeightOrInsetsChanged() + } + + /** + * When the bubble bar is shown for the persistent task bar the bar does not stash, so no + * operation is performed + */ + override fun setHandleTranslationY(translationY: Float) { + // no op since does not have a handle view + } + + /** Animates bubble bar Y accordingly to the showing mode */ + private fun animateBubbleBarY() { + val animator = + bubbleBarViewController.bubbleBarTranslationY.animateToValue(bubbleBarTranslationY) + updateTouchRegionOnAnimationEnd(animator) + animator.setDuration(BAR_TRANSLATION_DURATION) + animator.start() + } + + private fun updateTouchRegionOnAnimationEnd(animator: Animator) { + animator.addListener( + object : AnimatorListenerAdapter() { + + override fun onAnimationEnd(animation: Animator) { + controllersAfterInitAction.runAfterInit { + taskbarInsetsController.onTaskbarOrBubblebarWindowHeightOrInsetsChanged() + } + } + } + ) + } +} diff --git a/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentTaskbarStashControllerTest.kt b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentTaskbarStashControllerTest.kt new file mode 100644 index 0000000000..c46c08d860 --- /dev/null +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/PersistentTaskbarStashControllerTest.kt @@ -0,0 +1,256 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.taskbar.bubbles.stashing + +import android.animation.AnimatorTestRule +import android.content.Context +import android.widget.FrameLayout +import androidx.test.core.app.ApplicationProvider +import androidx.test.ext.junit.runners.AndroidJUnit4 +import androidx.test.filters.SmallTest +import androidx.test.platform.app.InstrumentationRegistry.getInstrumentation +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.util.MultiValueAlpha +import com.google.common.truth.Truth.assertThat +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.junit.runner.RunWith +import org.mockito.Mock +import org.mockito.junit.MockitoJUnit +import org.mockito.junit.MockitoRule +import org.mockito.kotlin.clearInvocations +import org.mockito.kotlin.verify +import org.mockito.kotlin.whenever + +/** Unit tests for [PersistentTaskbarStashController]. */ +@SmallTest +@RunWith(AndroidJUnit4::class) +class PersistentTaskbarStashControllerTest { + + companion object { + const val BUBBLE_BAR_HEIGHT = 100f + const val HOTSEAT_TRANSLATION_Y = -45f + const val TASK_BAR_TRANSLATION_Y = -5f + } + + @get:Rule val animatorTestRule: AnimatorTestRule = AnimatorTestRule(this) + @get:Rule val rule: MockitoRule = MockitoJUnit.rule() + + private val context = ApplicationProvider.getApplicationContext() + private lateinit var bubbleBarView: BubbleBarView + + @Mock lateinit var bubbleBarViewController: BubbleBarViewController + @Mock lateinit var taskbarInsetsController: TaskbarInsetsController + + private lateinit var persistentTaskBarStashController: PersistentTaskbarStashController + private lateinit var translationY: AnimatedFloat + private lateinit var scale: AnimatedFloat + private lateinit var alpha: MultiValueAlpha + + @Before + fun setUp() { + persistentTaskBarStashController = + PersistentTaskbarStashController(DefaultDimensionsProvider()) + setUpBubbleBarView() + setUpBubbleBarController() + persistentTaskBarStashController.init( + taskbarInsetsController, + bubbleBarViewController, + null, + ImmediateAction() + ) + } + + @Test + fun setBubblesShowingOnHomeUpdatedToFalse_barPositionYUpdated_controllersNotified() { + // Given bubble bar is on home and has bubbles + whenever(bubbleBarViewController.hasBubbles()).thenReturn(false) + persistentTaskBarStashController.isBubblesShowingOnHome = true + whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) + + // When switch out of the home screen + getInstrumentation().runOnMainSync { + persistentTaskBarStashController.isBubblesShowingOnHome = false + } + + // Then translation Y is animating and the bubble bar controller is notified + assertThat(translationY.isAnimating).isTrue() + verify(bubbleBarViewController).onBubbleBarConfigurationChanged(/* animate= */ true) + // Wait until animation ends + advanceTimeBy(BubbleStashController.BAR_TRANSLATION_DURATION) + // Check translation Y is correct and the insets controller is notified + assertThat(bubbleBarView.translationY).isEqualTo(TASK_BAR_TRANSLATION_Y) + verify(taskbarInsetsController).onTaskbarOrBubblebarWindowHeightOrInsetsChanged() + } + + @Test + fun setBubblesShowingOnHomeUpdatedToTrue_barPositionYUpdated_controllersNotified() { + // Given bubble bar has bubbles + whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) + + // When switch to home screen + getInstrumentation().runOnMainSync { + persistentTaskBarStashController.isBubblesShowingOnHome = true + } + + // Then translation Y is animating and the bubble bar controller is notified + assertThat(translationY.isAnimating).isTrue() + verify(bubbleBarViewController).onBubbleBarConfigurationChanged(/* animate= */ true) + // Wait until animation ends + advanceTimeBy(BubbleStashController.BAR_TRANSLATION_DURATION) + + // Check translation Y is correct and the insets controller is notified + assertThat(bubbleBarView.translationY).isEqualTo(HOTSEAT_TRANSLATION_Y) + verify(taskbarInsetsController).onTaskbarOrBubblebarWindowHeightOrInsetsChanged() + } + + @Test + fun setBubblesShowingOnOverviewUpdatedToFalse_controllersNotified() { + // Given bubble bar is on overview + persistentTaskBarStashController.isBubblesShowingOnOverview = true + clearInvocations(bubbleBarViewController) + + // When switch out of the overview screen + persistentTaskBarStashController.isBubblesShowingOnOverview = false + + // Then bubble bar controller is notified + verify(bubbleBarViewController).onBubbleBarConfigurationChanged(/* animate= */ true) + } + + @Test + fun setBubblesShowingOnOverviewUpdatedToTrue_controllersNotified() { + // When switch to the overview screen + persistentTaskBarStashController.isBubblesShowingOnOverview = true + + // Then bubble bar controller is notified + verify(bubbleBarViewController).onBubbleBarConfigurationChanged(/* animate= */ true) + } + + @Test + fun isSysuiLockedSwitchedToFalseForOverview_unlockAnimationIsShown() { + // Given screen is locked and bubble bar has bubbles + persistentTaskBarStashController.isSysuiLocked = true + persistentTaskBarStashController.isBubblesShowingOnOverview = true + whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) + + // When switch to the overview screen + getInstrumentation().runOnMainSync { + persistentTaskBarStashController.isSysuiLocked = false + } + + // Then + assertThat(translationY.isAnimating).isTrue() + assertThat(scale.isAnimating).isTrue() + // Wait until animation ends + advanceTimeBy(BubbleStashController.BAR_STASH_DURATION) + + // Then bubble bar is fully visible at the correct location + assertThat(bubbleBarView.scaleX).isEqualTo(1f) + assertThat(bubbleBarView.scaleY).isEqualTo(1f) + assertThat(bubbleBarView.translationY).isEqualTo(TASK_BAR_TRANSLATION_Y) + assertThat(bubbleBarView.alpha).isEqualTo(1f) + // Insets controller is notified + verify(taskbarInsetsController).onTaskbarOrBubblebarWindowHeightOrInsetsChanged() + } + + @Test + fun showBubbleBarImmediateToY() { + // Given bubble bar is fully transparent and scaled to 0 at 0 y position + val targetY = 341f + bubbleBarView.alpha = 0f + bubbleBarView.scaleX = 0f + bubbleBarView.scaleY = 0f + bubbleBarView.translationY = 0f + + // When + persistentTaskBarStashController.showBubbleBarImmediate(targetY) + + // Then all property values are updated + assertThat(bubbleBarView.translationY).isEqualTo(targetY) + assertThat(bubbleBarView.alpha).isEqualTo(1f) + assertThat(bubbleBarView.scaleX).isEqualTo(1f) + assertThat(bubbleBarView.scaleY).isEqualTo(1f) + } + + @Test + fun isTransientTaskbar_false() { + assertThat(persistentTaskBarStashController.isTransientTaskBar).isFalse() + } + + @Test + fun hasHandleView_false() { + assertThat(persistentTaskBarStashController.hasHandleView).isFalse() + } + + @Test + fun isStashed_false() { + assertThat(persistentTaskBarStashController.isStashed).isFalse() + } + + @Test + fun bubbleBarTranslationYForTaskbar() { + // Give bubble bar is on home + whenever(bubbleBarViewController.hasBubbles()).thenReturn(false) + persistentTaskBarStashController.isBubblesShowingOnHome = true + + // Then bubbleBarTranslationY would be HOTSEAT_TRANSLATION_Y + assertThat(persistentTaskBarStashController.bubbleBarTranslationY) + .isEqualTo(HOTSEAT_TRANSLATION_Y) + + // Give bubble bar is not on home + persistentTaskBarStashController.isBubblesShowingOnHome = false + + // Then bubbleBarTranslationY would be TASK_BAR_TRANSLATION_Y + assertThat(persistentTaskBarStashController.bubbleBarTranslationY) + .isEqualTo(TASK_BAR_TRANSLATION_Y) + } + + private fun advanceTimeBy(advanceMs: Long) { + // Advance animator for on-device tests + getInstrumentation().runOnMainSync { animatorTestRule.advanceTimeBy(advanceMs) } + } + + private fun setUpBubbleBarView() { + getInstrumentation().runOnMainSync { + bubbleBarView = BubbleBarView(context) + bubbleBarView.layoutParams = FrameLayout.LayoutParams(0, 0) + } + } + + private fun setUpBubbleBarController() { + translationY = AnimatedFloat(Runnable { bubbleBarView.translationY = translationY.value }) + scale = + AnimatedFloat( + Runnable { + val scale: Float = scale.value + bubbleBarView.scaleX = scale + bubbleBarView.scaleY = scale + } + ) + alpha = MultiValueAlpha(bubbleBarView, 1 /* num alpha channels */) + + whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) + whenever(bubbleBarViewController.bubbleBarTranslationY).thenReturn(translationY) + whenever(bubbleBarViewController.bubbleBarScale).thenReturn(scale) + whenever(bubbleBarViewController.bubbleBarAlpha).thenReturn(alpha) + whenever(bubbleBarViewController.bubbleBarCollapsedHeight).thenReturn(BUBBLE_BAR_HEIGHT) + } +} 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 new file mode 100644 index 0000000000..5dc9440d12 --- /dev/null +++ b/quickstep/tests/multivalentTests/src/com/android/launcher3/taskbar/bubbles/stashing/StashingTestUtils.kt @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2024 The Android Open Source Project + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.android.launcher3.taskbar.bubbles.stashing + +class ImmediateAction : BubbleStashController.ControllersAfterInitAction { + override fun runAfterInit(action: () -> Unit) = action.invoke() +} + +class DefaultDimensionsProvider : BubbleStashController.TaskbarHotseatDimensionsProvider { + override fun getTaskbarBottomSpace(): Int = TASKBAR_BOTTOM_SPACE + + override fun getTaskbarHeight(): Int = TASKBAR_HEIGHT + + override fun getHotseatBottomSpace(): Int = HOTSEAT_BOTTOM_SPACE + + override fun getHotseatHeight(): Int = HOTSEAT_HEIGHT + + companion object { + const val TASKBAR_BOTTOM_SPACE = 0 + const val TASKBAR_HEIGHT = 110 + const val HOTSEAT_BOTTOM_SPACE = 20 + const val HOTSEAT_HEIGHT = 150 + } +}