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

Commit 5b28cdf3 authored by Ben Lin's avatar Ben Lin Committed by Automerger Merge Worker
Browse files

Merge "PiP: Take inset into consideration when calculating stash offset." into...

Merge "PiP: Take inset into consideration when calculating stash offset." into sc-dev am: 7fc1313d

Original change: https://googleplex-android-review.googlesource.com/c/platform/frameworks/base/+/14345460

Change-Id: Ib806ef60aeade76abb0042574be715e88163bd80
parents 4cab4f8c 7fc1313d
Loading
Loading
Loading
Loading
+4 −3
Original line number Original line Diff line number Diff line
@@ -109,13 +109,14 @@ public class PipSnapAlgorithm {
     * consideration.
     * consideration.
     */
     */
    public void applySnapFraction(Rect stackBounds, Rect movementBounds, float snapFraction,
    public void applySnapFraction(Rect stackBounds, Rect movementBounds, float snapFraction,
            @PipBoundsState.StashType int stashType, int stashOffset, Rect displayBounds) {
            @PipBoundsState.StashType int stashType, int stashOffset, Rect displayBounds,
            Rect insetBounds) {
        applySnapFraction(stackBounds, movementBounds, snapFraction);
        applySnapFraction(stackBounds, movementBounds, snapFraction);


        if (stashType != STASH_TYPE_NONE) {
        if (stashType != STASH_TYPE_NONE) {
            stackBounds.offsetTo(stashType == STASH_TYPE_LEFT
            stackBounds.offsetTo(stashType == STASH_TYPE_LEFT
                            ? stashOffset - stackBounds.width()
                            ? stashOffset - stackBounds.width() + insetBounds.left
                            : displayBounds.right - stashOffset,
                            : displayBounds.right - stashOffset - insetBounds.right,
                    stackBounds.top);
                    stackBounds.top);
        }
        }
    }
    }
+4 −2
Original line number Original line Diff line number Diff line
@@ -464,7 +464,8 @@ public class PipController implements PipTransitionController.PipTransitionCallb
            pipSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
            pipSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
                    snapFraction, mPipBoundsState.getStashedState(),
                    snapFraction, mPipBoundsState.getStashedState(),
                    mPipBoundsState.getStashOffset(),
                    mPipBoundsState.getStashOffset(),
                    mPipBoundsState.getDisplayBounds());
                    mPipBoundsState.getDisplayBounds(),
                    mPipBoundsState.getDisplayLayout().stableInsets());


            mTouchHandler.getMotionHelper().movePip(postChangeStackBounds);
            mTouchHandler.getMotionHelper().movePip(postChangeStackBounds);
        } else {
        } else {
@@ -668,7 +669,8 @@ public class PipController implements PipTransitionController.PipTransitionCallb
                postChangeStackBounds, false /* adjustForIme */);
                postChangeStackBounds, false /* adjustForIme */);
        pipSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
        pipSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
                snapFraction, mPipBoundsState.getStashedState(), mPipBoundsState.getStashOffset(),
                snapFraction, mPipBoundsState.getStashedState(), mPipBoundsState.getStashOffset(),
                mPipBoundsState.getDisplayBounds());
                mPipBoundsState.getDisplayBounds(),
                mPipBoundsState.getDisplayLayout().stableInsets());


        mPipBoundsAlgorithm.getInsetBounds(outInsetBounds);
        mPipBoundsAlgorithm.getInsetBounds(outInsetBounds);
        outBounds.set(postChangeStackBounds);
        outBounds.set(postChangeStackBounds);
+10 −3
Original line number Original line Diff line number Diff line
@@ -406,11 +406,14 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
                .flingThenSpring(
                .flingThenSpring(
                        FloatProperties.RECT_Y, velocityY, mFlingConfigY, mSpringConfig);
                        FloatProperties.RECT_Y, velocityY, mFlingConfigY, mSpringConfig);


        final Rect insetBounds = mPipBoundsState.getDisplayLayout().stableInsets();
        final float leftEdge = isStash
        final float leftEdge = isStash
                ? mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width()
                ? mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width()
                + insetBounds.left
                : mPipBoundsState.getMovementBounds().left;
                : mPipBoundsState.getMovementBounds().left;
        final float rightEdge = isStash
        final float rightEdge = isStash
                ?  mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset()
                ?  mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset()
                - insetBounds.right
                : mPipBoundsState.getMovementBounds().right;
                : mPipBoundsState.getMovementBounds().right;


        final float xEndValue = velocityX < 0 ? leftEdge : rightEdge;
        final float xEndValue = velocityX < 0 ? leftEdge : rightEdge;
@@ -483,7 +486,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,


        mSnapAlgorithm.applySnapFraction(normalBounds, normalMovementBounds, savedSnapFraction,
        mSnapAlgorithm.applySnapFraction(normalBounds, normalMovementBounds, savedSnapFraction,
                mPipBoundsState.getStashedState(), mPipBoundsState.getStashOffset(),
                mPipBoundsState.getStashedState(), mPipBoundsState.getStashOffset(),
                mPipBoundsState.getDisplayBounds());
                mPipBoundsState.getDisplayBounds(),
                mPipBoundsState.getDisplayLayout().stableInsets());


        if (immediate) {
        if (immediate) {
            movePip(normalBounds);
            movePip(normalBounds);
@@ -529,10 +533,13 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
        mFlingConfigY = new PhysicsAnimator.FlingConfig(DEFAULT_FRICTION,
        mFlingConfigY = new PhysicsAnimator.FlingConfig(DEFAULT_FRICTION,
                mPipBoundsState.getMovementBounds().top,
                mPipBoundsState.getMovementBounds().top,
                mPipBoundsState.getMovementBounds().bottom);
                mPipBoundsState.getMovementBounds().bottom);
        final Rect insetBounds = mPipBoundsState.getDisplayLayout().stableInsets();
        mStashConfigX = new PhysicsAnimator.FlingConfig(
        mStashConfigX = new PhysicsAnimator.FlingConfig(
                DEFAULT_FRICTION,
                DEFAULT_FRICTION,
                mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width(),
                mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width()
                mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset());
                        + insetBounds.left,
                mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset()
                        - insetBounds.right);
    }
    }


    private void startBoundsAnimator(float toX, float toY) {
    private void startBoundsAnimator(float toX, float toY) {
+24 −4
Original line number Original line Diff line number Diff line
@@ -38,6 +38,8 @@ public class PipSnapAlgorithmTest extends ShellTestCase {
    private static final int DEFAULT_STASH_OFFSET = 32;
    private static final int DEFAULT_STASH_OFFSET = 32;
    private static final Rect DISPLAY_BOUNDS = new Rect(0, 0, 2000, 2000);
    private static final Rect DISPLAY_BOUNDS = new Rect(0, 0, 2000, 2000);
    private static final Rect STACK_BOUNDS_CENTERED = new Rect(900, 900, 1100, 1100);
    private static final Rect STACK_BOUNDS_CENTERED = new Rect(900, 900, 1100, 1100);
    private static final Rect INSET_BOUNDS_EMPTY = new Rect(0, 0, 0, 0);
    private static final Rect INSET_BOUNDS_RIGHT = new Rect(0, 0, 200, 0);
    private static final Rect MOVEMENT_BOUNDS = new Rect(0, 0,
    private static final Rect MOVEMENT_BOUNDS = new Rect(0, 0,
            DISPLAY_BOUNDS.width() - STACK_BOUNDS_CENTERED.width(),
            DISPLAY_BOUNDS.width() - STACK_BOUNDS_CENTERED.width(),
            DISPLAY_BOUNDS.width() - STACK_BOUNDS_CENTERED.width());
            DISPLAY_BOUNDS.width() - STACK_BOUNDS_CENTERED.width());
@@ -99,7 +101,8 @@ public class PipSnapAlgorithmTest extends ShellTestCase {
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);


        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, snapFraction,
        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, snapFraction,
                PipBoundsState.STASH_TYPE_NONE, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS);
                PipBoundsState.STASH_TYPE_NONE, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS,
                INSET_BOUNDS_EMPTY);


        assertEquals(MOVEMENT_BOUNDS.right, bounds.left);
        assertEquals(MOVEMENT_BOUNDS.right, bounds.left);
        assertEquals(MOVEMENT_BOUNDS.bottom, bounds.top);
        assertEquals(MOVEMENT_BOUNDS.bottom, bounds.top);
@@ -111,7 +114,8 @@ public class PipSnapAlgorithmTest extends ShellTestCase {
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);


        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, snapFraction,
        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, snapFraction,
                PipBoundsState.STASH_TYPE_LEFT, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS);
                PipBoundsState.STASH_TYPE_LEFT, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS,
                INSET_BOUNDS_EMPTY);


        final int offBoundsWidth = bounds.width() - DEFAULT_STASH_OFFSET;
        final int offBoundsWidth = bounds.width() - DEFAULT_STASH_OFFSET;
        assertEquals(MOVEMENT_BOUNDS.left - offBoundsWidth, bounds.left);
        assertEquals(MOVEMENT_BOUNDS.left - offBoundsWidth, bounds.left);
@@ -124,12 +128,27 @@ public class PipSnapAlgorithmTest extends ShellTestCase {
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);


        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, snapFraction,
        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, snapFraction,
                PipBoundsState.STASH_TYPE_RIGHT, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS);
                PipBoundsState.STASH_TYPE_RIGHT, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS,
                INSET_BOUNDS_EMPTY);


        assertEquals(DISPLAY_BOUNDS.right - DEFAULT_STASH_OFFSET, bounds.left);
        assertEquals(DISPLAY_BOUNDS.right - DEFAULT_STASH_OFFSET, bounds.left);
        assertEquals(MOVEMENT_BOUNDS.bottom, bounds.top);
        assertEquals(MOVEMENT_BOUNDS.bottom, bounds.top);
    }
    }


    @Test
    public void testApplySnapFraction_stashedRight_withInset() {
        final float snapFraction = 2f;
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);

        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, snapFraction,
                PipBoundsState.STASH_TYPE_RIGHT, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS,
                INSET_BOUNDS_RIGHT);

        assertEquals(DISPLAY_BOUNDS.right - DEFAULT_STASH_OFFSET - INSET_BOUNDS_RIGHT.right,
                bounds.left);
        assertEquals(MOVEMENT_BOUNDS.bottom, bounds.top);
    }

    @Test
    @Test
    public void testSnapRectToClosestEdge_rightEdge() {
    public void testSnapRectToClosestEdge_rightEdge() {
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
@@ -183,7 +202,8 @@ public class PipSnapAlgorithmTest extends ShellTestCase {
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
        final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
        // Stash it on the left side.
        // Stash it on the left side.
        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, 3.5f,
        mPipSnapAlgorithm.applySnapFraction(bounds, MOVEMENT_BOUNDS, 3.5f,
                PipBoundsState.STASH_TYPE_LEFT, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS);
                PipBoundsState.STASH_TYPE_LEFT, DEFAULT_STASH_OFFSET, DISPLAY_BOUNDS,
                INSET_BOUNDS_EMPTY);


        mPipSnapAlgorithm.snapRectToClosestEdge(bounds, MOVEMENT_BOUNDS, bounds,
        mPipSnapAlgorithm.snapRectToClosestEdge(bounds, MOVEMENT_BOUNDS, bounds,
                PipBoundsState.STASH_TYPE_LEFT);
                PipBoundsState.STASH_TYPE_LEFT);