diff options
5 files changed, 121 insertions, 77 deletions
diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java index 78f7e25ee3fa..ce1139b4264d 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/PipBoundsState.java @@ -54,6 +54,11 @@ public final class PipBoundsState { private static final String TAG = PipBoundsState.class.getSimpleName(); private final @NonNull Rect mBounds = new Rect(); + private final @NonNull Rect mMovementBounds = new Rect(); + private final @NonNull Rect mNormalBounds = new Rect(); + private final @NonNull Rect mExpandedBounds = new Rect(); + private final @NonNull Rect mNormalMovementBounds = new Rect(); + private final @NonNull Rect mExpandedMovementBounds = new Rect(); private final Context mContext; private float mAspectRatio; private int mStashedState = STASH_TYPE_NONE; @@ -92,9 +97,7 @@ public final class PipBoundsState { .getDimensionPixelSize(R.dimen.pip_stash_offset); } - /** - * Set the current PIP bounds. - */ + /** Set the current PIP bounds. */ public void setBounds(@NonNull Rect bounds) { mBounds.set(bounds); } @@ -104,6 +107,53 @@ public final class PipBoundsState { return new Rect(mBounds); } + /** Returns the current movement bounds. */ + public Rect getMovementBounds() { + return mMovementBounds; + } + + /** Set the current normal PIP bounds. */ + public void setNormalBounds(@NonNull Rect bounds) { + mNormalBounds.set(bounds); + } + + /** Get the current normal PIP bounds. */ + @NonNull + public Rect getNormalBounds() { + return mNormalBounds; + } + + /** Set the expanded bounds of PIP. */ + public void setExpandedBounds(@NonNull Rect bounds) { + mExpandedBounds.set(bounds); + } + + /** Get the PIP expanded bounds. */ + @NonNull + public Rect getExpandedBounds() { + return mExpandedBounds; + } + + /** Set the normal movement bounds. */ + public void setNormalMovementBounds(Rect bounds) { + mNormalMovementBounds.set(bounds); + } + + /** Returns the normal movement bounds. */ + public Rect getNormalMovementBounds() { + return mNormalMovementBounds; + } + + /** Set the expanded movement bounds. */ + public void setExpandedMovementBounds(Rect bounds) { + mExpandedMovementBounds.set(bounds); + } + + /** Returns the expanded movement bounds. */ + public Rect getExpandedMovementBounds() { + return mExpandedMovementBounds; + } + /** * Dictate where PiP currently should be stashed, if at all. */ @@ -389,6 +439,11 @@ public final class PipBoundsState { final String innerPrefix = prefix + " "; pw.println(prefix + TAG); pw.println(innerPrefix + "mBounds=" + mBounds); + pw.println(innerPrefix + "mNormalBounds=" + mNormalBounds); + pw.println(innerPrefix + "mExpandedBounds=" + mExpandedBounds); + pw.println(innerPrefix + "mMovementBounds=" + mMovementBounds); + pw.println(innerPrefix + "mNormalMovementBounds=" + mNormalMovementBounds); + pw.println(innerPrefix + "mExpandedMovementBounds=" + mExpandedMovementBounds); pw.println(innerPrefix + "mLastPipComponentName=" + mLastPipComponentName); pw.println(innerPrefix + "mAspectRatio=" + mAspectRatio); pw.println(innerPrefix + "mDisplayInfo=" + mDisplayInfo); diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java index 1f67d2c748e0..598b5d9b5d30 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipController.java @@ -87,7 +87,6 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac private final DisplayInfo mTmpDisplayInfo = new DisplayInfo(); private final Rect mTmpInsetBounds = new Rect(); - private final Rect mTmpNormalBounds = new Rect(); protected final Rect mReentryBounds = new Rect(); private boolean mIsInFixedRotation; @@ -114,12 +113,12 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac // TODO: Technically this should account for movement animation bounds as well Rect currentBounds = mPipTaskOrganizer.getCurrentOrAnimatingBounds(); final boolean changed = onDisplayRotationChanged(mContext, - mTmpNormalBounds, currentBounds, mTmpInsetBounds, displayId, fromRotation, - toRotation, t); + mPipBoundsState.getNormalBounds(), currentBounds, mTmpInsetBounds, displayId, + fromRotation, toRotation, t); if (changed) { // If the pip was in the offset zone earlier, adjust the new bounds to the bottom of the // movement bounds - mTouchHandler.adjustBoundsForRotation(mTmpNormalBounds, + mTouchHandler.adjustBoundsForRotation(mPipBoundsState.getNormalBounds(), mPipBoundsState.getBounds(), mTmpInsetBounds); // The bounds are being applied to a specific snap fraction, so reset any known offsets @@ -134,7 +133,7 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac mTouchHandler.onImeVisibilityChanged(false, 0); } - updateMovementBounds(mTmpNormalBounds, true /* fromRotation */, + updateMovementBounds(mPipBoundsState.getNormalBounds(), true /* fromRotation */, false /* fromImeAdjustment */, false /* fromShelfAdjustment */, t); } }; @@ -511,7 +510,7 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac mTmpDisplayInfo.copyFrom(mPipBoundsState.getDisplayInfo()); mPipBoundsAlgorithm.getInsetBounds(mTmpInsetBounds); - mTmpNormalBounds.set(mPipBoundsAlgorithm.getNormalBounds()); + mPipBoundsState.setNormalBounds(mPipBoundsAlgorithm.getNormalBounds()); if (outBounds.isEmpty()) { outBounds.set(mPipBoundsAlgorithm.getDefaultBounds()); } @@ -519,7 +518,7 @@ public class PipController implements Pip, PipTaskOrganizer.PipTransitionCallbac // mTouchHandler would rely on the bounds populated from mPipTaskOrganizer mPipTaskOrganizer.onMovementBoundsChanged(outBounds, fromRotation, fromImeAdjustment, fromShelfAdjustment, wct); - mTouchHandler.onMovementBoundsChanged(mTmpInsetBounds, mTmpNormalBounds, + mTouchHandler.onMovementBoundsChanged(mTmpInsetBounds, mPipBoundsState.getNormalBounds(), outBounds, fromImeAdjustment, fromShelfAdjustment, mTmpDisplayInfo.rotation); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java index d7b56ae74b38..e4e1211f9fa9 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipMotionHelper.java @@ -75,9 +75,6 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, private final Handler mMainHandler = new Handler(Looper.getMainLooper()); - /** The bounds within which PIP's top-left coordinate is allowed to move. */ - private final Rect mMovementBounds = new Rect(); - /** The region that all of PIP must stay within. */ private final Rect mFloatingAllowedArea = new Rect(); @@ -339,13 +336,12 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, } /** Sets the movement bounds to use to constrain PIP position animations. */ - void setCurrentMovementBounds(Rect movementBounds) { - mMovementBounds.set(movementBounds); + void onMovementBoundsChanged() { rebuildFlingConfigs(); // The movement bounds represent the area within which we can move PIP's top-left position. // The allowed area for all of PIP is those bounds plus PIP's width and height. - mFloatingAllowedArea.set(mMovementBounds); + mFloatingAllowedArea.set(mPipBoundsState.getMovementBounds()); mFloatingAllowedArea.right += getBounds().width(); mFloatingAllowedArea.bottom += getBounds().height(); } @@ -395,10 +391,10 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, final float leftEdge = isStash ? mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width() - : mMovementBounds.left; + : mPipBoundsState.getMovementBounds().left; final float rightEdge = isStash ? mPipBoundsState.getDisplayBounds().right - mPipBoundsState.getStashOffset() - : mMovementBounds.right; + : mPipBoundsState.getMovementBounds().right; final float xEndValue = velocityX < 0 ? leftEdge : rightEdge; @@ -433,7 +429,7 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, // Animate off the bottom of the screen, then dismiss PIP. mTemporaryBoundsPhysicsAnimator .spring(FloatProperties.RECT_Y, - mMovementBounds.bottom + getBounds().height() * 2, + mPipBoundsState.getMovementBounds().bottom + getBounds().height() * 2, 0, mSpringConfig) .withEndActions(this::dismissPip); @@ -504,10 +500,12 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, /** Set new fling configs whose min/max values respect the given movement bounds. */ private void rebuildFlingConfigs() { - mFlingConfigX = new PhysicsAnimator.FlingConfig( - DEFAULT_FRICTION, mMovementBounds.left, mMovementBounds.right); - mFlingConfigY = new PhysicsAnimator.FlingConfig( - DEFAULT_FRICTION, mMovementBounds.top, mMovementBounds.bottom); + mFlingConfigX = new PhysicsAnimator.FlingConfig(DEFAULT_FRICTION, + mPipBoundsState.getMovementBounds().left, + mPipBoundsState.getMovementBounds().right); + mFlingConfigY = new PhysicsAnimator.FlingConfig(DEFAULT_FRICTION, + mPipBoundsState.getMovementBounds().top, + mPipBoundsState.getMovementBounds().bottom); mStashConfigX = new PhysicsAnimator.FlingConfig( DEFAULT_FRICTION, mPipBoundsState.getStashOffset() - mPipBoundsState.getBounds().width(), diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java index 4cc41d9a8f1c..609fa3509e67 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipTouchHandler.java @@ -88,16 +88,8 @@ public class PipTouchHandler { */ private boolean mEnableStash = true; - // The current movement bounds - private Rect mMovementBounds = new Rect(); - // The reference inset bounds, used to determine the dismiss fraction private Rect mInsetBounds = new Rect(); - // The reference bounds used to calculate the normal/expanded target bounds - private Rect mNormalBounds = new Rect(); - @VisibleForTesting public Rect mNormalMovementBounds = new Rect(); - private Rect mExpandedBounds = new Rect(); - @VisibleForTesting public Rect mExpandedMovementBounds = new Rect(); private int mExpandedShortestEdgeSize; // Used to workaround an issue where the WM rotation happens before we are notified, allowing @@ -316,7 +308,8 @@ public class PipTouchHandler { final Rect toMovementBounds = new Rect(); mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(outBounds, insetBounds, toMovementBounds, 0); - final int prevBottom = mMovementBounds.bottom - mMovementBoundsExtraOffsets; + final int prevBottom = mPipBoundsState.getMovementBounds().bottom + - mMovementBoundsExtraOffsets; if ((prevBottom - mBottomOffsetBufferPx) <= curBounds.top) { outBounds.offsetTo(outBounds.left, toMovementBounds.bottom); } @@ -344,16 +337,15 @@ public class PipTouchHandler { } // Re-calculate the expanded bounds - mNormalBounds.set(normalBounds); Rect normalMovementBounds = new Rect(); - mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(mNormalBounds, insetBounds, + mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(normalBounds, insetBounds, normalMovementBounds, bottomOffset); - if (mMovementBounds.isEmpty()) { + if (mPipBoundsState.getMovementBounds().isEmpty()) { // mMovementBounds is not initialized yet and a clean movement bounds without // bottom offset shall be used later in this function. mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(curBounds, insetBounds, - mMovementBounds, 0 /* bottomOffset */); + mPipBoundsState.getMovementBounds(), 0 /* bottomOffset */); } // Calculate the expanded size @@ -362,13 +354,16 @@ public class PipTouchHandler { mContext.getDisplay().getRealSize(displaySize); Size expandedSize = mPipBoundsAlgorithm.getSnapAlgorithm().getSizeForAspectRatio( aspectRatio, mExpandedShortestEdgeSize, displaySize.x, displaySize.y); - mExpandedBounds.set(0, 0, expandedSize.getWidth(), expandedSize.getHeight()); + mPipBoundsState.setExpandedBounds( + new Rect(0, 0, expandedSize.getWidth(), expandedSize.getHeight())); Rect expandedMovementBounds = new Rect(); - mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(mExpandedBounds, insetBounds, - expandedMovementBounds, bottomOffset); + mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds( + mPipBoundsState.getExpandedBounds(), insetBounds, expandedMovementBounds, + bottomOffset); - mPipResizeGestureHandler.updateMinSize(mNormalBounds.width(), mNormalBounds.height()); - mPipResizeGestureHandler.updateMaxSize(mExpandedBounds.width(), mExpandedBounds.height()); + mPipResizeGestureHandler.updateMinSize(normalBounds.width(), normalBounds.height()); + mPipResizeGestureHandler.updateMaxSize(mPipBoundsState.getExpandedBounds().width(), + mPipBoundsState.getExpandedBounds().height()); // The extra offset does not really affect the movement bounds, but are applied based on the // current state (ime showing, or shelf offset) when we need to actually shift @@ -387,7 +382,8 @@ public class PipTouchHandler { final Rect toMovementBounds = new Rect(); mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(curBounds, insetBounds, toMovementBounds, mIsImeShowing ? mImeHeight : 0); - final int prevBottom = mMovementBounds.bottom - mMovementBoundsExtraOffsets; + final int prevBottom = mPipBoundsState.getMovementBounds().bottom + - mMovementBoundsExtraOffsets; // This is to handle landscape fullscreen IMEs, don't apply the extra offset in this // case final int toBottom = toMovementBounds.bottom < toMovementBounds.top @@ -395,7 +391,7 @@ public class PipTouchHandler { : toMovementBounds.bottom - extraOffset; if (isExpanded) { - curBounds.set(mExpandedBounds); + curBounds.set(mPipBoundsState.getExpandedBounds()); mPipBoundsAlgorithm.getSnapAlgorithm().applySnapFraction(curBounds, toMovementBounds, mSavedSnapFraction); } @@ -416,19 +412,21 @@ public class PipTouchHandler { // Update the movement bounds after doing the calculations based on the old movement bounds // above - mNormalMovementBounds.set(normalMovementBounds); - mExpandedMovementBounds.set(expandedMovementBounds); + mPipBoundsState.setNormalMovementBounds(normalMovementBounds); + mPipBoundsState.setExpandedMovementBounds(expandedMovementBounds); mDisplayRotation = displayRotation; mInsetBounds.set(insetBounds); updateMovementBounds(); mMovementBoundsExtraOffsets = extraOffset; - mConnection.onMovementBoundsChanged(mNormalBounds, mExpandedBounds, mNormalMovementBounds, - mExpandedMovementBounds); + mConnection.onMovementBoundsChanged(normalBounds, mPipBoundsState.getExpandedBounds(), + mPipBoundsState.getNormalMovementBounds(), + mPipBoundsState.getExpandedMovementBounds()); // If we have a deferred resize, apply it now if (mDeferResizeToNormalBoundsUntilRotation == displayRotation) { mMotionHelper.animateToUnexpandedState(normalBounds, mSavedSnapFraction, - mNormalMovementBounds, mMovementBounds, true /* immediate */); + mPipBoundsState.getNormalMovementBounds(), mPipBoundsState.getMovementBounds(), + true /* immediate */); mSavedSnapFraction = -1f; mDeferResizeToNormalBoundsUntilRotation = -1; } @@ -652,9 +650,10 @@ public class PipTouchHandler { } private void animateToExpandedState(Runnable callback) { - Rect expandedBounds = new Rect(mExpandedBounds); + Rect expandedBounds = new Rect(mPipBoundsState.getExpandedBounds()); mSavedSnapFraction = mMotionHelper.animateToExpandedState(expandedBounds, - mMovementBounds, mExpandedMovementBounds, callback); + mPipBoundsState.getMovementBounds(), mPipBoundsState.getExpandedMovementBounds(), + callback); } private void animateToUnexpandedState(Rect restoreBounds) { @@ -662,7 +661,7 @@ public class PipTouchHandler { mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(restoreBounds, mInsetBounds, restoredMovementBounds, mIsImeShowing ? mImeHeight : 0); mMotionHelper.animateToUnexpandedState(restoreBounds, mSavedSnapFraction, - restoredMovementBounds, mMovementBounds, false /* immediate */); + restoredMovementBounds, mPipBoundsState.getMovementBounds(), false /* immediate */); mSavedSnapFraction = -1f; } @@ -688,13 +687,6 @@ public class PipTouchHandler { mMotionHelper = pipMotionHelper; } - /** - * @return the unexpanded bounds. - */ - public Rect getNormalBounds() { - return mNormalBounds; - } - Rect getUserResizeBounds() { return mPipResizeGestureHandler.getUserResizeBounds(); } @@ -717,7 +709,8 @@ public class PipTouchHandler { Rect bounds = getPossiblyAnimatingBounds(); mDelta.set(0f, 0f); mStartPosition.set(bounds.left, bounds.top); - mMovementWithinDismiss = touchState.getDownTouchPosition().y >= mMovementBounds.bottom; + mMovementWithinDismiss = touchState.getDownTouchPosition().y + >= mPipBoundsState.getMovementBounds().bottom; mMotionHelper.setSpringingToTouch(false); mDownSavedFraction = mPipBoundsAlgorithm.getSnapFraction(mPipBoundsState.getBounds()); @@ -759,7 +752,7 @@ public class PipTouchHandler { final PointF curPos = touchState.getLastTouchPosition(); if (mMovementWithinDismiss) { // Track if movement remains near the bottom edge to identify swipe to dismiss - mMovementWithinDismiss = curPos.y >= mMovementBounds.bottom; + mMovementWithinDismiss = curPos.y >= mPipBoundsState.getMovementBounds().bottom; } return true; } @@ -804,15 +797,17 @@ public class PipTouchHandler { } else if (mTouchState.isDoubleTap() && !mPipBoundsState.isStashed()) { // 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); + final boolean toExpand = mMotionHelper.getBounds().width() + < mPipBoundsState.getExpandedBounds().width() + && mMotionHelper.getBounds().height() + < mPipBoundsState.getExpandedBounds().height(); + mPipResizeGestureHandler.setUserResizeBounds(toExpand + ? mPipBoundsState.getExpandedBounds() + : mPipBoundsState.getNormalBounds()); if (toExpand) { animateToExpandedState(null); } else { - animateToUnexpandedState(mNormalBounds); + animateToUnexpandedState(mPipBoundsState.getNormalBounds()); } } else { // Expand to fullscreen if this is a double tap @@ -870,8 +865,8 @@ public class PipTouchHandler { */ private void updateMovementBounds() { mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(mMotionHelper.getBounds(), - mInsetBounds, mMovementBounds, mIsImeShowing ? mImeHeight : 0); - mMotionHelper.setCurrentMovementBounds(mMovementBounds); + mInsetBounds, mPipBoundsState.getMovementBounds(), mIsImeShowing ? mImeHeight : 0); + mMotionHelper.onMovementBoundsChanged(); boolean isMenuExpanded = mMenuState == MENU_STATE_FULL; mPipBoundsState.setMinEdgeSize( @@ -893,8 +888,10 @@ public class PipTouchHandler { if (!mEnableResize) { return false; } - return mExpandedBounds.width() != mNormalBounds.width() - || mExpandedBounds.height() != mNormalBounds.height(); + return mPipBoundsState.getExpandedBounds().width() + != mPipBoundsState.getNormalBounds().width() + || mPipBoundsState.getExpandedBounds().height() + != mPipBoundsState.getNormalBounds().height(); } /** @@ -910,11 +907,6 @@ public class PipTouchHandler { public void dump(PrintWriter pw, String prefix) { final String innerPrefix = prefix + " "; pw.println(prefix + TAG); - pw.println(innerPrefix + "mMovementBounds=" + mMovementBounds); - pw.println(innerPrefix + "mNormalBounds=" + mNormalBounds); - pw.println(innerPrefix + "mNormalMovementBounds=" + mNormalMovementBounds); - pw.println(innerPrefix + "mExpandedBounds=" + mExpandedBounds); - pw.println(innerPrefix + "mExpandedMovementBounds=" + mExpandedMovementBounds); pw.println(innerPrefix + "mMenuState=" + mMenuState); pw.println(innerPrefix + "mIsImeShowing=" + mIsImeShowing); pw.println(innerPrefix + "mImeHeight=" + mImeHeight); diff --git a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java index ec02331d9870..b25c74d12818 100644 --- a/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java +++ b/libs/WindowManager/Shell/tests/unittest/src/com/android/wm/shell/pip/phone/PipTouchHandlerTest.java @@ -120,7 +120,7 @@ public class PipTouchHandlerTest extends ShellTestCase { mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds, mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation); - assertEquals(expectedMinMovementBounds, mPipTouchHandler.mNormalMovementBounds); + assertEquals(expectedMinMovementBounds, mPipBoundsState.getNormalMovementBounds()); verify(mPipResizeGestureHandler, times(1)) .updateMinSize(mMinBounds.width(), mMinBounds.height()); } @@ -139,7 +139,7 @@ public class PipTouchHandlerTest extends ShellTestCase { mPipTouchHandler.onMovementBoundsChanged(mInsetBounds, mMinBounds, mCurBounds, mFromImeAdjustment, mFromShelfAdjustment, mDisplayRotation); - assertEquals(expectedMaxMovementBounds, mPipTouchHandler.mExpandedMovementBounds); + assertEquals(expectedMaxMovementBounds, mPipBoundsState.getExpandedMovementBounds()); verify(mPipResizeGestureHandler, times(1)) .updateMaxSize(maxBounds.width(), maxBounds.height()); } |