Move movement bounds into PipBoundsState
Bug: 169373982 Test: com.android.wm.shell.pip Change-Id: I423219e9093f52edbd84ef52b928219679e187bc
This commit is contained in:
@@ -54,8 +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;
|
||||
@@ -104,6 +107,11 @@ 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);
|
||||
@@ -126,6 +134,26 @@ public final class PipBoundsState {
|
||||
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.
|
||||
*/
|
||||
@@ -413,6 +441,9 @@ public final class PipBoundsState {
|
||||
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);
|
||||
|
||||
@@ -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(),
|
||||
|
||||
@@ -89,13 +89,8 @@ public class PipTouchHandler {
|
||||
*/
|
||||
private boolean mEnableStash = false;
|
||||
|
||||
// The current movement bounds
|
||||
private Rect mMovementBounds = new Rect();
|
||||
|
||||
// The reference inset bounds, used to determine the dismiss fraction
|
||||
private Rect mInsetBounds = new Rect();
|
||||
@VisibleForTesting public Rect mNormalMovementBounds = 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
|
||||
@@ -314,7 +309,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);
|
||||
}
|
||||
@@ -346,11 +342,11 @@ public class PipTouchHandler {
|
||||
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
|
||||
@@ -387,7 +383,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
|
||||
@@ -416,19 +413,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(normalBounds, mPipBoundsState.getExpandedBounds(),
|
||||
mNormalMovementBounds, mExpandedMovementBounds);
|
||||
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;
|
||||
}
|
||||
@@ -654,7 +653,8 @@ public class PipTouchHandler {
|
||||
private void animateToExpandedState(Runnable callback) {
|
||||
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 +662,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;
|
||||
}
|
||||
|
||||
@@ -710,7 +710,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());
|
||||
|
||||
@@ -752,7 +753,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;
|
||||
}
|
||||
@@ -865,8 +866,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(
|
||||
@@ -907,9 +908,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 + "mNormalMovementBounds=" + mNormalMovementBounds);
|
||||
pw.println(innerPrefix + "mExpandedMovementBounds=" + mExpandedMovementBounds);
|
||||
pw.println(innerPrefix + "mMenuState=" + mMenuState);
|
||||
pw.println(innerPrefix + "mIsImeShowing=" + mIsImeShowing);
|
||||
pw.println(innerPrefix + "mImeHeight=" + mImeHeight);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user