Use last user-resized size when re-entering PIP

Bug: 160799929
Test: enter PIP, resize it, restore to fullscreen then re-enter.
The re-entry size should be the same as when exiting.

Change-Id: Idb36b5ec51c2d76b9df5f311518652109fa57b37
Merged-In: Idb36b5ec51c2d76b9df5f311518652109fa57b37
(cherry picked from commit 134e7fc413)
This commit is contained in:
jorgegil@google.com
2020-08-04 14:46:55 -07:00
committed by Jorge Gil
parent ca28a90bec
commit 89f122abe2
3 changed files with 19 additions and 16 deletions

View File

@@ -377,12 +377,7 @@ public class PipManager implements BasePipManager, PipTaskOrganizer.PipTransitio
* Update the bounds used to save the re-entry size and snap fraction when exiting PIP.
*/
public void updateReentryBounds() {
// On phones, the expansion animation that happens on pip tap before restoring
// to fullscreen makes it so that the last reported bounds are the expanded
// bounds. We want to restore to the unexpanded bounds when re-entering pip,
// so we use the bounds before expansion (normal) instead of the reported
// bounds.
Rect reentryBounds = mTouchHandler.getNormalBounds();
final Rect reentryBounds = mTouchHandler.getUserResizeBounds();
// Apply the snap fraction of the current bounds to the normal bounds.
final Rect bounds = mPipTaskOrganizer.getLastReportedBounds();
float snapFraction = mPipBoundsHandler.getSnapFraction(bounds);

View File

@@ -89,6 +89,7 @@ public class PipResizeGestureHandler {
private final Point mMaxSize = new Point();
private final Point mMinSize = new Point();
private final Rect mLastResizeBounds = new Rect();
private final Rect mUserResizeBounds = new Rect();
private final Rect mLastDownBounds = new Rect();
private final Rect mDragCornerSize = new Rect();
private final Rect mTmpTopLeftCorner = new Rect();
@@ -185,6 +186,7 @@ public class PipResizeGestureHandler {
void onActivityUnpinned() {
mIsAttached = false;
mUserResizeBounds.setEmpty();
updateIsEnabled();
}
@@ -333,6 +335,7 @@ public class PipResizeGestureHandler {
case MotionEvent.ACTION_UP:
case MotionEvent.ACTION_CANCEL:
if (!mLastResizeBounds.isEmpty()) {
mUserResizeBounds.set(mLastResizeBounds);
mPipTaskOrganizer.scheduleFinishResizePip(mLastResizeBounds,
(Rect bounds) -> {
new Handler(Looper.getMainLooper()).post(() -> {
@@ -357,6 +360,14 @@ public class PipResizeGestureHandler {
mThresholdCrossed = false;
}
void setUserResizeBounds(Rect bounds) {
mUserResizeBounds.set(bounds);
}
Rect getUserResizeBounds() {
return mUserResizeBounds;
}
void updateMaxSize(int maxX, int maxY) {
mMaxSize.set(maxX, maxY);
}

View File

@@ -133,9 +133,6 @@ public class PipTouchHandler {
// The current movement bounds
private Rect mMovementBounds = new Rect();
// The current resized bounds, changed by user resize.
// This is used during expand/un-expand to save/restore the user's resized size.
@VisibleForTesting Rect mResizedBounds = new Rect();
// The reference inset bounds, used to determine the dismiss fraction
private Rect mInsetBounds = new Rect();
@@ -376,7 +373,6 @@ public class PipTouchHandler {
mFloatingContentCoordinator.onContentRemoved(mMotionHelper);
}
mResizedBounds.setEmpty();
mPipResizeGestureHandler.onActivityUnpinned();
}
@@ -386,9 +382,8 @@ public class PipTouchHandler {
mMotionHelper.synchronizePinnedStackBounds();
updateMovementBounds();
if (direction == TRANSITION_DIRECTION_TO_PIP) {
// updates mResizedBounds only if it's an entering PiP animation
// mResized should be otherwise updated in setMenuState.
mResizedBounds.set(mMotionHelper.getBounds());
// Set the initial bounds as the user resize bounds.
mPipResizeGestureHandler.setUserResizeBounds(mMotionHelper.getBounds());
}
if (mShowPipMenuOnAnimationEnd) {
@@ -801,9 +796,7 @@ public class PipTouchHandler {
// Save the current snap fraction and if we do not drag or move the PiP, then
// we store back to this snap fraction. Otherwise, we'll reset the snap
// fraction and snap to the closest edge.
// Also save the current resized bounds so when the menu disappears, we can restore it.
if (resize) {
mResizedBounds.set(mMotionHelper.getBounds());
Rect expandedBounds = new Rect(mExpandedBounds);
mSavedSnapFraction = mMotionHelper.animateToExpandedState(expandedBounds,
mMovementBounds, mExpandedMovementBounds, callback);
@@ -832,7 +825,7 @@ public class PipTouchHandler {
}
if (mDeferResizeToNormalBoundsUntilRotation == -1) {
Rect restoreBounds = new Rect(mResizedBounds);
Rect restoreBounds = new Rect(getUserResizeBounds());
Rect restoredMovementBounds = new Rect();
mSnapAlgorithm.getMovementBounds(restoreBounds, mInsetBounds,
restoredMovementBounds, mIsImeShowing ? mImeHeight : 0);
@@ -885,6 +878,10 @@ public class PipTouchHandler {
return mNormalBounds;
}
Rect getUserResizeBounds() {
return mPipResizeGestureHandler.getUserResizeBounds();
}
/**
* Gesture controlling normal movement of the PIP.
*/