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
This commit is contained in:
Ats Jenk
2024-09-05 16:08:41 -07:00
parent 9ca662a7f7
commit 332828b340
4 changed files with 80 additions and 9 deletions
@@ -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());
}
@@ -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
//
@@ -67,6 +67,8 @@ class TransientBubbleStashController(
// bubble bar properties
private lateinit var bubbleBarAlpha: MultiPropertyFactory<View>.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))
}
}
@@ -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()))