Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 03a4d64b authored by Mady Mellor's avatar Mady Mellor Committed by Android (Google) Code Review
Browse files

Merge "Fix the overflow button disappearing suddenly during animations" into main

parents 8953d27c 2ad0edfc
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -318,7 +318,7 @@ public class BadgedImageView extends ConstraintLayout {
    /**
     * Animates the dot to the given scale, running the optional callback when the animation ends.
     */
    private void animateDotScale(float toScale, @Nullable Runnable after) {
    public void animateDotScale(float toScale, @Nullable Runnable after) {
        mDotIsAnimating = true;

        // Don't restart the animation if we're already animating to the given value.
+4 −1
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ import android.graphics.drawable.ColorDrawable
import android.graphics.drawable.InsetDrawable
import android.util.PathParser
import android.view.LayoutInflater
import android.view.View.VISIBLE
import android.widget.FrameLayout
import com.android.launcher3.icons.BubbleIconFactory
import com.android.wm.shell.R
@@ -156,8 +157,10 @@ class BubbleOverflow(private val context: Context, private val positioner: Bubbl

    fun setShowDot(show: Boolean) {
        showDot = show
        if (overflowBtn?.visibility == VISIBLE) {
            overflowBtn?.updateDotVisibility(true /* animate */)
        }
    }

    /** Creates the expanded view for bubbles showing in the stack view. */
    private fun createExpandedView(): BubbleExpandedView {
+14 −2
Original line number Diff line number Diff line
@@ -1864,6 +1864,14 @@ public class BubbleStackView extends FrameLayout
                : GONE);
    }

    private void updateOverflowDotVisibility(boolean expanding) {
        if (mBubbleOverflow.showDot()) {
            mBubbleOverflow.getIconView().animateDotScale(expanding ? 1 : 0f, () -> {
                mBubbleOverflow.setVisible(expanding ? VISIBLE : GONE);
            });
        }
    }

    // via BubbleData.Listener
    void updateBubble(Bubble bubble) {
        animateInFlyoutForBubble(bubble);
@@ -2274,6 +2282,7 @@ public class BubbleStackView extends FrameLayout
            if (mIsExpanded && mExpandedBubble.getExpandedView() != null) {
                maybeShowManageEdu();
            }
            updateOverflowDotVisibility(true /* expanding */);
        } /* after */);
        int index;
        if (mExpandedBubble != null && BubbleOverflow.KEY.equals(mExpandedBubble.getKey())) {
@@ -2405,11 +2414,15 @@ public class BubbleStackView extends FrameLayout
        // since we're about to animate collapsed.
        mExpandedAnimationController.notifyPreparingToCollapse();

        updateOverflowDotVisibility(false /* expanding */);
        final Runnable collapseBackToStack = () -> mExpandedAnimationController.collapseBackToStack(
                mStackAnimationController
                        .getStackPositionAlongNearestHorizontalEdge()
                /* collapseTo */,
                () -> mBubbleContainer.setActiveController(mStackAnimationController));
                () -> {
                    mBubbleContainer.setActiveController(mStackAnimationController);
                    updateOverflowVisibility();
                });

        final Runnable after = () -> {
            final BubbleViewProvider previouslySelected = mExpandedBubble;
@@ -2424,7 +2437,6 @@ public class BubbleStackView extends FrameLayout
                Log.d(TAG, BubbleDebugConfig.formatBubblesString(getBubblesOnScreen(),
                        mExpandedBubble));
            }
            updateOverflowVisibility();
            updateZOrder();
            updateBadges(true /* setBadgeForCollapsedStack */);
            afterExpandedViewAnimation();
+20 −3
Original line number Diff line number Diff line
@@ -34,6 +34,8 @@ import androidx.dynamicanimation.animation.SpringForce;
import com.android.wm.shell.R;
import com.android.wm.shell.animation.Interpolators;
import com.android.wm.shell.animation.PhysicsAnimator;
import com.android.wm.shell.bubbles.BadgedImageView;
import com.android.wm.shell.bubbles.BubbleOverflow;
import com.android.wm.shell.bubbles.BubblePositioner;
import com.android.wm.shell.bubbles.BubbleStackView;
import com.android.wm.shell.common.magnetictarget.MagnetizedObject;
@@ -63,6 +65,12 @@ public class ExpandedAnimationController
    /** Damping ratio for expand/collapse spring. */
    private static final float DAMPING_RATIO_MEDIUM_LOW_BOUNCY = 0.65f;

    /**
     * Damping ratio for the overflow bubble spring; this is less bouncy so it doesn't bounce behind
     * the top bubble when it goes to disappear.
     */
    private static final float DAMPING_RATIO_OVERFLOW_BOUNCY = 0.90f;

    /** Stiffness for the expand/collapse path-following animation. */
    private static final int EXPAND_COLLAPSE_ANIM_STIFFNESS = 400;

@@ -274,9 +282,14 @@ public class ExpandedAnimationController
                // of the screen where the bubble will be stacked.
                path.lineTo(stackedX, p.y);

                // The overflow should animate to the collapse point, so 0 offset.
                final boolean isOverflow = bubble instanceof BadgedImageView
                        && BubbleOverflow.KEY.equals(((BadgedImageView) bubble).getKey());
                final float offsetY = isOverflow
                        ? 0
                        : Math.min(index, NUM_VISIBLE_WHEN_RESTING - 1) * mStackOffsetPx;
                // Then, draw a line down to the stack position.
                path.lineTo(stackedX, mCollapsePoint.y
                        + Math.min(index, NUM_VISIBLE_WHEN_RESTING - 1) * mStackOffsetPx);
                path.lineTo(stackedX, mCollapsePoint.y + offsetY);
            }

            // The lead bubble should be the bubble with the longest distance to travel when we're
@@ -505,8 +518,12 @@ public class ExpandedAnimationController

    @Override
    SpringForce getSpringForce(DynamicAnimation.ViewProperty property, View view) {
        boolean isOverflow = (view instanceof BadgedImageView)
                && BubbleOverflow.KEY.equals(((BadgedImageView) view).getKey());
        return new SpringForce()
                .setDampingRatio(DAMPING_RATIO_MEDIUM_LOW_BOUNCY)
                .setDampingRatio(isOverflow
                        ? DAMPING_RATIO_OVERFLOW_BOUNCY
                        : DAMPING_RATIO_MEDIUM_LOW_BOUNCY)
                .setStiffness(SpringForce.STIFFNESS_LOW);
    }