From 5b9f045c23500e8a1a1872fa9874ce60ddd26a70 Mon Sep 17 00:00:00 2001 From: "jorgegil@google.com" Date: Thu, 12 Nov 2020 11:27:44 -0800 Subject: [PATCH] Use PipBoundsState to access current bounds Bug: 169373982 Test: com.android.wm.shell.pip Change-Id: I49e45d122444b80144c069224284f58c992ad16e --- ...PipAccessibilityInteractionConnection.java | 6 ++--- .../wm/shell/pip/phone/PipMotionHelper.java | 4 +-- .../pip/phone/PipResizeGestureHandler.java | 14 +++++----- .../wm/shell/pip/phone/PipTouchHandler.java | 27 ++++++++++--------- 4 files changed, 25 insertions(+), 26 deletions(-) diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java index 18b6922f30673..f153aa5a1beb8 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipAccessibilityInteractionConnection.java @@ -105,8 +105,8 @@ public class PipAccessibilityInteractionConnection // R constants are not final so this cannot be put in the switch-case. if (action == R.id.action_pip_resize) { - if (mMotionHelper.getBounds().width() == mNormalBounds.width() - && mMotionHelper.getBounds().height() == mNormalBounds.height()) { + if (mPipBoundsState.getBounds().width() == mNormalBounds.width() + && mPipBoundsState.getBounds().height() == mNormalBounds.height()) { setToExpandedBounds(); } else { setToNormalBounds(); @@ -130,7 +130,7 @@ public class PipAccessibilityInteractionConnection int newY = arguments.getInt( AccessibilityNodeInfo.ACTION_ARGUMENT_MOVE_WINDOW_Y); Rect pipBounds = new Rect(); - pipBounds.set(mMotionHelper.getBounds()); + pipBounds.set(mPipBoundsState.getBounds()); mTmpBounds.offsetTo(newX, newY); mMotionHelper.movePip(mTmpBounds); result = true; 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 e4e1211f9fa94..8fa944886905e 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 @@ -348,10 +348,8 @@ public class PipMotionHelper implements PipAppOpsListener.Callback, /** * @return the PiP bounds. - * - * TODO(b/169373982): can be private, outside callers can use PipBoundsState directly. */ - Rect getBounds() { + private Rect getBounds() { return mPipBoundsState.getBounds(); } diff --git a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java index 4849e0ddb6f7d..e5a49c430d828 100644 --- a/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java +++ b/libs/WindowManager/Shell/src/com/android/wm/shell/pip/phone/PipResizeGestureHandler.java @@ -296,7 +296,7 @@ public class PipResizeGestureHandler { * |_|_| |_|_| */ public boolean isWithinTouchRegion(int x, int y) { - final Rect currentPipBounds = mMotionHelper.getBounds(); + final Rect currentPipBounds = mPipBoundsState.getBounds(); if (currentPipBounds == null) { return false; } @@ -349,8 +349,8 @@ public class PipResizeGestureHandler { } private void setCtrlTypeForPinchToZoom() { - final Rect currentPipBounds = mMotionHelper.getBounds(); - mLastDownBounds.set(mMotionHelper.getBounds()); + final Rect currentPipBounds = mPipBoundsState.getBounds(); + mLastDownBounds.set(mPipBoundsState.getBounds()); Rect movementBounds = mMovementBoundsSupplier.apply(currentPipBounds); mDisplayBounds.set(movementBounds.left, @@ -372,7 +372,7 @@ public class PipResizeGestureHandler { } private void setCtrlType(int x, int y) { - final Rect currentPipBounds = mMotionHelper.getBounds(); + final Rect currentPipBounds = mPipBoundsState.getBounds(); Rect movementBounds = mMovementBoundsSupplier.apply(currentPipBounds); mDisplayBounds.set(movementBounds.left, @@ -413,13 +413,13 @@ public class PipResizeGestureHandler { float x = ev.getX(); float y = ev.getY(); if (action == MotionEvent.ACTION_DOWN) { - final Rect currentPipBounds = mMotionHelper.getBounds(); + final Rect currentPipBounds = mPipBoundsState.getBounds(); mLastResizeBounds.setEmpty(); mAllowGesture = isInValidSysUiState() && isWithinTouchRegion((int) x, (int) y); if (mAllowGesture) { setCtrlType((int) x, (int) y); mDownPoint.set(x, y); - mLastDownBounds.set(mMotionHelper.getBounds()); + mLastDownBounds.set(mPipBoundsState.getBounds()); } if (!currentPipBounds.contains((int) ev.getX(), (int) ev.getY()) && mPipMenuActivityController.isMenuVisible()) { @@ -446,7 +446,7 @@ public class PipResizeGestureHandler { mPipMenuActivityController.hideMenuWithoutResize(); mPipMenuActivityController.hideMenu(); } - final Rect currentPipBounds = mMotionHelper.getBounds(); + final Rect currentPipBounds = mPipBoundsState.getBounds(); mLastResizeBounds.set(TaskResizingAlgorithm.resizeDrag(x, y, mDownPoint.x, mDownPoint.y, currentPipBounds, mCtrlType, mMinSize.x, mMinSize.y, mMaxSize, true, 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 1853822f45c73..e5212bdf95fe7 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 @@ -146,7 +146,7 @@ public class PipTouchHandler { @Override public void onPipShowMenu() { - mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), + mMenuController.showMenu(MENU_STATE_FULL, mPipBoundsState.getBounds(), true /* allowMenuTimeout */, willResizeMenu(), shouldShowResizeHandle()); } } @@ -177,8 +177,9 @@ public class PipTouchHandler { mPipDismissTargetHandler = new PipDismissTargetHandler(context, pipUiEventLogger, mMotionHelper, mHandler); mTouchState = new PipTouchState(ViewConfiguration.get(context), mHandler, - () -> mMenuController.showMenuWithDelay(MENU_STATE_FULL, mMotionHelper.getBounds(), - true /* allowMenuTimeout */, willResizeMenu(), shouldShowResizeHandle()), + () -> mMenuController.showMenuWithDelay(MENU_STATE_FULL, + mPipBoundsState.getBounds(), true /* allowMenuTimeout */, willResizeMenu(), + shouldShowResizeHandle()), menuController::hideMenu); Resources res = context.getResources(); @@ -230,7 +231,7 @@ public class PipTouchHandler { public void showPictureInPictureMenu() { // Only show the menu if the user isn't currently interacting with the PiP if (!mTouchState.isUserInteracting()) { - mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), + mMenuController.showMenu(MENU_STATE_FULL, mPipBoundsState.getBounds(), false /* allowMenuTimeout */, willResizeMenu(), shouldShowResizeHandle()); } @@ -266,11 +267,11 @@ public class PipTouchHandler { updateMovementBounds(); if (direction == TRANSITION_DIRECTION_TO_PIP) { // Set the initial bounds as the user resize bounds. - mPipResizeGestureHandler.setUserResizeBounds(mMotionHelper.getBounds()); + mPipResizeGestureHandler.setUserResizeBounds(mPipBoundsState.getBounds()); } if (mShowPipMenuOnAnimationEnd) { - mMenuController.showMenu(MENU_STATE_CLOSE, mMotionHelper.getBounds(), + mMenuController.showMenu(MENU_STATE_CLOSE, mPipBoundsState.getBounds(), true /* allowMenuTimeout */, false /* willResizeMenu */, shouldShowResizeHandle()); mShowPipMenuOnAnimationEnd = false; @@ -447,7 +448,7 @@ public class PipTouchHandler { } private void onAccessibilityShowMenu() { - mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), + mMenuController.showMenu(MENU_STATE_FULL, mPipBoundsState.getBounds(), true /* allowMenuTimeout */, willResizeMenu(), shouldShowResizeHandle()); } @@ -530,7 +531,7 @@ public class PipTouchHandler { // Let's not enable menu show/hide for a11y services. if (!mAccessibilityManager.isTouchExplorationEnabled()) { mTouchState.removeHoverExitTimeoutCallback(); - mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), + mMenuController.showMenu(MENU_STATE_FULL, mPipBoundsState.getBounds(), false /* allowMenuTimeout */, false /* willResizeMenu */, shouldShowResizeHandle()); } @@ -774,7 +775,7 @@ public class PipTouchHandler { if (mMenuState != MENU_STATE_NONE) { // If the menu is still visible, then just poke the menu so that // it will timeout after the user stops touching it - mMenuController.showMenu(mMenuState, mMotionHelper.getBounds(), + mMenuController.showMenu(mMenuState, mPipBoundsState.getBounds(), true /* allowMenuTimeout */, willResizeMenu(), shouldShowResizeHandle()); } @@ -798,9 +799,9 @@ 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() + final boolean toExpand = mPipBoundsState.getBounds().width() < mPipBoundsState.getExpandedBounds().width() - && mMotionHelper.getBounds().height() + && mPipBoundsState.getBounds().height() < mPipBoundsState.getExpandedBounds().height(); mPipResizeGestureHandler.setUserResizeBounds(toExpand ? mPipBoundsState.getExpandedBounds() @@ -820,7 +821,7 @@ public class PipTouchHandler { if (!mTouchState.isWaitingForDoubleTap()) { // User has stalled long enough for this not to be a drag or a double tap, just // expand the menu - mMenuController.showMenu(MENU_STATE_FULL, mMotionHelper.getBounds(), + mMenuController.showMenu(MENU_STATE_FULL, mPipBoundsState.getBounds(), true /* allowMenuTimeout */, willResizeMenu(), shouldShowResizeHandle()); } else { @@ -865,7 +866,7 @@ public class PipTouchHandler { * resized. */ private void updateMovementBounds() { - mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(mMotionHelper.getBounds(), + mPipBoundsAlgorithm.getSnapAlgorithm().getMovementBounds(mPipBoundsState.getBounds(), mInsetBounds, mPipBoundsState.getMovementBounds(), mIsImeShowing ? mImeHeight : 0); mMotionHelper.onMovementBoundsChanged();