Loading libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsAlgorithm.java +4 −1 Original line number Diff line number Diff line Loading @@ -500,8 +500,11 @@ public class PipBoundsAlgorithm implements PipDisplayLayoutState.DisplayIdListen // is closest to the current position. final int newLeft = fromLeft < fromRight ? movementBounds.left : movementBounds.right; // Make sure that the PiP window vertically stays within the movement bounds final int newTop = Math.max(movementBounds.top, Math.min(bounds.top, movementBounds.bottom)); bounds.offsetTo(newLeft, bounds.top); bounds.offsetTo(newLeft, newTop); } /** * Dumps internal states. Loading libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipDisplayTransferHandler.java +4 −2 Original line number Diff line number Diff line Loading @@ -146,6 +146,10 @@ public class PipDisplayTransferHandler implements Rect finalBounds = new Rect(pipBounds); final DisplayLayout targetDisplayLayout = mDisplayController.getDisplayLayout( mTargetDisplayId); mPipDisplayLayoutState.setDisplayId(mTargetDisplayId); mPipDisplayLayoutState.setDisplayLayout(targetDisplayLayout); // Snap to movement bounds edge of the target display ID on drag release. // The target display layout needs to be supplied since this happens before the PiP // is released and the display ID and layout are updated. Loading @@ -159,8 +163,6 @@ public class PipDisplayTransferHandler implements mPipTransitionState.setState(PipTransitionState.EXITING_PIP); mPipTransitionState.setState(PipTransitionState.EXITED_PIP); mPipDisplayLayoutState.setDisplayId(mTargetDisplayId); mPipDisplayLayoutState.setDisplayLayout(targetDisplayLayout); mPipTransitionState.setPinnedTaskLeash(pipLeash); mPipTransitionState.setPipTaskInfo(taskInfo); Loading libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipBoundsAlgorithmTest.java +46 −6 Original line number Diff line number Diff line Loading @@ -492,7 +492,7 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { @Test public void snapToMovementBoundsEdge_boundsSnappedToLeft() { final Rect bounds = new Rect(100, 100, 550, 480); final Rect bounds = new Rect(100, 200, 550, 480); final Rect originalBounds = new Rect(bounds); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds); Loading @@ -505,7 +505,7 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { @Test public void snapToMovementBoundsEdge_boundsSnappedToRight() { final Rect bounds = new Rect(700, 100, 900, 480); final Rect bounds = new Rect(700, 200, 900, 480); final Rect originalBounds = new Rect(bounds); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds); Loading @@ -521,10 +521,10 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { final DisplayInfo displayInfo = new DisplayInfo(); displayInfo.displayId = 2; displayInfo.logicalWidth = 500; displayInfo.logicalHeight = 500; displayInfo.logicalHeight = 1000; final DisplayLayout displayLayout = new DisplayLayout(displayInfo, mContext.getResources(), true, true); final Rect bounds = new Rect(100, 100, 200, 200); final Rect bounds = new Rect(100, 200, 200, 400); final Rect originalBounds = new Rect(bounds); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds, displayLayout); Loading @@ -540,10 +540,10 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { final DisplayInfo displayInfo = new DisplayInfo(); displayInfo.displayId = 2; displayInfo.logicalWidth = 500; displayInfo.logicalHeight = 500; displayInfo.logicalHeight = 1000; final DisplayLayout displayLayout = new DisplayLayout(displayInfo, mContext.getResources(), true, true); final Rect bounds = new Rect(300, 100, 400, 200); final Rect bounds = new Rect(300, 200, 400, 400); final Rect originalBounds = new Rect(bounds); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds, displayLayout); Loading @@ -554,6 +554,46 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { bounds.top, originalBounds.top); } @Test public void snapToMovementBoundsEdge_customDisplayLayout_boundsSnappedToMovementBoundsTop() { final DisplayInfo displayInfo = new DisplayInfo(); displayInfo.displayId = 2; displayInfo.logicalWidth = 500; displayInfo.logicalHeight = 500; final DisplayLayout displayLayout = new DisplayLayout(displayInfo, mContext.getResources(), true, true); final Rect bounds = new Rect(100, -100, 200, 0); final Rect movementBounds = mPipBoundsAlgorithm.getMovementBounds(bounds, true, displayLayout); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds, displayLayout); assertEquals("Bounds are snapped to left edge of movement bounds of custom display", bounds.left, mPipDisplayLayoutState.getInsetBounds(displayLayout).left); assertEquals("Bounds top edge is moved to movement bounds top", bounds.top, movementBounds.top); } @Test public void snapToMovementBoundsEdge_customDisplayLayout_boundsSnappedToMovementBoundsBottom() { final DisplayInfo displayInfo = new DisplayInfo(); displayInfo.displayId = 2; displayInfo.logicalWidth = 500; displayInfo.logicalHeight = 500; final DisplayLayout displayLayout = new DisplayLayout(displayInfo, mContext.getResources(), true, true); final Rect bounds = new Rect(300, 600, 400, 700); final Rect movementBounds = mPipBoundsAlgorithm.getMovementBounds(bounds, true, displayLayout); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds, displayLayout); assertEquals("Bounds are snapped to right edge of movement bounds of custom display", bounds.right, mPipDisplayLayoutState.getInsetBounds(displayLayout).right); assertEquals("Bounds top edge is moved to movement bounds bottom", bounds.top, movementBounds.bottom); } private void overrideDefaultAspectRatio(float aspectRatio) { final TestableResources res = mContext.getOrCreateTestableResources(); res.addOverride( Loading Loading
libs/WindowManager/Shell/src/com/android/wm/shell/common/pip/PipBoundsAlgorithm.java +4 −1 Original line number Diff line number Diff line Loading @@ -500,8 +500,11 @@ public class PipBoundsAlgorithm implements PipDisplayLayoutState.DisplayIdListen // is closest to the current position. final int newLeft = fromLeft < fromRight ? movementBounds.left : movementBounds.right; // Make sure that the PiP window vertically stays within the movement bounds final int newTop = Math.max(movementBounds.top, Math.min(bounds.top, movementBounds.bottom)); bounds.offsetTo(newLeft, bounds.top); bounds.offsetTo(newLeft, newTop); } /** * Dumps internal states. Loading
libs/WindowManager/Shell/src/com/android/wm/shell/pip2/phone/PipDisplayTransferHandler.java +4 −2 Original line number Diff line number Diff line Loading @@ -146,6 +146,10 @@ public class PipDisplayTransferHandler implements Rect finalBounds = new Rect(pipBounds); final DisplayLayout targetDisplayLayout = mDisplayController.getDisplayLayout( mTargetDisplayId); mPipDisplayLayoutState.setDisplayId(mTargetDisplayId); mPipDisplayLayoutState.setDisplayLayout(targetDisplayLayout); // Snap to movement bounds edge of the target display ID on drag release. // The target display layout needs to be supplied since this happens before the PiP // is released and the display ID and layout are updated. Loading @@ -159,8 +163,6 @@ public class PipDisplayTransferHandler implements mPipTransitionState.setState(PipTransitionState.EXITING_PIP); mPipTransitionState.setState(PipTransitionState.EXITED_PIP); mPipDisplayLayoutState.setDisplayId(mTargetDisplayId); mPipDisplayLayoutState.setDisplayLayout(targetDisplayLayout); mPipTransitionState.setPinnedTaskLeash(pipLeash); mPipTransitionState.setPipTaskInfo(taskInfo); Loading
libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/common/pip/PipBoundsAlgorithmTest.java +46 −6 Original line number Diff line number Diff line Loading @@ -492,7 +492,7 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { @Test public void snapToMovementBoundsEdge_boundsSnappedToLeft() { final Rect bounds = new Rect(100, 100, 550, 480); final Rect bounds = new Rect(100, 200, 550, 480); final Rect originalBounds = new Rect(bounds); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds); Loading @@ -505,7 +505,7 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { @Test public void snapToMovementBoundsEdge_boundsSnappedToRight() { final Rect bounds = new Rect(700, 100, 900, 480); final Rect bounds = new Rect(700, 200, 900, 480); final Rect originalBounds = new Rect(bounds); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds); Loading @@ -521,10 +521,10 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { final DisplayInfo displayInfo = new DisplayInfo(); displayInfo.displayId = 2; displayInfo.logicalWidth = 500; displayInfo.logicalHeight = 500; displayInfo.logicalHeight = 1000; final DisplayLayout displayLayout = new DisplayLayout(displayInfo, mContext.getResources(), true, true); final Rect bounds = new Rect(100, 100, 200, 200); final Rect bounds = new Rect(100, 200, 200, 400); final Rect originalBounds = new Rect(bounds); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds, displayLayout); Loading @@ -540,10 +540,10 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { final DisplayInfo displayInfo = new DisplayInfo(); displayInfo.displayId = 2; displayInfo.logicalWidth = 500; displayInfo.logicalHeight = 500; displayInfo.logicalHeight = 1000; final DisplayLayout displayLayout = new DisplayLayout(displayInfo, mContext.getResources(), true, true); final Rect bounds = new Rect(300, 100, 400, 200); final Rect bounds = new Rect(300, 200, 400, 400); final Rect originalBounds = new Rect(bounds); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds, displayLayout); Loading @@ -554,6 +554,46 @@ public class PipBoundsAlgorithmTest extends ShellTestCase { bounds.top, originalBounds.top); } @Test public void snapToMovementBoundsEdge_customDisplayLayout_boundsSnappedToMovementBoundsTop() { final DisplayInfo displayInfo = new DisplayInfo(); displayInfo.displayId = 2; displayInfo.logicalWidth = 500; displayInfo.logicalHeight = 500; final DisplayLayout displayLayout = new DisplayLayout(displayInfo, mContext.getResources(), true, true); final Rect bounds = new Rect(100, -100, 200, 0); final Rect movementBounds = mPipBoundsAlgorithm.getMovementBounds(bounds, true, displayLayout); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds, displayLayout); assertEquals("Bounds are snapped to left edge of movement bounds of custom display", bounds.left, mPipDisplayLayoutState.getInsetBounds(displayLayout).left); assertEquals("Bounds top edge is moved to movement bounds top", bounds.top, movementBounds.top); } @Test public void snapToMovementBoundsEdge_customDisplayLayout_boundsSnappedToMovementBoundsBottom() { final DisplayInfo displayInfo = new DisplayInfo(); displayInfo.displayId = 2; displayInfo.logicalWidth = 500; displayInfo.logicalHeight = 500; final DisplayLayout displayLayout = new DisplayLayout(displayInfo, mContext.getResources(), true, true); final Rect bounds = new Rect(300, 600, 400, 700); final Rect movementBounds = mPipBoundsAlgorithm.getMovementBounds(bounds, true, displayLayout); mPipBoundsAlgorithm.snapToMovementBoundsEdge(bounds, displayLayout); assertEquals("Bounds are snapped to right edge of movement bounds of custom display", bounds.right, mPipDisplayLayoutState.getInsetBounds(displayLayout).right); assertEquals("Bounds top edge is moved to movement bounds bottom", bounds.top, movementBounds.bottom); } private void overrideDefaultAspectRatio(float aspectRatio) { final TestableResources res = mContext.getOrCreateTestableResources(); res.addOverride( Loading