End drag touch event when crossing task drag threshold, and only when task is going up (drag to dismiss) am: 49cb49b1f5

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Launcher3/+/14800534

Change-Id: I93c5b7dc6bd6cabb3560334102fae46553b39506
This commit is contained in:
Pat Manning 2021-06-03 07:29:24 +00:00 committed by Automerger Merge Worker
commit 668d10d6c4
2 changed files with 39 additions and 14 deletions

View File

@ -45,8 +45,9 @@
<!-- These speeds are in dp/s -->
<dimen name="max_task_dismiss_drag_velocity">2.25dp</dimen>
<dimen name="default_task_dismiss_drag_velocity">1.75dp</dimen>
<dimen name="default_task_dismiss_drag_velocity_grid">0.75dp</dimen>
<dimen name="default_task_dismiss_drag_velocity">1.5dp</dimen>
<dimen name="default_task_dismiss_drag_velocity_grid">1dp</dimen>
<dimen name="default_task_dismiss_drag_velocity_grid_focus_task">5dp</dimen>
<dimen name="recents_page_spacing">16dp</dimen>
<dimen name="recents_clear_all_deadzone_vertical_margin">70dp</dimen>

View File

@ -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<T extends BaseDraggingActivity>
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<T extends BaseDraggingActivity>
mCurrentAnimation.pause();
}
mFlingBlockCheck.unblockFling();
mOverrideVelocity = null;
}
@Override
@ -283,19 +286,36 @@ public abstract class TaskViewTouchController<T extends BaseDraggingActivity>
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<T extends BaseDraggingActivity>
@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);