From f1f507e8c38c348da97d69d6428b78769a2f3954 Mon Sep 17 00:00:00 2001 From: Ats Jenk Date: Wed, 23 Apr 2025 16:30:37 -0700 Subject: [PATCH] Do not animate bubble bar for initial state [2/N] Initial state for bubble bar does not need to be animated. Especially if it is sent after rotation. In that case we do not want it to animate. When launcher is rotated, taskbar is recreated. After getting recreated, we receive the initial state from WMShell for the bubbles again. Part of the initial state is whether bubble bar is expanded or not. Bug: 357115534 Flag: com.android.wm.shell.enable_bubble_bar Test: rotate device Change-Id: I859b73597c8f286069f384dcdea0e3a5296e0073 --- .../taskbar/bubbles/BubbleBarController.java | 4 +- .../taskbar/bubbles/BubbleBarView.java | 87 ++++++++++++------- .../bubbles/BubbleBarViewController.java | 18 +++- 3 files changed, 73 insertions(+), 36 deletions(-) diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java index b6a0ffe53c..fa6d8c1b48 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarController.java @@ -505,7 +505,9 @@ public class BubbleBarController extends IBubblesListener.Stub { } if (update.expandedChanged) { if (update.expanded != mBubbleBarViewController.isExpanded()) { - mBubbleBarViewController.setExpandedFromSysui(update.expanded); + // If we start as expanded, show bar immediately without waiting for animation. + boolean animate = !update.initialState; + mBubbleBarViewController.setExpandedFromSysui(update.expanded, animate); } else { Log.w(TAG, "expansion was changed but is the same"); } diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java index f104d93094..a572d73f5a 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarView.java @@ -145,7 +145,8 @@ public class BubbleBarView extends FrameLayout { // An animator that represents the expansion state of the bubble bar, where 0 corresponds to the // collapsed state and 1 to the fully expanded state. - private ValueAnimator mWidthAnimator = createExpansionAnimator(/* expanding = */ false); + @Nullable + private ValueAnimator mWidthAnimator; @Nullable private ValueAnimator mDismissAnimator = null; @@ -1007,7 +1008,12 @@ public class BubbleBarView extends FrameLayout { * on the expanded state. */ private void updateBubblesLayoutProperties(BubbleBarLocation bubbleBarLocation) { - final float widthState = (float) mWidthAnimator.getAnimatedValue(); + final float widthState; + if (mWidthAnimator == null) { + widthState = mIsBarExpanded ? 1f : 0f; + } else { + widthState = (float) mWidthAnimator.getAnimatedValue(); + } final float currentWidth = getWidth(); final float expandedWidth = expandedWidth(); final float collapsedWidth = collapsedWidth(); @@ -1044,7 +1050,7 @@ public class BubbleBarView extends FrameLayout { bv.setZ(fullElevationForChild * elevationState); // only update the dot and badge scale if we're expanding or collapsing - if (mWidthAnimator.isRunning()) { + if (mWidthAnimator != null && mWidthAnimator.isRunning()) { // The dot for the selected bubble scales in the opposite direction of the expansion // animation. bv.showDotIfNeeded(bv == mSelectedBubbleView ? 1 - widthState : widthState); @@ -1160,7 +1166,7 @@ public class BubbleBarView extends FrameLayout { * Reorders the views to match the provided list. */ public void reorder(List viewOrder) { - if (isExpanded() || mWidthAnimator.isRunning()) { + if (isExpanded() || (mWidthAnimator != null && mWidthAnimator.isRunning())) { mReorderRunnable = () -> doReorder(viewOrder); } else { doReorder(viewOrder); @@ -1308,22 +1314,39 @@ public class BubbleBarView extends FrameLayout { super.setOnClickListener(mIsBarExpanded ? null : mOnClickListener); } + /** + * Update bubble bar expanded state. + */ + public void setExpanded(boolean isBarExpanded) { + setExpandedInternal(isBarExpanded, false); + } + /** * Update bubble bar expanded state with animation. + *

+ * Also triggers a talkback announcement for accessibility. */ public void animateExpanded(boolean isBarExpanded) { - if (mIsBarExpanded != isBarExpanded) { - mIsBarExpanded = isBarExpanded; - updateArrowForSelected(/* shouldAnimate= */ false); - setOrUnsetClickListener(); + setExpandedInternal(isBarExpanded, true); + } + + private void setExpandedInternal(boolean isBarExpanded, boolean animate) { + if (mIsBarExpanded == isBarExpanded) return; + mIsBarExpanded = isBarExpanded; + updateArrowForSelected(/* shouldAnimate= */ false); + setOrUnsetClickListener(); + if (animate) { mWidthAnimator = createExpansionAnimator(isBarExpanded); mWidthAnimator.start(); - updateBubbleAccessibilityStates(); announceExpandedStateChange(); - mController.onBubbleBarExpandedStateChanged(mIsBarExpanded); + } else { + onExpandedChanged(); } + updateBubbleAccessibilityStates(); + mController.onBubbleBarExpandedStateChanged(mIsBarExpanded); } + /** * Returns whether the bubble bar is expanded. */ @@ -1335,7 +1358,7 @@ public class BubbleBarView extends FrameLayout { * Returns whether the bubble bar is expanding. */ public boolean isExpanding() { - return mWidthAnimator.isRunning() && mIsBarExpanded; + return mWidthAnimator != null && mWidthAnimator.isRunning() && mIsBarExpanded; } /** @@ -1584,26 +1607,7 @@ public class BubbleBarView extends FrameLayout { animator.setInterpolator(Interpolators.EMPHASIZED); addAnimationCallBacks(animator, /* onStart= */ () -> mBubbleBarBackground.showArrow(true), - /* onEnd= */ () -> { - mBubbleBarBackground.showArrow(mIsBarExpanded); - if (!mIsBarExpanded && mReorderRunnable != null) { - mReorderRunnable.run(); - mReorderRunnable = null; - } - // If the bar was just collapsed and the overflow was the last bubble that was - // selected, set the first bubble as selected. - if (!mIsBarExpanded && mUpdateSelectedBubbleAfterCollapse != null - && mSelectedBubbleView != null - && mSelectedBubbleView.getBubble() instanceof BubbleBarOverflow) { - BubbleView firstBubble = (BubbleView) getChildAt(0); - mUpdateSelectedBubbleAfterCollapse.accept(firstBubble.getBubble().getKey()); - } - // If the bar was just expanded, remove the dot from the selected bubble. - if (mIsBarExpanded && mSelectedBubbleView != null) { - mSelectedBubbleView.markSeen(); - } - updateLayoutParams(); - }, + /* onEnd= */ this::onExpandedChanged, /* onUpdate= */ anim -> { updateBubblesLayoutProperties(mBubbleBarLocation); invalidate(); @@ -1611,6 +1615,27 @@ public class BubbleBarView extends FrameLayout { return animator; } + private void onExpandedChanged() { + mBubbleBarBackground.showArrow(mIsBarExpanded); + if (!mIsBarExpanded && mReorderRunnable != null) { + mReorderRunnable.run(); + mReorderRunnable = null; + } + // If the bar was just collapsed and the overflow was the last bubble that was + // selected, set the first bubble as selected. + if (!mIsBarExpanded && mUpdateSelectedBubbleAfterCollapse != null + && mSelectedBubbleView != null + && mSelectedBubbleView.getBubble() instanceof BubbleBarOverflow) { + BubbleView firstBubble = (BubbleView) getChildAt(0); + mUpdateSelectedBubbleAfterCollapse.accept(firstBubble.getBubble().getKey()); + } + // If the bar was just expanded, remove the dot from the selected bubble. + if (mIsBarExpanded && mSelectedBubbleView != null) { + mSelectedBubbleView.markSeen(); + } + updateLayoutParams(); + } + /** * Returns the distance between the top left corner of the bubble bar to the center of the dot * of the selected bubble. diff --git a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java index c74140a8fe..e22577d262 100644 --- a/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java +++ b/quickstep/src/com/android/launcher3/taskbar/bubbles/BubbleBarViewController.java @@ -1298,15 +1298,25 @@ public class BubbleBarViewController { * Sets whether the bubble bar should be expanded. This method is used in response to UI events * from SystemUI. */ - public void setExpandedFromSysui(boolean isExpanded) { + public void setExpandedFromSysui(boolean isExpanded, boolean animate) { if (isNewBubbleAnimationRunningOrPending() && isExpanded) { mBubbleBarViewAnimator.expandedWhileAnimating(); return; } - if (!isExpanded) { - mBubbleStashController.stashBubbleBar(); + if (animate) { + if (!isExpanded) { + mBubbleStashController.stashBubbleBar(); + } else { + mBubbleStashController.showBubbleBar(true /* expand the bubbles */); + } } else { - mBubbleStashController.showBubbleBar(true /* expand the bubbles */); + if (!isExpanded) { + mBubbleStashController.stashBubbleBarImmediate(); + } else { + mBubbleStashController.showBubbleBarImmediate(); + mBarView.setExpanded(true); + adjustTaskbarAndHotseatToBubbleBarState(true); + } } }