Loading core/java/com/android/internal/policy/PipSnapAlgorithm.java +28 −12 Original line number Original line Diff line number Diff line Loading @@ -36,15 +36,18 @@ import java.util.ArrayList; */ */ public class PipSnapAlgorithm { public class PipSnapAlgorithm { // The below SNAP_MODE_* constants correspond to the config resource value // config_pictureInPictureSnapMode and should not be changed independently. // Allows snapping to the four corners // Allows snapping to the four corners private static final int SNAP_MODE_CORNERS_ONLY = 0; private static final int SNAP_MODE_CORNERS_ONLY = 0; // Allows snapping to the four corners and the mid-points on the long edge in each orientation // Allows snapping to the four corners and the mid-points on the long edge in each orientation private static final int SNAP_MODE_CORNERS_AND_SIDES = 1; private static final int SNAP_MODE_CORNERS_AND_SIDES = 1; // Allows snapping to anywhere along the edge of the screen // Allows snapping to anywhere along the edge of the screen private static final int SNAP_MODE_EDGE = 2; private static final int SNAP_MODE_EDGE = 2; // Allows snapping to four corners on a fling towards a corner or slow move near a corner // Allows snapping anywhere along the edge of the screen and magnets towards corners // snaps anywhere along the edge of screen otherwise private static final int SNAP_MODE_EDGE_MAGNET_CORNERS = 3; private static final int SNAP_MODE_CORNERS_AND_EDGES = 3; // Allows snapping on the long edge in each orientation and magnets towards corners private static final int SNAP_MODE_LONG_EDGE_MAGNET_CORNERS = 4; // The friction multiplier to control how slippery the PIP is when flung // The friction multiplier to control how slippery the PIP is when flung private static final float SCROLL_FRICTION_MULTIPLIER = 8f; private static final float SCROLL_FRICTION_MULTIPLIER = 8f; Loading @@ -55,7 +58,7 @@ public class PipSnapAlgorithm { private final Context mContext; private final Context mContext; private final ArrayList<Integer> mSnapGravities = new ArrayList<>(); private final ArrayList<Integer> mSnapGravities = new ArrayList<>(); private final int mDefaultSnapMode = SNAP_MODE_CORNERS_AND_EDGES; private final int mDefaultSnapMode = SNAP_MODE_EDGE_MAGNET_CORNERS; private int mSnapMode = mDefaultSnapMode; private int mSnapMode = mDefaultSnapMode; private final float mDefaultSizePercent; private final float mDefaultSizePercent; Loading Loading @@ -85,7 +88,9 @@ public class PipSnapAlgorithm { * Updates the snap algorithm when the configuration changes. * Updates the snap algorithm when the configuration changes. */ */ public void onConfigurationChanged() { public void onConfigurationChanged() { mOrientation = mContext.getResources().getConfiguration().orientation; Resources res = mContext.getResources(); mOrientation = res.getConfiguration().orientation; mSnapMode = res.getInteger(com.android.internal.R.integer.config_pictureInPictureSnapMode); calculateSnapTargets(); calculateSnapTargets(); } } Loading Loading @@ -127,7 +132,8 @@ public class PipSnapAlgorithm { movementBounds.right + stackBounds.width(), movementBounds.right + stackBounds.width(), movementBounds.bottom + stackBounds.height()); movementBounds.bottom + stackBounds.height()); final Rect newBounds = new Rect(stackBounds); final Rect newBounds = new Rect(stackBounds); if (mSnapMode == SNAP_MODE_CORNERS_AND_EDGES) { if (mSnapMode == SNAP_MODE_LONG_EDGE_MAGNET_CORNERS || mSnapMode == SNAP_MODE_EDGE_MAGNET_CORNERS) { final Rect tmpBounds = new Rect(); final Rect tmpBounds = new Rect(); final Point[] snapTargets = new Point[mSnapGravities.size()]; final Point[] snapTargets = new Point[mSnapGravities.size()]; for (int i = 0; i < mSnapGravities.size(); i++) { for (int i = 0; i < mSnapGravities.size(); i++) { Loading @@ -137,11 +143,11 @@ public class PipSnapAlgorithm { } } Point snapTarget = findClosestPoint(stackBounds.left, stackBounds.top, snapTargets); Point snapTarget = findClosestPoint(stackBounds.left, stackBounds.top, snapTargets); float distance = distanceToPoint(snapTarget, stackBounds.left, stackBounds.top); float distance = distanceToPoint(snapTarget, stackBounds.left, stackBounds.top); final float thresh = stackBounds.width() * CORNER_MAGNET_THRESHOLD; final float thresh = Math.max(stackBounds.width(), stackBounds.height()) * CORNER_MAGNET_THRESHOLD; if (distance < thresh) { if (distance < thresh) { newBounds.offsetTo(snapTarget.x, snapTarget.y); newBounds.offsetTo(snapTarget.x, snapTarget.y); } else { } else { // Otherwise we snap to the edge snapRectToClosestEdge(stackBounds, movementBounds, newBounds); snapRectToClosestEdge(stackBounds, movementBounds, newBounds); } } } else if (mSnapMode == SNAP_MODE_EDGE) { } else if (mSnapMode == SNAP_MODE_EDGE) { Loading Loading @@ -324,11 +330,20 @@ public class PipSnapAlgorithm { final int fromTop = Math.abs(stackBounds.top - movementBounds.top); final int fromTop = Math.abs(stackBounds.top - movementBounds.top); final int fromRight = Math.abs(movementBounds.right - stackBounds.left); final int fromRight = Math.abs(movementBounds.right - stackBounds.left); final int fromBottom = Math.abs(movementBounds.bottom - stackBounds.top); final int fromBottom = Math.abs(movementBounds.bottom - stackBounds.top); if (fromLeft <= fromTop && fromLeft <= fromRight && fromLeft <= fromBottom) { int shortest; if (mSnapMode == SNAP_MODE_LONG_EDGE_MAGNET_CORNERS) { // Only check longest edges shortest = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? Math.min(fromTop, fromBottom) : Math.min(fromLeft, fromRight); } else { shortest = Math.min(Math.min(fromLeft, fromRight), Math.min(fromTop, fromBottom)); } if (shortest == fromLeft) { boundsOut.offsetTo(movementBounds.left, boundedTop); boundsOut.offsetTo(movementBounds.left, boundedTop); } else if (fromTop <= fromLeft && fromTop <= fromRight && fromTop <= fromBottom) { } else if (shortest == fromTop) { boundsOut.offsetTo(boundedLeft, movementBounds.top); boundsOut.offsetTo(boundedLeft, movementBounds.top); } else if (fromRight < fromLeft && fromRight < fromTop && fromRight < fromBottom) { } else if (shortest == fromRight) { boundsOut.offsetTo(movementBounds.right, boundedTop); boundsOut.offsetTo(movementBounds.right, boundedTop); } else { } else { boundsOut.offsetTo(boundedLeft, movementBounds.bottom); boundsOut.offsetTo(boundedLeft, movementBounds.bottom); Loading Loading @@ -358,7 +373,8 @@ public class PipSnapAlgorithm { } } // Fall through // Fall through case SNAP_MODE_CORNERS_ONLY: case SNAP_MODE_CORNERS_ONLY: case SNAP_MODE_CORNERS_AND_EDGES: case SNAP_MODE_EDGE_MAGNET_CORNERS: case SNAP_MODE_LONG_EDGE_MAGNET_CORNERS: mSnapGravities.add(Gravity.TOP | Gravity.LEFT); mSnapGravities.add(Gravity.TOP | Gravity.LEFT); mSnapGravities.add(Gravity.TOP | Gravity.RIGHT); mSnapGravities.add(Gravity.TOP | Gravity.RIGHT); mSnapGravities.add(Gravity.BOTTOM | Gravity.LEFT); mSnapGravities.add(Gravity.BOTTOM | Gravity.LEFT); Loading core/res/res/values-sw600dp/config.xml +11 −1 Original line number Original line Diff line number Diff line Loading @@ -41,5 +41,15 @@ <dimen name="config_minScalingSpan">32mm</dimen> <dimen name="config_minScalingSpan">32mm</dimen> <integer name="config_dockedStackDividerSnapMode">1</integer> <integer name="config_dockedStackDividerSnapMode">1</integer> <!-- The snap mode to use for picture-in-picture. These values correspond to constants defined in PipSnapAlgorithm and should not be changed independently. 0 - Snap to the four corners 1 - Snap to the four corners and the mid-points on the long edge in each orientation 2 - Snap anywhere along the edge of the screen 3 - Snap anywhere along the edge of the screen and magnet to corners 4 - Snap to the long edges in each orientation and magnet to corners --> <integer name="config_pictureInPictureSnapMode">3</integer> </resources> </resources> core/res/res/values/config.xml +10 −0 Original line number Original line Diff line number Diff line Loading @@ -2569,6 +2569,16 @@ ratio larger than this is considered to wide and short to be usable. --> ratio larger than this is considered to wide and short to be usable. --> <item name="config_pictureInPictureMaxAspectRatio" format="float" type="dimen">2.35</item> <item name="config_pictureInPictureMaxAspectRatio" format="float" type="dimen">2.35</item> <!-- The snap mode to use for picture-in-picture. These values correspond to constants defined in PipSnapAlgorithm and should not be changed independently. 0 - Snap to the four corners 1 - Snap to the four corners and the mid-points on the long edge in each orientation 2 - Snap anywhere along the edge of the screen 3 - Snap anywhere along the edge of the screen and magnet to corners 4 - Snap to the long edges in each orientation and magnet to corners --> <integer name="config_pictureInPictureSnapMode">4</integer> <!-- Controls the snap mode for the docked stack divider <!-- Controls the snap mode for the docked stack divider 0 - 3 snap targets: left/top has 16:9 ratio, 1:1, and right/bottom has 16:9 ratio 0 - 3 snap targets: left/top has 16:9 ratio, 1:1, and right/bottom has 16:9 ratio 1 - 3 snap targets: fixed ratio, 1:1, (1 - fixed ratio) 1 - 3 snap targets: fixed ratio, 1:1, (1 - fixed ratio) Loading core/res/res/values/symbols.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -1556,6 +1556,7 @@ <java-symbol type="dimen" name="docked_stack_minimize_thickness" /> <java-symbol type="dimen" name="docked_stack_minimize_thickness" /> <java-symbol type="dimen" name="pip_minimized_visible_size" /> <java-symbol type="dimen" name="pip_minimized_visible_size" /> <java-symbol type="integer" name="config_dockedStackDividerSnapMode" /> <java-symbol type="integer" name="config_dockedStackDividerSnapMode" /> <java-symbol type="integer" name="config_pictureInPictureSnapMode" /> <java-symbol type="fraction" name="docked_stack_divider_fixed_ratio" /> <java-symbol type="fraction" name="docked_stack_divider_fixed_ratio" /> <java-symbol type="fraction" name="thumbnail_fullscreen_scale" /> <java-symbol type="fraction" name="thumbnail_fullscreen_scale" /> <java-symbol type="integer" name="thumbnail_width_tv" /> <java-symbol type="integer" name="thumbnail_width_tv" /> Loading Loading
core/java/com/android/internal/policy/PipSnapAlgorithm.java +28 −12 Original line number Original line Diff line number Diff line Loading @@ -36,15 +36,18 @@ import java.util.ArrayList; */ */ public class PipSnapAlgorithm { public class PipSnapAlgorithm { // The below SNAP_MODE_* constants correspond to the config resource value // config_pictureInPictureSnapMode and should not be changed independently. // Allows snapping to the four corners // Allows snapping to the four corners private static final int SNAP_MODE_CORNERS_ONLY = 0; private static final int SNAP_MODE_CORNERS_ONLY = 0; // Allows snapping to the four corners and the mid-points on the long edge in each orientation // Allows snapping to the four corners and the mid-points on the long edge in each orientation private static final int SNAP_MODE_CORNERS_AND_SIDES = 1; private static final int SNAP_MODE_CORNERS_AND_SIDES = 1; // Allows snapping to anywhere along the edge of the screen // Allows snapping to anywhere along the edge of the screen private static final int SNAP_MODE_EDGE = 2; private static final int SNAP_MODE_EDGE = 2; // Allows snapping to four corners on a fling towards a corner or slow move near a corner // Allows snapping anywhere along the edge of the screen and magnets towards corners // snaps anywhere along the edge of screen otherwise private static final int SNAP_MODE_EDGE_MAGNET_CORNERS = 3; private static final int SNAP_MODE_CORNERS_AND_EDGES = 3; // Allows snapping on the long edge in each orientation and magnets towards corners private static final int SNAP_MODE_LONG_EDGE_MAGNET_CORNERS = 4; // The friction multiplier to control how slippery the PIP is when flung // The friction multiplier to control how slippery the PIP is when flung private static final float SCROLL_FRICTION_MULTIPLIER = 8f; private static final float SCROLL_FRICTION_MULTIPLIER = 8f; Loading @@ -55,7 +58,7 @@ public class PipSnapAlgorithm { private final Context mContext; private final Context mContext; private final ArrayList<Integer> mSnapGravities = new ArrayList<>(); private final ArrayList<Integer> mSnapGravities = new ArrayList<>(); private final int mDefaultSnapMode = SNAP_MODE_CORNERS_AND_EDGES; private final int mDefaultSnapMode = SNAP_MODE_EDGE_MAGNET_CORNERS; private int mSnapMode = mDefaultSnapMode; private int mSnapMode = mDefaultSnapMode; private final float mDefaultSizePercent; private final float mDefaultSizePercent; Loading Loading @@ -85,7 +88,9 @@ public class PipSnapAlgorithm { * Updates the snap algorithm when the configuration changes. * Updates the snap algorithm when the configuration changes. */ */ public void onConfigurationChanged() { public void onConfigurationChanged() { mOrientation = mContext.getResources().getConfiguration().orientation; Resources res = mContext.getResources(); mOrientation = res.getConfiguration().orientation; mSnapMode = res.getInteger(com.android.internal.R.integer.config_pictureInPictureSnapMode); calculateSnapTargets(); calculateSnapTargets(); } } Loading Loading @@ -127,7 +132,8 @@ public class PipSnapAlgorithm { movementBounds.right + stackBounds.width(), movementBounds.right + stackBounds.width(), movementBounds.bottom + stackBounds.height()); movementBounds.bottom + stackBounds.height()); final Rect newBounds = new Rect(stackBounds); final Rect newBounds = new Rect(stackBounds); if (mSnapMode == SNAP_MODE_CORNERS_AND_EDGES) { if (mSnapMode == SNAP_MODE_LONG_EDGE_MAGNET_CORNERS || mSnapMode == SNAP_MODE_EDGE_MAGNET_CORNERS) { final Rect tmpBounds = new Rect(); final Rect tmpBounds = new Rect(); final Point[] snapTargets = new Point[mSnapGravities.size()]; final Point[] snapTargets = new Point[mSnapGravities.size()]; for (int i = 0; i < mSnapGravities.size(); i++) { for (int i = 0; i < mSnapGravities.size(); i++) { Loading @@ -137,11 +143,11 @@ public class PipSnapAlgorithm { } } Point snapTarget = findClosestPoint(stackBounds.left, stackBounds.top, snapTargets); Point snapTarget = findClosestPoint(stackBounds.left, stackBounds.top, snapTargets); float distance = distanceToPoint(snapTarget, stackBounds.left, stackBounds.top); float distance = distanceToPoint(snapTarget, stackBounds.left, stackBounds.top); final float thresh = stackBounds.width() * CORNER_MAGNET_THRESHOLD; final float thresh = Math.max(stackBounds.width(), stackBounds.height()) * CORNER_MAGNET_THRESHOLD; if (distance < thresh) { if (distance < thresh) { newBounds.offsetTo(snapTarget.x, snapTarget.y); newBounds.offsetTo(snapTarget.x, snapTarget.y); } else { } else { // Otherwise we snap to the edge snapRectToClosestEdge(stackBounds, movementBounds, newBounds); snapRectToClosestEdge(stackBounds, movementBounds, newBounds); } } } else if (mSnapMode == SNAP_MODE_EDGE) { } else if (mSnapMode == SNAP_MODE_EDGE) { Loading Loading @@ -324,11 +330,20 @@ public class PipSnapAlgorithm { final int fromTop = Math.abs(stackBounds.top - movementBounds.top); final int fromTop = Math.abs(stackBounds.top - movementBounds.top); final int fromRight = Math.abs(movementBounds.right - stackBounds.left); final int fromRight = Math.abs(movementBounds.right - stackBounds.left); final int fromBottom = Math.abs(movementBounds.bottom - stackBounds.top); final int fromBottom = Math.abs(movementBounds.bottom - stackBounds.top); if (fromLeft <= fromTop && fromLeft <= fromRight && fromLeft <= fromBottom) { int shortest; if (mSnapMode == SNAP_MODE_LONG_EDGE_MAGNET_CORNERS) { // Only check longest edges shortest = (mOrientation == Configuration.ORIENTATION_LANDSCAPE) ? Math.min(fromTop, fromBottom) : Math.min(fromLeft, fromRight); } else { shortest = Math.min(Math.min(fromLeft, fromRight), Math.min(fromTop, fromBottom)); } if (shortest == fromLeft) { boundsOut.offsetTo(movementBounds.left, boundedTop); boundsOut.offsetTo(movementBounds.left, boundedTop); } else if (fromTop <= fromLeft && fromTop <= fromRight && fromTop <= fromBottom) { } else if (shortest == fromTop) { boundsOut.offsetTo(boundedLeft, movementBounds.top); boundsOut.offsetTo(boundedLeft, movementBounds.top); } else if (fromRight < fromLeft && fromRight < fromTop && fromRight < fromBottom) { } else if (shortest == fromRight) { boundsOut.offsetTo(movementBounds.right, boundedTop); boundsOut.offsetTo(movementBounds.right, boundedTop); } else { } else { boundsOut.offsetTo(boundedLeft, movementBounds.bottom); boundsOut.offsetTo(boundedLeft, movementBounds.bottom); Loading Loading @@ -358,7 +373,8 @@ public class PipSnapAlgorithm { } } // Fall through // Fall through case SNAP_MODE_CORNERS_ONLY: case SNAP_MODE_CORNERS_ONLY: case SNAP_MODE_CORNERS_AND_EDGES: case SNAP_MODE_EDGE_MAGNET_CORNERS: case SNAP_MODE_LONG_EDGE_MAGNET_CORNERS: mSnapGravities.add(Gravity.TOP | Gravity.LEFT); mSnapGravities.add(Gravity.TOP | Gravity.LEFT); mSnapGravities.add(Gravity.TOP | Gravity.RIGHT); mSnapGravities.add(Gravity.TOP | Gravity.RIGHT); mSnapGravities.add(Gravity.BOTTOM | Gravity.LEFT); mSnapGravities.add(Gravity.BOTTOM | Gravity.LEFT); Loading
core/res/res/values-sw600dp/config.xml +11 −1 Original line number Original line Diff line number Diff line Loading @@ -41,5 +41,15 @@ <dimen name="config_minScalingSpan">32mm</dimen> <dimen name="config_minScalingSpan">32mm</dimen> <integer name="config_dockedStackDividerSnapMode">1</integer> <integer name="config_dockedStackDividerSnapMode">1</integer> <!-- The snap mode to use for picture-in-picture. These values correspond to constants defined in PipSnapAlgorithm and should not be changed independently. 0 - Snap to the four corners 1 - Snap to the four corners and the mid-points on the long edge in each orientation 2 - Snap anywhere along the edge of the screen 3 - Snap anywhere along the edge of the screen and magnet to corners 4 - Snap to the long edges in each orientation and magnet to corners --> <integer name="config_pictureInPictureSnapMode">3</integer> </resources> </resources>
core/res/res/values/config.xml +10 −0 Original line number Original line Diff line number Diff line Loading @@ -2569,6 +2569,16 @@ ratio larger than this is considered to wide and short to be usable. --> ratio larger than this is considered to wide and short to be usable. --> <item name="config_pictureInPictureMaxAspectRatio" format="float" type="dimen">2.35</item> <item name="config_pictureInPictureMaxAspectRatio" format="float" type="dimen">2.35</item> <!-- The snap mode to use for picture-in-picture. These values correspond to constants defined in PipSnapAlgorithm and should not be changed independently. 0 - Snap to the four corners 1 - Snap to the four corners and the mid-points on the long edge in each orientation 2 - Snap anywhere along the edge of the screen 3 - Snap anywhere along the edge of the screen and magnet to corners 4 - Snap to the long edges in each orientation and magnet to corners --> <integer name="config_pictureInPictureSnapMode">4</integer> <!-- Controls the snap mode for the docked stack divider <!-- Controls the snap mode for the docked stack divider 0 - 3 snap targets: left/top has 16:9 ratio, 1:1, and right/bottom has 16:9 ratio 0 - 3 snap targets: left/top has 16:9 ratio, 1:1, and right/bottom has 16:9 ratio 1 - 3 snap targets: fixed ratio, 1:1, (1 - fixed ratio) 1 - 3 snap targets: fixed ratio, 1:1, (1 - fixed ratio) Loading
core/res/res/values/symbols.xml +1 −0 Original line number Original line Diff line number Diff line Loading @@ -1556,6 +1556,7 @@ <java-symbol type="dimen" name="docked_stack_minimize_thickness" /> <java-symbol type="dimen" name="docked_stack_minimize_thickness" /> <java-symbol type="dimen" name="pip_minimized_visible_size" /> <java-symbol type="dimen" name="pip_minimized_visible_size" /> <java-symbol type="integer" name="config_dockedStackDividerSnapMode" /> <java-symbol type="integer" name="config_dockedStackDividerSnapMode" /> <java-symbol type="integer" name="config_pictureInPictureSnapMode" /> <java-symbol type="fraction" name="docked_stack_divider_fixed_ratio" /> <java-symbol type="fraction" name="docked_stack_divider_fixed_ratio" /> <java-symbol type="fraction" name="thumbnail_fullscreen_scale" /> <java-symbol type="fraction" name="thumbnail_fullscreen_scale" /> <java-symbol type="integer" name="thumbnail_width_tv" /> <java-symbol type="integer" name="thumbnail_width_tv" /> Loading