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

Commit 0278513d authored by Jorge Gil's avatar Jorge Gil Committed by Automerger Merge Worker
Browse files

Merge "Use reentry size to calculate PIP entry bounds" into rvc-qpr-dev am: 6d1ef3b4

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

Change-Id: I09a527e6781c86e11b182375675b6dad8b120205
parents 3f0645ea 6d1ef3b4
Loading
Loading
Loading
Loading
+9 −8
Original line number Original line Diff line number Diff line
@@ -177,7 +177,7 @@ public class PipBoundsHandler {
        }
        }
        if (isValidPictureInPictureAspectRatio(mAspectRatio)) {
        if (isValidPictureInPictureAspectRatio(mAspectRatio)) {
            transformBoundsToAspectRatio(normalBounds, mAspectRatio,
            transformBoundsToAspectRatio(normalBounds, mAspectRatio,
                    false /* useCurrentMinEdgeSize */);
                    false /* useCurrentMinEdgeSize */, false /* useCurrentSize */);
        }
        }
        displayInfo.copyFrom(mDisplayInfo);
        displayInfo.copyFrom(mDisplayInfo);
    }
    }
@@ -278,7 +278,9 @@ public class PipBoundsHandler {
            destinationBounds = new Rect(bounds);
            destinationBounds = new Rect(bounds);
        }
        }
        if (isValidPictureInPictureAspectRatio(aspectRatio)) {
        if (isValidPictureInPictureAspectRatio(aspectRatio)) {
            transformBoundsToAspectRatio(destinationBounds, aspectRatio, useCurrentMinEdgeSize);
            boolean useCurrentSize = bounds == null && mReentrySize != null;
            transformBoundsToAspectRatio(destinationBounds, aspectRatio, useCurrentMinEdgeSize,
                    useCurrentSize);
        }
        }
        mAspectRatio = aspectRatio;
        mAspectRatio = aspectRatio;
        return destinationBounds;
        return destinationBounds;
@@ -384,7 +386,8 @@ public class PipBoundsHandler {
     * @param stackBounds
     * @param stackBounds
     */
     */
    public void transformBoundsToAspectRatio(Rect stackBounds) {
    public void transformBoundsToAspectRatio(Rect stackBounds) {
        transformBoundsToAspectRatio(stackBounds, mAspectRatio, true);
        transformBoundsToAspectRatio(stackBounds, mAspectRatio, true /* useCurrentMinEdgeSize */,
                true /* useCurrentSize */);
    }
    }


    /**
    /**
@@ -392,18 +395,16 @@ public class PipBoundsHandler {
     * specified aspect ratio.
     * specified aspect ratio.
     */
     */
    private void transformBoundsToAspectRatio(Rect stackBounds, float aspectRatio,
    private void transformBoundsToAspectRatio(Rect stackBounds, float aspectRatio,
            boolean useCurrentMinEdgeSize) {
            boolean useCurrentMinEdgeSize, boolean useCurrentSize) {
        // Save the snap fraction and adjust the size based on the new aspect ratio.
        // Save the snap fraction and adjust the size based on the new aspect ratio.
        final float snapFraction = mSnapAlgorithm.getSnapFraction(stackBounds,
        final float snapFraction = mSnapAlgorithm.getSnapFraction(stackBounds,
                getMovementBounds(stackBounds));
                getMovementBounds(stackBounds));
        final int minEdgeSize;
        final int minEdgeSize = useCurrentMinEdgeSize ? mCurrentMinSize : mDefaultMinSize;
        final Size size;
        final Size size;
        if (useCurrentMinEdgeSize) {
        if (useCurrentMinEdgeSize || useCurrentSize) {
            minEdgeSize = mCurrentMinSize;
            size = mSnapAlgorithm.getSizeForAspectRatio(
            size = mSnapAlgorithm.getSizeForAspectRatio(
                    new Size(stackBounds.width(), stackBounds.height()), aspectRatio, minEdgeSize);
                    new Size(stackBounds.width(), stackBounds.height()), aspectRatio, minEdgeSize);
        } else {
        } else {
            minEdgeSize = mDefaultMinSize;
            size = mSnapAlgorithm.getSizeForAspectRatio(aspectRatio, minEdgeSize,
            size = mSnapAlgorithm.getSizeForAspectRatio(aspectRatio, minEdgeSize,
                    mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
                    mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight);
        }
        }
+31 −0
Original line number Original line Diff line number Diff line
@@ -269,6 +269,21 @@ public class PipBoundsHandlerTest extends SysuiTestCase {
        assertBoundsInclusionWithMargin("restoreLastPosition", oldPosition, newPosition);
        assertBoundsInclusionWithMargin("restoreLastPosition", oldPosition, newPosition);
    }
    }


    @Test
    public void onSaveReentryBounds_restoreLastSize() {
        final Rect oldSize = mPipBoundsHandler.getDestinationBounds(mTestComponentName1,
                DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE);

        oldSize.scale(1.25f);
        mPipBoundsHandler.onSaveReentryBounds(mTestComponentName1, oldSize);

        final Rect newSize = mPipBoundsHandler.getDestinationBounds(mTestComponentName1,
                DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE);

        assertEquals(oldSize.width(), newSize.width());
        assertEquals(oldSize.height(), newSize.height());
    }

    @Test
    @Test
    public void onResetReentryBounds_useDefaultBounds() {
    public void onResetReentryBounds_useDefaultBounds() {
        final Rect defaultBounds = mPipBoundsHandler.getDestinationBounds(mTestComponentName1,
        final Rect defaultBounds = mPipBoundsHandler.getDestinationBounds(mTestComponentName1,
@@ -299,6 +314,22 @@ public class PipBoundsHandlerTest extends SysuiTestCase {
        assertBoundsInclusionWithMargin("restoreLastPosition", newBounds, actualBounds);
        assertBoundsInclusionWithMargin("restoreLastPosition", newBounds, actualBounds);
    }
    }


    @Test
    public void onSaveReentryBounds_componentMismatch_restoreLastSize() {
        final Rect oldSize = mPipBoundsHandler.getDestinationBounds(mTestComponentName1,
                DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE);

        oldSize.scale(1.25f);
        mPipBoundsHandler.onSaveReentryBounds(mTestComponentName1, oldSize);

        mPipBoundsHandler.onResetReentryBounds(mTestComponentName2);
        final Rect newSize = mPipBoundsHandler.getDestinationBounds(mTestComponentName1,
                DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE);

        assertEquals(oldSize.width(), newSize.width());
        assertEquals(oldSize.height(), newSize.height());
    }

    private void assertBoundsInclusionWithMargin(String from, Rect expected, Rect actual) {
    private void assertBoundsInclusionWithMargin(String from, Rect expected, Rect actual) {
        final Rect expectedWithMargin = new Rect(expected);
        final Rect expectedWithMargin = new Rect(expected);
        expectedWithMargin.inset(-ROUNDING_ERROR_MARGIN, -ROUNDING_ERROR_MARGIN);
        expectedWithMargin.inset(-ROUNDING_ERROR_MARGIN, -ROUNDING_ERROR_MARGIN);