From dddafae44e59c1af25b9dc54ca1bebf2dab3323b Mon Sep 17 00:00:00 2001 From: Uwais Ashraf Date: Tue, 27 Feb 2024 11:04:40 +0000 Subject: [PATCH] Fix bouncing of task view when dragged past dismiss threshold. Before: https://screenshot.googleplex.com/56AHSMFkNwC76BV After: https://screenshot.googleplex.com/AjuWqZaSNxmNYn8 Other cases after: https://screenshot.googleplex.com/oaNotdg79v7LGUA https://screenshot.googleplex.com/8SVtzpokbvmAzpv https://screenshot.googleplex.com/87uRqmEAasBMQz2 Fix: 319577620 Flag: NA Test: Manual (animation), analyse setPlayFraction log - see screenshots Change-Id: Ib1f24182b8fc0f6ea1ff07125f25dbfc206ae5c2 --- .../TaskViewTouchController.java | 23 +++++++++++-------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java index ef5096b219..e9f2d4f019 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java @@ -21,7 +21,6 @@ import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_BOTH import android.animation.Animator; import android.animation.AnimatorListenerAdapter; -import android.os.SystemClock; import android.os.VibrationEffect; import android.view.MotionEvent; import android.view.View; @@ -80,6 +79,7 @@ public abstract class TaskViewTouchController private float mDisplacementShift; private float mProgressMultiplier; private float mEndDisplacement; + private boolean mDraggingEnabled = true; private FlingBlockCheck mFlingBlockCheck = new FlingBlockCheck(); private Float mOverrideVelocity = null; @@ -270,6 +270,8 @@ public abstract class TaskViewTouchController @Override public void onDragStart(boolean start, float startDisplacement) { + if (!mDraggingEnabled) return; + RecentsPagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler(); if (mCurrentAnimation == null) { @@ -285,6 +287,8 @@ public abstract class TaskViewTouchController @Override public boolean onDrag(float displacement) { + if (!mDraggingEnabled) return true; + RecentsPagedOrientationHandler orientationHandler = mRecentsView.getPagedOrientationHandler(); float totalDisplacement = displacement + mDisplacementShift; @@ -317,12 +321,9 @@ public abstract class TaskViewTouchController mOverrideVelocity = -mTaskBeingDragged.getResources().getDimension(velocityDimenId); // Once halfway through task dismissal interpolation, switch from reversible - // dragging-task animation to playing the remaining task translation animations - final long now = SystemClock.uptimeMillis(); - MotionEvent upAction = MotionEvent.obtain(now, now, - MotionEvent.ACTION_UP, 0.0f, 0.0f, 0); - mDetector.onTouchEvent(upAction); - upAction.recycle(); + // dragging-task animation to playing the remaining task translation animations, + // while this is in progress disable dragging. + mDraggingEnabled = false; } } else { mCurrentAnimation.setPlayFraction( @@ -343,7 +344,7 @@ public abstract class TaskViewTouchController R.dimen.max_task_dismiss_drag_velocity); velocity = Utilities.boundToRange(velocity, -maxTaskDismissDragVelocity, maxTaskDismissDragVelocity); - boolean fling = mDetector.isFling(velocity); + boolean fling = mDraggingEnabled && mDetector.isFling(velocity); final boolean goingToEnd; boolean blockedFling = fling && mFlingBlockCheck.isBlocked(); if (blockedFling) { @@ -371,19 +372,21 @@ public abstract class TaskViewTouchController MIN_TASK_DISMISS_ANIMATION_DURATION, MAX_TASK_DISMISS_ANIMATION_DURATION); mCurrentAnimation.setEndAction(this::clearState); - mCurrentAnimation.startWithVelocity(mActivity, goingToEnd, - velocity * orientationHandler.getSecondaryTranslationDirectionFactor(), + mCurrentAnimation.startWithVelocity(mActivity, goingToEnd, Math.abs(velocity), mEndDisplacement, animationDuration); if (goingUp && goingToEnd && !mIsDismissHapticRunning) { VibratorWrapper.INSTANCE.get(mActivity).vibrate(TASK_DISMISS_VIBRATION_PRIMITIVE, TASK_DISMISS_VIBRATION_PRIMITIVE_SCALE, TASK_DISMISS_VIBRATION_FALLBACK); mIsDismissHapticRunning = true; } + + mDraggingEnabled = true; } private void clearState() { mDetector.finishedScrolling(); mDetector.setDetectableScrollConditions(0, false); + mDraggingEnabled = true; mTaskBeingDragged = null; mCurrentAnimation = null; mIsDismissHapticRunning = false;