Merge "PiP: Change double-tap to expand/normal resize."

This commit is contained in:
Ben Lin
2020-09-24 18:04:42 +00:00
committed by Android (Google) Code Review
2 changed files with 39 additions and 14 deletions

View File

@@ -308,6 +308,10 @@ public class PipResizeGestureHandler {
return mTmpRegion.contains(x, y);
}
public boolean isUsingPinchToZoom() {
return mEnablePinchResize;
}
public boolean willStartResizeGesture(MotionEvent ev) {
if (isInValidSysUiState()) {
switch (ev.getActionMasked()) {

View File

@@ -831,9 +831,7 @@ public class PipTouchHandler {
// we store back to this snap fraction. Otherwise, we'll reset the snap
// fraction and snap to the closest edge.
if (resize) {
Rect expandedBounds = new Rect(mExpandedBounds);
mSavedSnapFraction = mMotionHelper.animateToExpandedState(expandedBounds,
mMovementBounds, mExpandedMovementBounds, callback);
animateToExpandedState(callback);
}
} else if (menuState == MENU_STATE_NONE && mMenuState == MENU_STATE_FULL) {
// Try and restore the PiP to the closest edge, using the saved snap fraction
@@ -859,13 +857,7 @@ public class PipTouchHandler {
}
if (mDeferResizeToNormalBoundsUntilRotation == -1) {
Rect restoreBounds = new Rect(getUserResizeBounds());
Rect restoredMovementBounds = new Rect();
mPipBoundsHandler.getSnapAlgorithm().getMovementBounds(restoreBounds,
mInsetBounds, restoredMovementBounds, mIsImeShowing ? mImeHeight : 0);
mMotionHelper.animateToUnexpandedState(restoreBounds, mSavedSnapFraction,
restoredMovementBounds, mMovementBounds, false /* immediate */);
mSavedSnapFraction = -1f;
animateToUnexpandedState(getUserResizeBounds());
}
} else {
mSavedSnapFraction = -1f;
@@ -883,6 +875,21 @@ public class PipTouchHandler {
}
}
private void animateToExpandedState(Runnable callback) {
Rect expandedBounds = new Rect(mExpandedBounds);
mSavedSnapFraction = mMotionHelper.animateToExpandedState(expandedBounds,
mMovementBounds, mExpandedMovementBounds, callback);
}
private void animateToUnexpandedState(Rect restoreBounds) {
Rect restoredMovementBounds = new Rect();
mPipBoundsHandler.getSnapAlgorithm().getMovementBounds(restoreBounds,
mInsetBounds, restoredMovementBounds, mIsImeShowing ? mImeHeight : 0);
mMotionHelper.animateToUnexpandedState(restoreBounds, mSavedSnapFraction,
restoredMovementBounds, mMovementBounds, false /* immediate */);
mSavedSnapFraction = -1f;
}
/**
* @return the motion helper.
*/
@@ -1025,10 +1032,24 @@ public class PipTouchHandler {
this::flingEndAction /* endAction */);
}
} else if (mTouchState.isDoubleTap()) {
// Expand to fullscreen if this is a double tap
// the PiP should be frozen until the transition ends
setTouchEnabled(false);
mMotionHelper.expandLeavePip();
// If using pinch to zoom, double-tap functions as resizing between max/min size
if (mPipResizeGestureHandler.isUsingPinchToZoom()) {
final boolean toExpand =
mMotionHelper.getBounds().width() < mExpandedBounds.width()
&& mMotionHelper.getBounds().height() < mExpandedBounds.height();
mPipResizeGestureHandler.setUserResizeBounds(toExpand ? mExpandedBounds
: mNormalBounds);
if (toExpand) {
animateToExpandedState(null);
} else {
animateToUnexpandedState(mNormalBounds);
}
} else {
// Expand to fullscreen if this is a double tap
// the PiP should be frozen until the transition ends
setTouchEnabled(false);
mMotionHelper.expandLeavePip();
}
} else if (mMenuState != MENU_STATE_FULL) {
if (!mTouchState.isWaitingForDoubleTap()) {
// User has stalled long enough for this not to be a drag or a double tap, just