diff options
| author | 2020-07-16 23:01:00 +0000 | |
|---|---|---|
| committer | 2020-07-16 23:01:00 +0000 | |
| commit | 7a0844c60d8698c9ab01406809ef58fc32e5b9ec (patch) | |
| tree | 5db22a6a6b8beb98ed25245a341dcb7a895a0585 | |
| parent | dc903bcda2da4862e83202e5da1663a0bae354c4 (diff) | |
| parent | 4177a5ee62fe548d3c90963eb8b78e29f7bda707 (diff) | |
Merge "Use reentry size to calculate PIP entry bounds"
| -rw-r--r-- | packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java | 17 | ||||
| -rw-r--r-- | packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java | 31 |
2 files changed, 40 insertions, 8 deletions
diff --git a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java index 79909b2a8ae9..665b90e29976 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/PipBoundsHandler.java @@ -178,7 +178,7 @@ public class PipBoundsHandler { } if (isValidPictureInPictureAspectRatio(mAspectRatio)) { transformBoundsToAspectRatio(normalBounds, mAspectRatio, - false /* useCurrentMinEdgeSize */); + false /* useCurrentMinEdgeSize */, false /* useCurrentSize */); } displayInfo.copyFrom(mDisplayInfo); } @@ -279,7 +279,9 @@ public class PipBoundsHandler { destinationBounds = new Rect(bounds); } if (isValidPictureInPictureAspectRatio(aspectRatio)) { - transformBoundsToAspectRatio(destinationBounds, aspectRatio, useCurrentMinEdgeSize); + boolean useCurrentSize = bounds == null && mReentrySize != null; + transformBoundsToAspectRatio(destinationBounds, aspectRatio, useCurrentMinEdgeSize, + useCurrentSize); } mAspectRatio = aspectRatio; return destinationBounds; @@ -389,7 +391,8 @@ public class PipBoundsHandler { * @param stackBounds */ public void transformBoundsToAspectRatio(Rect stackBounds) { - transformBoundsToAspectRatio(stackBounds, mAspectRatio, true); + transformBoundsToAspectRatio(stackBounds, mAspectRatio, true /* useCurrentMinEdgeSize */, + true /* useCurrentSize */); } /** @@ -397,18 +400,16 @@ public class PipBoundsHandler { * specified aspect ratio. */ 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. final float snapFraction = mSnapAlgorithm.getSnapFraction(stackBounds, getMovementBounds(stackBounds)); - final int minEdgeSize; + final int minEdgeSize = useCurrentMinEdgeSize ? mCurrentMinSize : mDefaultMinSize; final Size size; - if (useCurrentMinEdgeSize) { - minEdgeSize = mCurrentMinSize; + if (useCurrentMinEdgeSize || useCurrentSize) { size = mSnapAlgorithm.getSizeForAspectRatio( new Size(stackBounds.width(), stackBounds.height()), aspectRatio, minEdgeSize); } else { - minEdgeSize = mDefaultMinSize; size = mSnapAlgorithm.getSizeForAspectRatio(aspectRatio, minEdgeSize, mDisplayInfo.logicalWidth, mDisplayInfo.logicalHeight); } diff --git a/packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java b/packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java index f404f0489e01..70c2bba040a0 100644 --- a/packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java +++ b/packages/SystemUI/tests/src/com/android/systemui/pip/PipBoundsHandlerTest.java @@ -270,6 +270,21 @@ public class PipBoundsHandlerTest extends SysuiTestCase { } @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 public void onResetReentryBounds_useDefaultBounds() { final Rect defaultBounds = mPipBoundsHandler.getDestinationBounds(mTestComponentName1, DEFAULT_ASPECT_RATIO, EMPTY_CURRENT_BOUNDS, EMPTY_MINIMAL_SIZE); @@ -299,6 +314,22 @@ public class PipBoundsHandlerTest extends SysuiTestCase { 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) { final Rect expectedWithMargin = new Rect(expected); expectedWithMargin.inset(-ROUNDING_ERROR_MARGIN, -ROUNDING_ERROR_MARGIN); |