From b54b65b001dadbc6fef790700819c33c99772333 Mon Sep 17 00:00:00 2001 From: Winson Chung Date: Wed, 26 Apr 2017 14:02:13 -0700 Subject: [PATCH] Fixing issue with lingering dismiss PiP overlay. - Always try and remove the dismiss overlay when animating touch ends, or if the input consumer is unregistered to handle cases where the interaction is interrupted by the pip animation. Bug: 37309693 Test: Intermittent, enter pip and try to tap and then tap-drag the PIP Change-Id: I05f360f1d9d264590725e13eb2cc9254a3f21eef --- .../systemui/pip/phone/PipTouchHandler.java | 50 ++++++++++++------- 1 file changed, 33 insertions(+), 17 deletions(-) diff --git a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java index f586ec6c552e2..9c7e3986f8773 100644 --- a/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java +++ b/packages/SystemUI/src/com/android/systemui/pip/phone/PipTouchHandler.java @@ -225,7 +225,7 @@ public class PipTouchHandler implements TunerService.Tunable { if (mIsMinimized) { setMinimizedStateInternal(false); } - mDismissViewController.destroyDismissTarget(); + cleanUpDismissTarget(); mShowPipMenuOnAnimationEnd = true; } @@ -334,6 +334,12 @@ public class PipTouchHandler implements TunerService.Tunable { mAccessibilityManager.setPictureInPictureActionReplacingConnection(isRegistered ? new PipAccessibilityInteractionConnection(mMotionHelper, this::onAccessibilityShowMenu, mHandler) : null); + + if (!isRegistered && mTouchState.isUserInteracting()) { + // If the input consumer is unregistered while the user is interacting, then we may not + // get the final TOUCH_UP event, so clean up the dismiss target as well + cleanUpDismissTarget(); + } } private void onAccessibilityShowMenu() { @@ -578,11 +584,11 @@ public class PipTouchHandler implements TunerService.Tunable { if (touchState.startedDragging()) { mSavedSnapFraction = -1f; - } - if (touchState.startedDragging() && ENABLE_DISMISS_DRAG_TO_EDGE) { - mHandler.removeCallbacks(mShowDismissAffordance); - mDismissViewController.showDismissTarget(); + if (ENABLE_DISMISS_DRAG_TO_EDGE) { + mHandler.removeCallbacks(mShowDismissAffordance); + mDismissViewController.showDismissTarget(); + } } if (touchState.isDragging()) { @@ -625,6 +631,12 @@ public class PipTouchHandler implements TunerService.Tunable { @Override public boolean onUp(PipTouchState touchState) { + if (ENABLE_DISMISS_DRAG_TO_EDGE) { + // Clean up the dismiss target regardless of the touch state in case the touch + // enabled state changes while the user is interacting + cleanUpDismissTarget(); + } + if (!touchState.isUserInteracting()) { return false; } @@ -640,18 +652,14 @@ public class PipTouchHandler implements TunerService.Tunable { final boolean isFlingToBot = isFling && vel.y > 0 && !isHorizontal && (mMovementWithinDismiss || isUpWithinDimiss); if (ENABLE_DISMISS_DRAG_TO_EDGE) { - try { - mHandler.removeCallbacks(mShowDismissAffordance); - if (mMotionHelper.shouldDismissPip() || isFlingToBot) { - mMotionHelper.animateDismiss(mMotionHelper.getBounds(), vel.x, - vel.y, mUpdateScrimListener); - MetricsLogger.action(mContext, - MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED, - METRIC_VALUE_DISMISSED_BY_DRAG); - return true; - } - } finally { - mDismissViewController.destroyDismissTarget(); + // Check if the user dragged or flung the PiP offscreen to dismiss it + if (mMotionHelper.shouldDismissPip() || isFlingToBot) { + mMotionHelper.animateDismiss(mMotionHelper.getBounds(), vel.x, + vel.y, mUpdateScrimListener); + MetricsLogger.action(mContext, + MetricsEvent.ACTION_PICTURE_IN_PICTURE_DISMISSED, + METRIC_VALUE_DISMISSED_BY_DRAG); + return true; } } @@ -728,6 +736,14 @@ public class PipTouchHandler implements TunerService.Tunable { : mNormalMovementBounds; } + /** + * Removes the dismiss target and cancels any pending callbacks to show it. + */ + private void cleanUpDismissTarget() { + mHandler.removeCallbacks(mShowDismissAffordance); + mDismissViewController.destroyDismissTarget(); + } + public void dump(PrintWriter pw, String prefix) { final String innerPrefix = prefix + " "; pw.println(prefix + TAG);