PiP: Take inset into consideration when calculating stash offset.
When stashing, currently it assumes the entire display is usable - not taking into insets into consideration that can be caused by navigation bar, etc. Bug: 186698828 Test: Manual. Stashing PIP while w/ insets now stashes correctly. Test: atest PipSnapAlgorithmTest Change-Id: Ia6cbb8f21b666a4ba4ee10b84e3087b6a23cd982
This commit is contained in:
@@ -109,13 +109,14 @@ public class PipSnapAlgorithm {
|
||||
* consideration.
|
||||
*/
|
||||
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);
|
||||
|
||||
if (stashType != STASH_TYPE_NONE) {
|
||||
stackBounds.offsetTo(stashType == STASH_TYPE_LEFT
|
||||
? stashOffset - stackBounds.width()
|
||||
: displayBounds.right - stashOffset,
|
||||
? stashOffset - stackBounds.width() + insetBounds.left
|
||||
: displayBounds.right - stashOffset - insetBounds.right,
|
||||
stackBounds.top);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -464,7 +464,8 @@ public class PipController implements PipTransitionController.PipTransitionCallb
|
||||
pipSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
|
||||
snapFraction, mPipBoundsState.getStashedState(),
|
||||
mPipBoundsState.getStashOffset(),
|
||||
mPipBoundsState.getDisplayBounds());
|
||||
mPipBoundsState.getDisplayBounds(),
|
||||
mPipBoundsState.getDisplayLayout().stableInsets());
|
||||
|
||||
mTouchHandler.getMotionHelper().movePip(postChangeStackBounds);
|
||||
} else {
|
||||
@@ -668,7 +669,8 @@ public class PipController implements PipTransitionController.PipTransitionCallb
|
||||
postChangeStackBounds, false /* adjustForIme */);
|
||||
pipSnapAlgorithm.applySnapFraction(postChangeStackBounds, postChangeMovementBounds,
|
||||
snapFraction, mPipBoundsState.getStashedState(), mPipBoundsState.getStashOffset(),
|
||||
mPipBoundsState.getDisplayBounds());
|
||||
mPipBoundsState.getDisplayBounds(),
|
||||
mPipBoundsState.getDisplayLayout().stableInsets());
|
||||
|
||||
mPipBoundsAlgorithm.getInsetBounds(outInsetBounds);
|
||||
outBounds.set(postChangeStackBounds);
|
||||
|
||||
@@ -406,11 +406,14 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
||||
.flingThenSpring(
|
||||
FloatProperties.RECT_Y, velocityY, mFlingConfigY, mSpringConfig);
|
||||
|
||||
final Rect insetBounds = mPipBoundsState.getDisplayLayout().stableInsets();
|
||||
final float leftEdge = isStash
|
||||
? mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width()
|
||||
+ insetBounds.left
|
||||
: mPipBoundsState.getMovementBounds().left;
|
||||
final float rightEdge = isStash
|
||||
? mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset()
|
||||
- insetBounds.right
|
||||
: mPipBoundsState.getMovementBounds().right;
|
||||
|
||||
final float xEndValue = velocityX < 0 ? leftEdge : rightEdge;
|
||||
@@ -483,7 +486,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
||||
|
||||
mSnapAlgorithm.applySnapFraction(normalBounds, normalMovementBounds, savedSnapFraction,
|
||||
mPipBoundsState.getStashedState(), mPipBoundsState.getStashOffset(),
|
||||
mPipBoundsState.getDisplayBounds());
|
||||
mPipBoundsState.getDisplayBounds(),
|
||||
mPipBoundsState.getDisplayLayout().stableInsets());
|
||||
|
||||
if (immediate) {
|
||||
movePip(normalBounds);
|
||||
@@ -529,10 +533,13 @@ public class PipMotionHelper implements PipAppOpsListener.Callback,
|
||||
mFlingConfigY = new PhysicsAnimator.FlingConfig(DEFAULT_FRICTION,
|
||||
mPipBoundsState.getMovementBounds().top,
|
||||
mPipBoundsState.getMovementBounds().bottom);
|
||||
final Rect insetBounds = mPipBoundsState.getDisplayLayout().stableInsets();
|
||||
mStashConfigX = new PhysicsAnimator.FlingConfig(
|
||||
DEFAULT_FRICTION,
|
||||
mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width(),
|
||||
mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset());
|
||||
mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width()
|
||||
+ insetBounds.left,
|
||||
mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset()
|
||||
- insetBounds.right);
|
||||
}
|
||||
|
||||
private void startBoundsAnimator(float toX, float toY) {
|
||||
|
||||
@@ -38,6 +38,8 @@ public class PipSnapAlgorithmTest extends ShellTestCase {
|
||||
private static final int DEFAULT_STASH_OFFSET = 32;
|
||||
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 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,
|
||||
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);
|
||||
|
||||
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.bottom, bounds.top);
|
||||
@@ -111,7 +114,8 @@ public class PipSnapAlgorithmTest extends ShellTestCase {
|
||||
final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
|
||||
|
||||
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;
|
||||
assertEquals(MOVEMENT_BOUNDS.left - offBoundsWidth, bounds.left);
|
||||
@@ -124,12 +128,27 @@ public class PipSnapAlgorithmTest extends ShellTestCase {
|
||||
final Rect bounds = new Rect(STACK_BOUNDS_CENTERED);
|
||||
|
||||
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(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
|
||||
public void testSnapRectToClosestEdge_rightEdge() {
|
||||
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);
|
||||
// Stash it on the left side.
|
||||
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,
|
||||
PipBoundsState.STASH_TYPE_LEFT);
|
||||
|
||||
Reference in New Issue
Block a user