From 49cb49b1f54de25d05f8c24e22ae7db5b79fb411 Mon Sep 17 00:00:00 2001 From: Pat Manning Date: Tue, 1 Jun 2021 14:49:22 +0000 Subject: [PATCH] End drag touch event when crossing task drag threshold, and only when task is going up (drag to dismiss) Test: manual Fix: 188618115 Bug: 188618115 Change-Id: I51d157e224eaeee34ed131e4945bb92d6baf18cd --- quickstep/res/values/dimens.xml | 5 +- .../TaskViewTouchController.java | 48 ++++++++++++++----- 2 files changed, 39 insertions(+), 14 deletions(-) diff --git a/quickstep/res/values/dimens.xml b/quickstep/res/values/dimens.xml index c85d3dcbdb..60eeaffbbb 100644 --- a/quickstep/res/values/dimens.xml +++ b/quickstep/res/values/dimens.xml @@ -45,8 +45,9 @@ 2.25dp - 1.75dp - 0.75dp + 1.5dp + 1dp + 5dp 16dp 70dp diff --git a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java index c6ea953aff..180af0bd9f 100644 --- a/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java +++ b/quickstep/src/com/android/launcher3/uioverrides/touchcontrollers/TaskViewTouchController.java @@ -21,6 +21,7 @@ import static com.android.launcher3.touch.SingleAxisSwipeDetector.DIRECTION_BOTH import android.animation.Animator; import android.animation.AnimatorListenerAdapter; +import android.os.SystemClock; import android.view.MotionEvent; import android.view.View; import android.view.animation.Interpolator; @@ -72,6 +73,7 @@ public abstract class TaskViewTouchController private float mProgressMultiplier; private float mEndDisplacement; private FlingBlockCheck mFlingBlockCheck = new FlingBlockCheck(); + private Float mOverrideVelocity = null; private TaskView mTaskBeingDragged; @@ -268,6 +270,7 @@ public abstract class TaskViewTouchController mCurrentAnimation.pause(); } mFlingBlockCheck.unblockFling(); + mOverrideVelocity = null; } @Override @@ -283,19 +286,36 @@ public abstract class TaskViewTouchController mFlingBlockCheck.onEvent(); } - // Once halfway through task dismissal interpolation, switch from reversible dragging-task - // animation to playing the remaining task translation animations - if (mCurrentAnimation.getProgressFraction() < ANIMATION_PROGRESS_FRACTION_MIDPOINT) { - // Halve the value as we are animating the drag across the full length for only the - // first half of the progress - mCurrentAnimation.setPlayFraction( - Utilities.boundToRange(totalDisplacement * mProgressMultiplier / 2, 0, 1)); + if (isGoingUp) { + if (mCurrentAnimation.getProgressFraction() < ANIMATION_PROGRESS_FRACTION_MIDPOINT) { + // Halve the value when dismissing, as we are animating the drag across the full + // length for only the first half of the progress + mCurrentAnimation.setPlayFraction( + Utilities.boundToRange(totalDisplacement * mProgressMultiplier / 2, 0, 1)); + } else { + // Set mOverrideVelocity to control task dismiss velocity in onDragEnd + int velocityDimenId = R.dimen.default_task_dismiss_drag_velocity; + if (mRecentsView.showAsGrid()) { + if (mTaskBeingDragged.isFocusedTask()) { + velocityDimenId = + R.dimen.default_task_dismiss_drag_velocity_grid_focus_task; + } else { + velocityDimenId = R.dimen.default_task_dismiss_drag_velocity_grid; + } + } + 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(); + } } else { - float dragVelocity = -mTaskBeingDragged.getResources().getDimension( - mRecentsView.showAsGrid() ? R.dimen.default_task_dismiss_drag_velocity_grid - : R.dimen.default_task_dismiss_drag_velocity); - onDragEnd(dragVelocity); - return true; + mCurrentAnimation.setPlayFraction( + Utilities.boundToRange(totalDisplacement * mProgressMultiplier, 0, 1)); } return true; @@ -303,6 +323,10 @@ public abstract class TaskViewTouchController @Override public void onDragEnd(float velocity) { + if (mOverrideVelocity != null) { + velocity = mOverrideVelocity; + mOverrideVelocity = null; + } // Limit velocity, as very large scalar values make animations play too quickly float maxTaskDismissDragVelocity = mTaskBeingDragged.getResources().getDimension( R.dimen.max_task_dismiss_drag_velocity);