Move normal and expanded bounds into PipBoundsState

Bug; 169373982
Test: com.android.wm.shell.pip

Change-Id: Id5636cfc7c9cfa828dd51f1a79e2ba1ed3b79c42
This commit is contained in:
jorgegil@google.com
2020-11-10 13:19:13 -08:00
parent 67959b765d
commit 8dcbe0c9bf
3 changed files with 58 additions and 41 deletions

View File

@@ -54,6 +54,8 @@ public final class PipBoundsState {
private static final String TAG = PipBoundsState.class.getSimpleName();
private final @NonNull Rect mBounds = new Rect();
private final @NonNull Rect mNormalBounds = new Rect();
private final @NonNull Rect mExpandedBounds = new Rect();
private final Context mContext;
private float mAspectRatio;
private int mStashedState = STASH_TYPE_NONE;
@@ -92,9 +94,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 +104,28 @@ public final class PipBoundsState {
return new Rect(mBounds);
}
/** 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;
}
/**
* Dictate where PiP currently should be stashed, if at all.
*/
@@ -389,6 +411,8 @@ 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 + "mLastPipComponentName=" + mLastPipComponentName);
pw.println(innerPrefix + "mAspectRatio=" + mAspectRatio);
pw.println(innerPrefix + "mDisplayInfo=" + mDisplayInfo);

View File

@@ -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);
}

View File

@@ -94,10 +94,7 @@ public class PipTouchHandler {
// 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;
@@ -345,9 +342,8 @@ 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()) {
@@ -363,13 +359,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
@@ -396,7 +395,7 @@ public class PipTouchHandler {
: toMovementBounds.bottom - extraOffset;
if (isExpanded) {
curBounds.set(mExpandedBounds);
curBounds.set(mPipBoundsState.getExpandedBounds());
mPipBoundsAlgorithm.getSnapAlgorithm().applySnapFraction(curBounds,
toMovementBounds, mSavedSnapFraction);
}
@@ -423,8 +422,8 @@ public class PipTouchHandler {
mInsetBounds.set(insetBounds);
updateMovementBounds();
mMovementBoundsExtraOffsets = extraOffset;
mConnection.onMovementBoundsChanged(mNormalBounds, mExpandedBounds, mNormalMovementBounds,
mExpandedMovementBounds);
mConnection.onMovementBoundsChanged(normalBounds, mPipBoundsState.getExpandedBounds(),
mNormalMovementBounds, mExpandedMovementBounds);
// If we have a deferred resize, apply it now
if (mDeferResizeToNormalBoundsUntilRotation == displayRotation) {
@@ -653,7 +652,7 @@ 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);
}
@@ -689,13 +688,6 @@ public class PipTouchHandler {
mMotionHelper = pipMotionHelper;
}
/**
* @return the unexpanded bounds.
*/
public Rect getNormalBounds() {
return mNormalBounds;
}
Rect getUserResizeBounds() {
return mPipResizeGestureHandler.getUserResizeBounds();
}
@@ -805,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
@@ -894,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();
}
/**
@@ -912,9 +908,7 @@ public class PipTouchHandler {
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);