From 332828b340d187bdbdc5f8b1b0a67d66d412e87f Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Thu, 5 Sep 2024 16:08:41 -0700 Subject: [PATCH] Animate alpha for bubbles and background (3/n) Use separate timings for bubble icons and bubble bar background when stashing and unstashing. Follows alpha timings applied to taskbar background and icons. Bug: 345488489 Test: TransientBubbleStashControllerTest Test: stash and unstash bubble bar in app by swiping up from taskbar Test: expand and collapse bubble bar in app by swiping up on bar Test: expand and collapse bubble bar on home screen by tapping on it Flag: com.android.wm.shell.enable_bubble_bar Change-Id: I485f6346539cb6c8ea6dd4d15f25a6421021fec1 --- .../taskbar/bubbles/BubbleBarView.java | 25 +++++++++--- .../bubbles/BubbleBarViewController.java | 19 +++++++++ .../TransientBubbleStashController.kt | 39 +++++++++++++++++-- .../TransientBubbleStashControllerTest.kt | 6 +++ 4 files changed, 80 insertions(+), 9 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java index 9c6ba8bb6c..1dbf445647 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java @@ -205,7 +205,6 @@ public class BubbleBarView extends FrameLayout { public BubbleBarView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { super(context, attrs, defStyleAttr, defStyleRes); - setAlpha(0); setVisibility(INVISIBLE); mIconOverlapAmount = getResources().getDimensionPixelSize(R.dimen.bubblebar_icon_overlap); mBubbleBarPadding = getResources().getDimensionPixelSize(R.dimen.bubblebar_icon_spacing); @@ -319,6 +318,22 @@ public class BubbleBarView extends FrameLayout { mBubbleBarBackground.setScaleY(scaleY); } + /** + * Set alpha for bubble views + */ + public void setBubbleAlpha(float alpha) { + for (int i = 0; i < getChildCount(); i++) { + getChildAt(i).setAlpha(alpha); + } + } + + /** + * Set alpha for bar background + */ + public void setBackgroundAlpha(float alpha) { + mBubbleBarBackground.setAlpha((int) (255 * alpha)); + } + /** * Sets new icon sizes and newBubbleBarPadding between icons and bubble bar borders. * @@ -1029,7 +1044,7 @@ public class BubbleBarView extends FrameLayout { // where the bubble will end up when the animation ends final float targetX = expandedX + expandedBarShift; bv.setTranslationX(widthState * (targetX - collapsedX) + collapsedX); - bv.setAlpha(1); + bv.setVisibility(VISIBLE); } else { // If bar is on the right, account for bubble bar expanding and shifting left final float collapsedBarShift = onLeft ? 0 : currentWidth - collapsedWidth; @@ -1039,9 +1054,9 @@ public class BubbleBarView extends FrameLayout { // the overflow. if (widthState == 0) { if (bv.isOverflow() || i > MAX_VISIBLE_BUBBLES_COLLAPSED - 1) { - bv.setAlpha(0); + bv.setVisibility(INVISIBLE); } else { - bv.setAlpha(1); + bv.setVisibility(VISIBLE); } } } @@ -1349,7 +1364,7 @@ public class BubbleBarView extends FrameLayout { * touch bounds. */ public boolean isEventOverAnyItem(MotionEvent ev) { - if (getVisibility() == View.VISIBLE) { + if (getVisibility() == VISIBLE) { getBoundsOnScreen(mTempRect); return mTempRect.contains((int) ev.getX(), (int) ev.getY()); } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index c6803dc61a..570b1b9b4e 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -86,6 +86,9 @@ public class BubbleBarViewController { // These are exposed to {@link BubbleStashController} to animate for stashing/un-stashing private final MultiValueAlpha mBubbleBarAlpha; + private final AnimatedFloat mBubbleBarBubbleAlpha = new AnimatedFloat(this::updateBubbleAlpha); + private final AnimatedFloat mBubbleBarBackgroundAlpha = new AnimatedFloat( + this::updateBackgroundAlpha); private final AnimatedFloat mBubbleBarScaleX = new AnimatedFloat(this::updateScaleX); private final AnimatedFloat mBubbleBarScaleY = new AnimatedFloat(this::updateScaleY); private final AnimatedFloat mBubbleBarBackgroundScaleX = new AnimatedFloat( @@ -268,6 +271,14 @@ public class BubbleBarViewController { return mBubbleBarAlpha; } + public AnimatedFloat getBubbleBarBubbleAlpha() { + return mBubbleBarBubbleAlpha; + } + + public AnimatedFloat getBubbleBarBackgroundAlpha() { + return mBubbleBarBackgroundAlpha; + } + public AnimatedFloat getBubbleBarScaleX() { return mBubbleBarScaleX; } @@ -561,6 +572,14 @@ public class BubbleBarViewController { mBarView.setBackgroundScaleY(scale); } + private void updateBubbleAlpha(float alpha) { + mBarView.setBubbleAlpha(alpha); + } + + private void updateBackgroundAlpha(float alpha) { + mBarView.setBackgroundAlpha(alpha); + } + // // Manipulating the specific bubble views in the bar // 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 5f7c79c42b..5d1e890762 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/stashing/TransientBubbleStashController.kt @@ -67,6 +67,8 @@ class TransientBubbleStashController( // bubble bar properties private lateinit var bubbleBarAlpha: MultiPropertyFactory.MultiProperty + private lateinit var bubbleBarBubbleAlpha: AnimatedFloat + private lateinit var bubbleBarBackgroundAlpha: AnimatedFloat private lateinit var bubbleBarTranslationYAnimator: AnimatedFloat private lateinit var bubbleBarBackgroundScaleX: AnimatedFloat private lateinit var bubbleBarBackgroundScaleY: AnimatedFloat @@ -150,6 +152,8 @@ class TransientBubbleStashController( bubbleBarTranslationYAnimator = bubbleBarViewController.bubbleBarTranslationY // bubble bar has only alpha property, getting it at index 0 bubbleBarAlpha = bubbleBarViewController.bubbleBarAlpha.get(/* index= */ 0) + bubbleBarBubbleAlpha = bubbleBarViewController.bubbleBarBubbleAlpha + bubbleBarBackgroundAlpha = bubbleBarViewController.bubbleBarBackgroundAlpha bubbleBarBackgroundScaleX = bubbleBarViewController.bubbleBarBackgroundScaleX bubbleBarBackgroundScaleY = bubbleBarViewController.bubbleBarBackgroundScaleY stashedHeight = bubbleStashedHandleViewController?.stashedHeight ?: 0 @@ -164,7 +168,9 @@ class TransientBubbleStashController( bubbleBarBackgroundScaleX.animateToValue(1f), bubbleBarBackgroundScaleY.animateToValue(1f), bubbleBarTranslationYAnimator.animateToValue(bubbleBarTranslationY), - bubbleBarAlpha.animateToValue(1f) + bubbleBarAlpha.animateToValue(1f), + bubbleBarBubbleAlpha.animateToValue(1f), + bubbleBarBackgroundAlpha.animateToValue(1f) ) } else { isStashed = true @@ -182,6 +188,8 @@ class TransientBubbleStashController( stashHandleViewAlpha?.value = 0f this.bubbleBarTranslationYAnimator.updateValue(bubbleBarTranslationY) bubbleBarAlpha.setValue(1f) + bubbleBarBubbleAlpha.updateValue(1f) + bubbleBarBackgroundAlpha.updateValue(1f) bubbleBarBackgroundScaleX.updateValue(1f) bubbleBarBackgroundScaleY.updateValue(1f) isStashed = false @@ -193,6 +201,9 @@ class TransientBubbleStashController( stashHandleViewAlpha?.value = 1f this.bubbleBarTranslationYAnimator.updateValue(getStashTranslation()) bubbleBarAlpha.setValue(0f) + // Reset bubble and background alpha to 1 and only keep the bubble bar alpha at 0 + bubbleBarBubbleAlpha.updateValue(1f) + bubbleBarBackgroundAlpha.updateValue(1f) bubbleBarBackgroundScaleX.updateValue(getStashScaleX()) bubbleBarBackgroundScaleY.updateValue(getStashScaleY()) isStashed = true @@ -293,13 +304,22 @@ class TransientBubbleStashController( val alphaDuration = if (isStashed) duration else TASKBAR_STASH_ALPHA_DURATION val alphaDelay = if (isStashed) TASKBAR_STASH_ALPHA_START_DELAY else 0L animatorSet.play( - createStashAlphaAnimator(isStashed).apply { + createBackgroundAlphaAnimator(isStashed).apply { this.duration = max(0L, alphaDuration - alphaDelay) this.startDelay = alphaDelay this.interpolator = LINEAR } ) + val iconAlphaTarget = if (isStashed) 0f else 1f + animatorSet.play( + bubbleBarBubbleAlpha.animateToValue(iconAlphaTarget).apply { + this.duration = TASKBAR_STASH_ALPHA_DURATION + this.startDelay = TASKBAR_STASH_ALPHA_START_DELAY + this.interpolator = LINEAR + } + ) + animatorSet.play( createSpringOnStashAnimator(isStashed).apply { this.duration = duration @@ -338,10 +358,21 @@ class TransientBubbleStashController( } ) + animatorSet.doOnStart { + if (!isStashed) { + bubbleBarBackgroundAlpha.updateValue(0f) + bubbleBarBubbleAlpha.updateValue(0f) + bubbleBarAlpha.value = 1f + } + } animatorSet.doOnEnd { animator = null controllersAfterInitAction.runAfterInit { if (isStashed) { + bubbleBarAlpha.value = 0f + // reset bubble view alpha + bubbleBarBubbleAlpha.updateValue(1f) + bubbleBarBackgroundAlpha.updateValue(1f) bubbleBarViewController.isExpanded = false } taskbarInsetsController.onTaskbarOrBubblebarWindowHeightOrInsetsChanged() @@ -350,11 +381,11 @@ class TransientBubbleStashController( return animatorSet } - private fun createStashAlphaAnimator(isStashed: Boolean): AnimatorSet { + private fun createBackgroundAlphaAnimator(isStashed: Boolean): AnimatorSet { val stashHandleAlphaTarget = if (isStashed) 1f else 0f val barAlphaTarget = if (isStashed) 0f else 1f return AnimatorSet().apply { - play(bubbleBarAlpha.animateToValue(barAlphaTarget)) + play(bubbleBarBackgroundAlpha.animateToValue(barAlphaTarget)) play(stashHandleViewAlpha?.animateToValue(stashHandleAlphaTarget)) } } 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 20f1ff8e31..1d13956bd8 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 @@ -81,6 +81,8 @@ class TransientBubbleStashControllerTest { private lateinit var barScaleX: AnimatedFloat private lateinit var barScaleY: AnimatedFloat private lateinit var barAlpha: MultiValueAlpha + private lateinit var bubbleAlpha: AnimatedFloat + private lateinit var backgroundAlpha: AnimatedFloat private lateinit var stashedHandleAlpha: MultiValueAlpha private lateinit var stashedHandleScale: AnimatedFloat private lateinit var stashedHandleTranslationY: AnimatedFloat @@ -300,12 +302,16 @@ class TransientBubbleStashControllerTest { barScaleX = AnimatedFloat { value -> bubbleBarView.scaleX = value } barScaleY = AnimatedFloat { value -> bubbleBarView.scaleY = value } barAlpha = MultiValueAlpha(bubbleBarView, 1 /* num alpha channels */) + bubbleAlpha = AnimatedFloat { value -> bubbleBarView.setBubbleAlpha(value) } + backgroundAlpha = AnimatedFloat { value -> bubbleBarView.setBackgroundAlpha(value) } whenever(bubbleBarViewController.hasBubbles()).thenReturn(true) whenever(bubbleBarViewController.bubbleBarTranslationY).thenReturn(barTranslationY) whenever(bubbleBarViewController.bubbleBarBackgroundScaleX).thenReturn(barScaleX) whenever(bubbleBarViewController.bubbleBarBackgroundScaleY).thenReturn(barScaleY) whenever(bubbleBarViewController.bubbleBarAlpha).thenReturn(barAlpha) + whenever(bubbleBarViewController.bubbleBarBubbleAlpha).thenReturn(bubbleAlpha) + whenever(bubbleBarViewController.bubbleBarBackgroundAlpha).thenReturn(backgroundAlpha) whenever(bubbleBarViewController.bubbleBarCollapsedWidth).thenReturn(BUBBLE_BAR_WIDTH) whenever(bubbleBarViewController.bubbleBarCollapsedHeight).thenReturn(BUBBLE_BAR_HEIGHT) whenever(bubbleBarViewController.createRevealAnimatorForStashChange(any()))