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

Commit 90259d2d authored by Mady Mellor's avatar Mady Mellor
Browse files

Remove some methods in animation helper & use from bubble positioner

1 - Some of the positioning logic in BubbleBarAnimationHelper could rely
on existing methods in BubblePositioner, so migrate to those.

2 - Create a general method to retrieve the resting bounds of the
expanded view for either floating / bubble bar

3 - Use the new method on bubble positioner for retrieving bounds info
in BubbleTransitions -- this will help remove the reliance on layerView.

Flag: com.android.wm.shell.enable_create_any_bubble
Test: atest BubblePositionerTest BubbleTransitionsTest
Test: manual - turn on enable_bubble_to_fullscreen and observe the
               transitions: drag app handle to bubble, use app handle
               menu to bubble, drag bubble to fullscreen, use bubble
               menu to fullscreen
Bug: 408453889
Change-Id: If86ec86ee2b7e1057cdf25ec77b0cf10f96d20c9
parent d87ac8d6
Loading
Loading
Loading
Loading
+37 −6
Original line number Diff line number Diff line
@@ -585,22 +585,42 @@ class BubblePositionerTest {

    @Test
    fun testGetBubbleBarExpandedViewBounds_onLeft() {
        testGetBubbleBarExpandedViewBounds(onLeft = true, isOverflow = false)
        verifyGetBubbleBarExpandedViewBounds(onLeft = true, isOverflow = false)
    }

    @Test
    fun testGetBubbleBarExpandedViewBounds_onRight() {
        testGetBubbleBarExpandedViewBounds(onLeft = false, isOverflow = false)
        verifyGetBubbleBarExpandedViewBounds(onLeft = false, isOverflow = false)
    }

    @Test
    fun testGetBubbleBarExpandedViewBounds_isOverflow_onLeft() {
        testGetBubbleBarExpandedViewBounds(onLeft = true, isOverflow = true)
        verifyGetBubbleBarExpandedViewBounds(onLeft = true, isOverflow = true)
    }

    @Test
    fun testGetBubbleBarExpandedViewBounds_isOverflow_onRight() {
        testGetBubbleBarExpandedViewBounds(onLeft = false, isOverflow = true)
        verifyGetBubbleBarExpandedViewBounds(onLeft = false, isOverflow = true)
    }

    @Test
    fun testGetTaskViewRestBounds_phone() {
        val deviceConfig =
            defaultDeviceConfig.copy(
                insets = Insets.of(10, 20, 5, 15),
                windowBounds = Rect(0, 0, 1800, 2600)
            )
        positioner.update(deviceConfig)

        val padding = context.resources.getDimensionPixelSize(R.dimen.bubble_expanded_view_padding)
        val top = positioner.expandedViewYTopAligned
        val left = positioner.insets.left + padding
        val right = positioner.screenRect.right - positioner.insets.right - padding
        val bottom = top + positioner.getMaxExpandedViewHeight(false)

        val rect = Rect()
        positioner.getTaskViewRestBounds(rect)
        assertThat(rect).isEqualTo(Rect(left, top, right, bottom))
    }

    @Test
@@ -667,8 +687,13 @@ class BubblePositionerTest {
        assertThat(paddings).isEqualTo(intArrayOf(padding - positioner.pointerSize, 0, padding, 0))
    }

    private fun testGetBubbleBarExpandedViewBounds(onLeft: Boolean, isOverflow: Boolean) {
    private fun verifyGetBubbleBarExpandedViewBounds(onLeft: Boolean, isOverflow: Boolean) {
        positioner.isShowingInBubbleBar = true
        positioner.bubbleBarLocation = if (onLeft) {
            BubbleBarLocation.LEFT
        } else {
            BubbleBarLocation.RIGHT
        }
        val windowBounds = Rect(0, 0, 2000, 2600)
        val insets = Insets.of(10, 20, 5, 15)
        val deviceConfig =
@@ -706,8 +731,14 @@ class BubblePositionerTest {

        val bounds = Rect()
        positioner.getBubbleBarExpandedViewBounds(onLeft, isOverflow, bounds)

        assertThat(bounds).isEqualTo(expectedBounds)

        if (!isOverflow) {
            val bounds2 = Rect()
            // In bubble bar mode this should return the same bounds
            positioner.getTaskViewRestBounds(bounds2)
            assertThat(bounds2).isEqualTo(expectedBounds)
        }
    }

    private val defaultYPosition: Float
+25 −0
Original line number Diff line number Diff line
@@ -860,6 +860,31 @@ public class BubblePositioner implements BubbleDropTargetBoundsProvider {
                screen.bottom);
    }


    /**
     * Populates {@param out} with the rest bounds of an expanded bubble on screen.
     * <p>
     * TODO: b/417226976
     *  Never used for the overflow or for floating mode on large screen -- bubble bar & phone
     *  floating only.
     */
    public void getTaskViewRestBounds(Rect out) {
        if (isShowingInBubbleBar()) {
            getBubbleBarExpandedViewBounds(isBubbleBarOnLeft(), false /* isOverflow */, out);
        } else {
            final int top = getExpandedViewYTopAligned();
            // Can assume left false because that only matters for floating on large screen which
            // is never used here.
            final int width = getTaskViewContentWidth(false /* onLeft */);
            // TODO (b/419347947): this assumes max height for the bubble, chat bubbles can have
            //  variable height if the developer overrides; will matter for move chat to fullscreen
            final int height = getMaxExpandedViewHeight(false /* overflow */);
            final int[] paddings = getExpandedViewContainerPadding(false /* onLeft */,
                    false /* overflow */);
            out.set(paddings[0], top, paddings[0] + width, top + height);
        }
    }

    //
    // Bubble bar specific sizes below.
    //
+18 −12
Original line number Diff line number Diff line
@@ -301,8 +301,9 @@ public class BubbleTransitions {
    }

    /** Starts a transition that converts a floating expanded bubble to a bar bubble. */
    public BubbleTransition startFloatingToBarConversion(Bubble bubble) {
        return new FloatingToBarConversion(bubble);
    public BubbleTransition startFloatingToBarConversion(Bubble bubble,
            BubblePositioner positioner) {
        return new FloatingToBarConversion(bubble, positioner);
    }

    /** Starts a transition that converts a dragged bubble icon to a full screen task. */
@@ -470,6 +471,7 @@ public class BubbleTransitions {
    @VisibleForTesting
    class LaunchNewTaskBubbleForExistingTransition implements TransitionHandler, BubbleTransition {
        final BubbleBarLayerView mLayerView;
        final BubblePositioner mPositioner;
        private final TransitionProgress mTransitionProgress;
        Bubble mBubble;
        IBinder mTransition;
@@ -499,6 +501,7 @@ public class BubbleTransitions {
            mBubble = bubble;
            mTransition = transition;
            mTransitionProgress = new TransitionProgress(bubble);
            mPositioner = positioner;
            mLayerView = layerView;
            mBubble.setInflateSynchronously(inflateSync);
            mBubble.setPreparingTransition(this);
@@ -527,9 +530,6 @@ public class BubbleTransitions {
            if (!mBubble.isShortcut() && !mBubble.isApp()) {
                throw new IllegalArgumentException("Unsupported bubble type");
            }
            final Rect launchBounds = new Rect();
            mLayerView.getExpandedViewRestBounds(launchBounds);

            final TaskView tv = b.getTaskView();
            tv.setSurfaceLifecycle(SurfaceView.SURFACE_LIFECYCLE_FOLLOWS_ATTACHMENT);
            final TaskViewRepository.TaskViewState state = mRepository.byTaskView(
@@ -723,6 +723,7 @@ public class BubbleTransitions {
    @VisibleForTesting
    class LaunchOrConvertToBubble implements TransitionHandler, BubbleTransition {
        final BubbleBarLayerView mLayerView;
        final BubblePositioner mPositioner;
        private final TransitionProgress mTransitionProgress;
        Bubble mBubble;
        IBinder mTransition;
@@ -755,6 +756,7 @@ public class BubbleTransitions {
                    layerView.isExpanded());
            mBubble = bubble;
            mTransitionProgress = new TransitionProgress(bubble);
            mPositioner = positioner;
            mLayerView = layerView;
            mBubble.setInflateSynchronously(inflateSync);
            mBubble.setPreparingTransition(this);
@@ -782,7 +784,7 @@ public class BubbleTransitions {
                throw new IllegalArgumentException("Unsupported bubble type");
            }
            final Rect launchBounds = new Rect();
            mLayerView.getExpandedViewRestBounds(launchBounds);
            mPositioner.getTaskViewRestBounds(launchBounds);

            final TaskView tv = b.getTaskView();
            tv.setSurfaceLifecycle(SurfaceView.SURFACE_LIFECYCLE_FOLLOWS_ATTACHMENT);
@@ -1069,6 +1071,7 @@ public class BubbleTransitions {
    @VisibleForTesting
    class ConvertToBubble implements Transitions.TransitionHandler, BubbleTransition {
        final BubbleBarLayerView mLayerView;
        final BubblePositioner mPositioner;
        final HomeIntentProvider mHomeIntentProvider;
        Bubble mBubble;
        @Nullable
@@ -1094,6 +1097,7 @@ public class BubbleTransitions {
            mBubble = bubble;
            mTransitionProgress = new TransitionProgress(bubble);
            mTaskInfo = taskInfo;
            mPositioner = positioner;
            mLayerView = layerView;
            mHomeIntentProvider = homeIntentProvider;
            mDragData = dragData;
@@ -1118,7 +1122,7 @@ public class BubbleTransitions {
                throw new IllegalArgumentException("inflate callback doesn't match bubble");
            }
            final Rect launchBounds = new Rect();
            mLayerView.getExpandedViewRestBounds(launchBounds);
            mPositioner.getTaskViewRestBounds(launchBounds);
            final boolean reparentToTda =
                    mTaskInfo.getWindowingMode() == WINDOWING_MODE_MULTI_WINDOW
                            && mTaskInfo.getParentTaskId() != INVALID_TASK_ID;
@@ -1623,7 +1627,7 @@ public class BubbleTransitions {
     * once the bubble bar location on the screen is known.
     */
    class FloatingToBarConversion implements TransitionHandler, BubbleTransition {

        private final BubblePositioner mPositioner;
        private final Bubble mBubble;
        private final TransactionProvider mTransactionProvider;
        IBinder mTransition;
@@ -1633,15 +1637,17 @@ public class BubbleTransitions {
        private SurfaceControl.Transaction mFinishTransaction;
        private boolean mIsStarted = false;

        FloatingToBarConversion(Bubble bubble) {
            this(bubble, SurfaceControl.Transaction::new);
        FloatingToBarConversion(Bubble bubble, BubblePositioner positioner) {
            this(bubble, SurfaceControl.Transaction::new, positioner);
        }

        @VisibleForTesting
        FloatingToBarConversion(Bubble bubble, TransactionProvider transactionProvider) {
        FloatingToBarConversion(Bubble bubble, TransactionProvider transactionProvider,
                BubblePositioner positioner) {
            mBubble = bubble;
            mBubble.setPreparingTransition(this);
            mTransactionProvider = transactionProvider;
            mPositioner = positioner;
        }

        @Override
@@ -1717,7 +1723,7 @@ public class BubbleTransitions {

        @Override
        public void continueConvert(BubbleBarLayerView layerView) {
            layerView.getExpandedViewRestBounds(mBounds);
            mPositioner.getTaskViewRestBounds(mBounds);
            mWct.setBounds(mBubble.getTaskView().getTaskInfo().token, mBounds);
            if (!mIsStarted) {
                startTransition();
+23 −43
Original line number Diff line number Diff line
@@ -37,10 +37,8 @@ import android.animation.AnimatorSet;
import android.animation.ObjectAnimator;
import android.annotation.NonNull;
import android.content.Context;
import android.graphics.Point;
import android.graphics.Rect;
import android.util.Log;
import android.util.Size;
import android.view.SurfaceControl;
import android.widget.FrameLayout;

@@ -458,12 +456,15 @@ public class BubbleBarAnimationHelper {
            Log.w(TAG, "Trying to animate expanded view to rest position without a bubble");
            return;
        }
        Point restPoint = getExpandedViewRestPosition(getExpandedViewSize());
        final boolean isOverflow = mExpandedBubble.getKey().equals(BubbleOverflow.KEY);
        final Rect rect = new Rect();
        mPositioner.getBubbleBarExpandedViewBounds(mPositioner.isBubbleBarOnLeft(),
                isOverflow, rect);

        AnimatorSet contentAnim = new AnimatorSet();
        contentAnim.playTogether(
                ObjectAnimator.ofFloat(bbev, X, restPoint.x),
                ObjectAnimator.ofFloat(bbev, Y, restPoint.y),
                ObjectAnimator.ofFloat(bbev, X, rect.left),
                ObjectAnimator.ofFloat(bbev, Y, rect.top),
                ObjectAnimator.ofFloat(bbev, SCALE_X, 1f),
                ObjectAnimator.ofFloat(bbev, SCALE_Y, 1f),
                ObjectAnimator.ofFloat(bbev, CORNER_RADIUS, bbev.getRestingCornerRadius())
@@ -609,12 +610,16 @@ public class BubbleBarAnimationHelper {
        bbev.setTaskViewAlpha(1f);
        SurfaceControl tvSf = ((Bubble) mExpandedBubble).getTaskView().getSurfaceControl();

        final Size size = getExpandedViewSize();
        Point position = getExpandedViewRestPosition(size);
        final boolean isOverflow = mExpandedBubble.getKey().equals(BubbleOverflow.KEY);
        final Rect restBounds = new Rect();
        mPositioner.getBubbleBarExpandedViewBounds(mPositioner.isBubbleBarOnLeft(),
                isOverflow, restBounds);

        Rect startBounds = new Rect(origBounds.left - position.x, origBounds.top - position.y,
                origBounds.right - position.x, origBounds.bottom - position.y);
        Rect endBounds = new Rect(0, 0, size.getWidth(), size.getHeight());
        Rect startBounds = new Rect(origBounds.left - restBounds.left,
                origBounds.top - restBounds.top,
                origBounds.right - restBounds.left,
                origBounds.bottom - restBounds.top);
        Rect endBounds = new Rect(0, 0, restBounds.width(), restBounds.height());
        final SizeChangeAnimation sca = new SizeChangeAnimation(startBounds, endBounds,
                origScale, /* scaleFactor= */ 1f);
        sca.initialize(bbev, taskLeash, snapshot, startT);
@@ -678,47 +683,22 @@ public class BubbleBarAnimationHelper {
            Log.w(TAG, "Trying to update the expanded view without a bubble");
            return;
        }

        final Size size = getExpandedViewSize();
        Point position = getExpandedViewRestPosition(size);
        final boolean isOverflow = mExpandedBubble.getKey().equals(BubbleOverflow.KEY);
        final Rect rect = new Rect();
        mPositioner.getBubbleBarExpandedViewBounds(mPositioner.isBubbleBarOnLeft(),
                isOverflow, rect);
        FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams) bbev.getLayoutParams();
        lp.width = size.getWidth();
        lp.height = size.getHeight();
        lp.width = rect.width();
        lp.height = rect.height();
        bbev.setLayoutParams(lp);
        bbev.setX(position.x);
        bbev.setY(position.y);
        bbev.setX(rect.left);
        bbev.setY(rect.top);
        bbev.setScaleX(1f);
        bbev.setScaleY(1f);
        bbev.updateLocation();
        bbev.maybeShowOverflow();
    }

    void getExpandedViewRestBounds(Rect out) {
        final int width = mPositioner.getExpandedViewWidthForBubbleBar(false /* overflow */);
        final int height = mPositioner.getExpandedViewHeightForBubbleBar(false /* overflow */);
        Point position = getExpandedViewRestPosition(new Size(width, height));
        out.set(position.x, position.y, position.x + width, position.y + height);
    }

    private Point getExpandedViewRestPosition(Size size) {
        final int padding = mPositioner.getBubbleBarExpandedViewPadding();
        Point point = new Point();
        if (mPositioner.isBubbleBarOnLeft()) {
            point.x = mPositioner.getInsets().left + padding;
        } else {
            point.x = mPositioner.getAvailableRect().width() - size.getWidth() - padding;
        }
        point.y = mPositioner.getExpandedViewBottomForBubbleBar() - size.getHeight();
        return point;
    }

    private Size getExpandedViewSize() {
        boolean isOverflowExpanded = mExpandedBubble.getKey().equals(BubbleOverflow.KEY);
        final int width = mPositioner.getExpandedViewWidthForBubbleBar(isOverflowExpanded);
        final int height = mPositioner.getExpandedViewHeightForBubbleBar(isOverflowExpanded);
        return new Size(width, height);
    }

    private void startNewAnimator(Animator animator) {
        cancelAnimations();
        mRunningAnimator = animator;
+0 −7
Original line number Diff line number Diff line
@@ -488,13 +488,6 @@ public class BubbleBarLayerView extends FrameLayout
                taskLeash, animFinish);
    }

    /**
     * Populates {@param out} with the rest bounds of an expanded bubble.
     */
    public void getExpandedViewRestBounds(Rect out) {
        mAnimationHelper.getExpandedViewRestBounds(out);
    }

    public void removeBubble(@NonNull Bubble bubble, @NonNull Runnable endAction) {
        final boolean inTransition = bubble.getPreparingTransition() != null;
        ProtoLog.d(WM_SHELL_BUBBLES_NOISY,
Loading