Ensure we account for insets in minimized state.

- When dragging slightly offscreen to minimize the PIP,
  ensure that the bounds take the insets into account so
  that the user can still interact with the PIP.

Test: Enter PIP in landscape, try to minimize it.

Change-Id: I093a37ba600722d44e50cc68dac77365a2ba062e
This commit is contained in:
Winson Chung
2017-01-09 16:08:07 -08:00
parent 7d13f29b12
commit 114aeea516
4 changed files with 19 additions and 9 deletions

View File

@@ -128,11 +128,14 @@ public class PipSnapAlgorithm {
/**
* Applies the offset to the {@param stackBounds} to adjust it to a minimized state.
*/
public void applyMinimizedOffset(Rect stackBounds, Rect movementBounds, Point displaySize) {
public void applyMinimizedOffset(Rect stackBounds, Rect movementBounds, Point displaySize,
Rect stableInsets) {
if (stackBounds.left <= movementBounds.centerX()) {
stackBounds.offsetTo(-stackBounds.width() + mMinimizedVisibleSize, stackBounds.top);
stackBounds.offsetTo(stableInsets.left + mMinimizedVisibleSize - stackBounds.width(),
stackBounds.top);
} else {
stackBounds.offsetTo(displaySize.x - mMinimizedVisibleSize, stackBounds.top);
stackBounds.offsetTo(displaySize.x - stableInsets.right - mMinimizedVisibleSize,
stackBounds.top);
}
}

View File

@@ -87,6 +87,7 @@ public class PipTouchHandler implements TunerService.Tunable {
// Allow the PIP to be "docked" slightly offscreen
private boolean mEnableMinimizing = true;
private final Rect mStableInsets = new Rect();
private final Rect mPinnedStackBounds = new Rect();
private final Rect mBoundedPinnedStackBounds = new Rect();
private ValueAnimator mPinnedStackBoundsAnimator = null;
@@ -421,7 +422,8 @@ public class PipTouchHandler implements TunerService.Tunable {
mContext.getDisplay().getRealSize(displaySize);
Rect toBounds = mSnapAlgorithm.findClosestSnapBounds(mBoundedPinnedStackBounds,
mPinnedStackBounds);
mSnapAlgorithm.applyMinimizedOffset(toBounds, mBoundedPinnedStackBounds, displaySize);
mSnapAlgorithm.applyMinimizedOffset(toBounds, mBoundedPinnedStackBounds, displaySize,
mStableInsets);
mPinnedStackBoundsAnimator = mMotionHelper.createAnimationToBounds(mPinnedStackBounds,
toBounds, MINIMIZE_STACK_MAX_DURATION, LINEAR_OUT_SLOW_IN,
mUpdatePinnedStackBoundsListener);
@@ -528,6 +530,7 @@ public class PipTouchHandler implements TunerService.Tunable {
if (updatePinnedStackBounds) {
mPinnedStackBounds.set(info.bounds);
}
mWindowManager.getStableInsets(info.displayId, mStableInsets);
mBoundedPinnedStackBounds.set(mWindowManager.getPictureInPictureMovementBounds(
info.displayId));
}

View File

@@ -82,6 +82,7 @@ class PinnedStackController {
// Used to calculate stack bounds across rotations
private final DisplayInfo mDisplayInfo = new DisplayInfo();
private final Rect mStableInsets = new Rect();
// The size and position information that describes where the pinned stack will go by default.
private int mDefaultStackGravity;
@@ -250,10 +251,12 @@ class PinnedStackController {
}
/**
* @return the repositioned PIP bounds given it's pre-change bounds, and the new display info.
* @return the repositioned PIP bounds given it's pre-change bounds, and the new display
* content.
*/
Rect onDisplayChanged(Rect preChangeStackBounds, DisplayInfo displayInfo) {
Rect onDisplayChanged(Rect preChangeStackBounds, DisplayContent displayContent) {
final Rect postChangeStackBounds = new Rect(preChangeStackBounds);
final DisplayInfo displayInfo = displayContent.getDisplayInfo();
if (!mDisplayInfo.equals(displayInfo)) {
// Calculate the snap fraction of the current stack along the old movement bounds, and
// then update the stack bounds to the same fraction along the rotated movement bounds.
@@ -269,8 +272,9 @@ class PinnedStackController {
if (mIsMinimized) {
final Point displaySize = new Point(mDisplayInfo.logicalWidth,
mDisplayInfo.logicalHeight);
mService.getStableInsetsLocked(displayContent.getDisplayId(), mStableInsets);
mSnapAlgorithm.applyMinimizedOffset(postChangeStackBounds, postChangeMovementBounds,
displaySize);
displaySize, mStableInsets);
}
}
return postChangeStackBounds;

View File

@@ -413,7 +413,7 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
switch (mStackId) {
case PINNED_STACK_ID:
mTmpRect2 = mDisplayContent.getPinnedStackController().onDisplayChanged(mBounds,
getDisplayInfo());
mDisplayContent);
break;
case DOCKED_STACK_ID:
repositionDockedStackAfterRotation(mTmpRect2);
@@ -684,7 +684,7 @@ public class TaskStack extends WindowContainer<Task> implements DimLayer.DimLaye
// Update the pinned stack controller after the display info is updated
if (mStackId == PINNED_STACK_ID) {
mDisplayContent.getPinnedStackController().onDisplayChanged(oldBounds,
getDisplayInfo());
mDisplayContent);
}
super.onDisplayChanged(dc);