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

Commit fe4a1db2 authored by Ats Jenk's avatar Ats Jenk
Browse files

Animate bubble overflow when it opens from a shortcut

Flag: com.android.wm.shell.enable_retrievable_bubbles
Bug: 340337839
Test: manual
Change-Id: Ia1bc4da40ed94b18c40752454e83b539fbc9f870
parent 936749e8
Loading
Loading
Loading
Loading
+86 −6
Original line number Diff line number Diff line
@@ -134,6 +134,8 @@ public class BubbleStackView extends FrameLayout

    private static final float EXPANDED_VIEW_ANIMATE_SCALE_AMOUNT = 0.1f;

    private static final float OPEN_OVERFLOW_ANIMATE_SCALE_AMOUNT = 0.5f;

    private static final int EXPANDED_VIEW_ALPHA_ANIMATION_DURATION = 150;

    /** Minimum alpha value for scrim when alpha is being changed via drag */
@@ -1549,10 +1551,20 @@ public class BubbleStackView extends FrameLayout
    }

    private void updateOverflowVisibility() {
        mBubbleOverflow.setVisible(mShowingOverflow
                && (mIsExpanded || mBubbleData.isShowingOverflow())
                ? VISIBLE
                : GONE);
        int visibility = GONE;
        if (mShowingOverflow) {
            if (mIsExpanded || mBubbleData.isShowingOverflow()) {
                visibility = VISIBLE;
            }
        }
        if (Flags.enableRetrievableBubbles()) {
            if (BubbleOverflow.KEY.equals(mBubbleData.getSelectedBubbleKey())
                    && !mBubbleData.hasBubbles()) {
                // Hide overflow bubble icon if it is the only bubble
                visibility = GONE;
            }
        }
        mBubbleOverflow.setVisible(visibility);
    }

    private void updateOverflowDotVisibility(boolean expanding) {
@@ -2147,6 +2159,13 @@ public class BubbleStackView extends FrameLayout
        if (mIsExpanded) {
            hideCurrentInputMethod();

            if (Flags.enableRetrievableBubbles()) {
                if (mBubbleData.getBubbles().size() == 1) {
                    // First bubble, check if overflow visibility needs to change
                    updateOverflowVisibility();
                }
            }

            // Make the container of the expanded view transparent before removing the expanded view
            // from it. Otherwise a punch hole created by {@link android.view.SurfaceView} in the
            // expanded view becomes visible on the screen. See b/126856255
@@ -2214,6 +2233,16 @@ public class BubbleStackView extends FrameLayout
        announceExpandForAccessibility(mExpandedBubble, mIsExpanded);
    }

    /**
     * Check if we only have overflow expanded. Which is the case when we are launching bubbles from
     * background.
     */
    private boolean isOnlyOverflowExpanded() {
        boolean overflowExpanded = mExpandedBubble != null && BubbleOverflow.KEY.equals(
                mExpandedBubble.getKey());
        return overflowExpanded && !mBubbleData.hasBubbles();
    }

    /**
     * Monitor for swipe up gesture that is used to collapse expanded view
     */
@@ -2434,7 +2463,7 @@ public class BubbleStackView extends FrameLayout
        ProtoLog.d(WM_SHELL_BUBBLES, "animateExpansion, expandedBubble=%s",
                mExpandedBubble != null ? mExpandedBubble.getKey() : "null");
        cancelDelayedExpandCollapseSwitchAnimations();
        final boolean showVertically = mPositioner.showBubblesVertically();

        mIsExpanded = true;
        if (isStackEduVisible()) {
            mStackEduView.hide(true /* fromExpansion */);
@@ -2444,8 +2473,17 @@ public class BubbleStackView extends FrameLayout
        showScrim(true, null /* runnable */);
        updateBubbleShadows(mIsExpanded);
        mBubbleContainer.setActiveController(mExpandedAnimationController);
        updateBadges(false /* setBadgeForCollapsedStack */);
        updateOverflowVisibility();

        if (Flags.enableRetrievableBubbles() && isOnlyOverflowExpanded()) {
            animateOverflowExpansion();
        } else {
            animateBubbleExpansion();
        }
    }

    private void animateBubbleExpansion() {
        updateBadges(false /* setBadgeForCollapsedStack */);
        updatePointerPosition(false /* forIme */);
        if (Flags.enableBubbleStashing()) {
            mBubbleContainer.animate().translationX(0).start();
@@ -2469,6 +2507,7 @@ public class BubbleStackView extends FrameLayout
        mExpandedViewContainer.setTranslationY(translationY);
        mExpandedViewContainer.setAlpha(1f);

        final boolean showVertically = mPositioner.showBubblesVertically();
        // How far horizontally the bubble will be animating. We'll wait a bit longer for bubbles
        // that are animating farther, so that the expanded view doesn't move as much.
        final float relevantStackPosition = showVertically
@@ -2561,6 +2600,47 @@ public class BubbleStackView extends FrameLayout
        mMainExecutor.executeDelayed(mDelayedAnimation, startDelay);
    }

    /**
     * Animate expansion of overflow view when it is shown from the bubble shortcut.
     * <p>
     * Animates the view with a scale originating from the center of the view.
     */
    private void animateOverflowExpansion() {
        PointF bubbleXY = mPositioner.getExpandedBubbleXY(0, getState());
        final float translationY = mPositioner.getExpandedViewY(mExpandedBubble,
                mPositioner.showBubblesVertically() ? bubbleXY.y : bubbleXY.x);
        mExpandedViewContainer.setTranslationX(0f);
        mExpandedViewContainer.setTranslationY(translationY);
        mExpandedViewContainer.setAlpha(1f);

        boolean stackOnLeft = mPositioner.isStackOnLeft(getStackPosition());
        float width = mPositioner.getTaskViewContentWidth(stackOnLeft);
        float height = mPositioner.getExpandedViewHeight(mExpandedBubble);
        float scale = 1f - OPEN_OVERFLOW_ANIMATE_SCALE_AMOUNT;
        // Scale from the center of the view
        mExpandedViewContainerMatrix.setScale(scale, scale, width / 2f, height / 2f);
        mExpandedViewContainer.setAnimationMatrix(mExpandedViewContainerMatrix);
        mExpandedViewAlphaAnimator.start();
        PhysicsAnimator.getInstance(mExpandedViewContainerMatrix).cancel();
        PhysicsAnimator.getInstance(mExpandedViewContainerMatrix)
                .spring(AnimatableScaleMatrix.SCALE_X,
                        AnimatableScaleMatrix.getAnimatableValueForScaleFactor(1f),
                        mScaleInSpringConfig)
                .spring(AnimatableScaleMatrix.SCALE_Y,
                        AnimatableScaleMatrix.getAnimatableValueForScaleFactor(1f),
                        mScaleInSpringConfig)
                .addUpdateListener((target, values) -> {
                    mExpandedViewContainer.setAnimationMatrix(mExpandedViewContainerMatrix);
                }).withEndActions(() -> {
                    mExpandedViewContainer.setAnimationMatrix(null);
                    afterExpandedViewAnimation();
                    BubbleExpandedView expandedView = getExpandedView();
                    if (expandedView != null) {
                        expandedView.setSurfaceZOrderedOnTop(false);
                    }
                }).start();
    }

    private void animateCollapse() {
        cancelDelayedExpandCollapseSwitchAnimations();
        ProtoLog.d(WM_SHELL_BUBBLES, "animateCollapse");