[DO NOT MERGE] Log gesture velocity to help debug and help direct future gesture nav thresholds.
Bug: 259021562
Test: performed gestures and checked logs
Change-Id: If0dec4ef74c2ef2d1617d8c37f10f3ef9d96b2f5
diff --git a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
index 3d8ffc4..e769c1d 100644
--- a/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
+++ b/quickstep/src/com/android/quickstep/AbsSwipeUpHandler.java
@@ -1001,26 +1001,27 @@
}
/**
- * @param endVelocity The velocity in the direction of the nav bar to the middle of the screen.
- * @param velocity The x and y components of the velocity when the gesture ends.
+ * @param endVelocityPxPerMs The velocity in the direction of the nav bar to the middle of the
+ * screen.
+ * @param velocityPxPerMs The x and y components of the velocity when the gesture ends.
* @param downPos The x and y value of where the gesture started.
*/
@UiThread
- public void onGestureEnded(float endVelocity, PointF velocity, PointF downPos) {
+ public void onGestureEnded(float endVelocityPxPerMs, PointF velocityPxPerMs, PointF downPos) {
float flingThreshold = mContext.getResources()
.getDimension(R.dimen.quickstep_fling_threshold_speed);
boolean isFling = mGestureStarted && !mIsMotionPaused
- && Math.abs(endVelocity) > flingThreshold;
+ && Math.abs(endVelocityPxPerMs) > flingThreshold;
mStateCallback.setStateOnUiThread(STATE_GESTURE_COMPLETED);
- boolean isVelocityVertical = Math.abs(velocity.y) > Math.abs(velocity.x);
+ boolean isVelocityVertical = Math.abs(velocityPxPerMs.y) > Math.abs(velocityPxPerMs.x);
if (isVelocityVertical) {
- mLogDirectionUpOrLeft = velocity.y < 0;
+ mLogDirectionUpOrLeft = velocityPxPerMs.y < 0;
} else {
- mLogDirectionUpOrLeft = velocity.x < 0;
+ mLogDirectionUpOrLeft = velocityPxPerMs.x < 0;
}
mDownPos = downPos;
- Runnable handleNormalGestureEndCallback = () ->
- handleNormalGestureEnd(endVelocity, isFling, velocity, /* isCancel= */ false);
+ Runnable handleNormalGestureEndCallback = () -> handleNormalGestureEnd(
+ endVelocityPxPerMs, isFling, velocityPxPerMs, /* isCancel= */ false);
if (mRecentsView != null) {
mRecentsView.runOnPageScrollsInitialized(handleNormalGestureEndCallback);
} else {
@@ -1115,8 +1116,20 @@
return false;
}
+ private float dpiFromPx(float pixels) {
+ return Utilities.dpiFromPx(pixels, mContext.getResources().getDisplayMetrics().densityDpi);
+ }
+
private GestureEndTarget calculateEndTarget(
- PointF velocity, float endVelocity, boolean isFlingY, boolean isCancel) {
+ PointF velocityPxPerMs, float endVelocityPxPerMs, boolean isFlingY, boolean isCancel) {
+ ActiveGestureLog.INSTANCE.addLog(
+ new ActiveGestureLog.CompoundString("calculateEndTarget: velocities=(x=")
+ .append(Float.toString(dpiFromPx(velocityPxPerMs.x)))
+ .append("dp/ms, y=")
+ .append(Float.toString(dpiFromPx(velocityPxPerMs.y)))
+ .append("dp/ms), angle=")
+ .append(Double.toString(Math.toDegrees(Math.atan2(
+ -velocityPxPerMs.y, velocityPxPerMs.x)))));
if (mGestureState.isHandlingAtomicEvent()) {
// Button mode, this is only used to go to recents.
@@ -1127,9 +1140,9 @@
if (isCancel) {
endTarget = LAST_TASK;
} else if (isFlingY) {
- endTarget = calculateEndTargetForFlingY(velocity, endVelocity);
+ endTarget = calculateEndTargetForFlingY(velocityPxPerMs, endVelocityPxPerMs);
} else {
- endTarget = calculateEndTargetForNonFling(velocity);
+ endTarget = calculateEndTargetForNonFling(velocityPxPerMs);
}
if (mDeviceState.isOverviewDisabled() && endTarget == RECENTS) {
@@ -1197,13 +1210,12 @@
}
@UiThread
- private void handleNormalGestureEnd(float endVelocity, boolean isFling, PointF velocity,
- boolean isCancel) {
+ private void handleNormalGestureEnd(
+ float endVelocityPxPerMs, boolean isFling, PointF velocityPxPerMs, boolean isCancel) {
long duration = MAX_SWIPE_DURATION;
float currentShift = mCurrentShift.value;
- final GestureEndTarget endTarget = calculateEndTarget(velocity, endVelocity,
- isFling, isCancel);
-
+ final GestureEndTarget endTarget = calculateEndTarget(
+ velocityPxPerMs, endVelocityPxPerMs, isFling, isCancel);
// Set the state, but don't notify until the animation completes
mGestureState.setEndTarget(endTarget, false /* isAtomic */);
mAnimationFactory.setEndTarget(endTarget);
@@ -1216,16 +1228,16 @@
duration = Math.min(MAX_SWIPE_DURATION, expectedDuration);
startShift = currentShift;
} else {
- startShift = Utilities.boundToRange(currentShift - velocity.y
+ startShift = Utilities.boundToRange(currentShift - velocityPxPerMs.y
* getSingleFrameMs(mContext) / mTransitionDragLength, 0, mDragLengthFactor);
if (mTransitionDragLength > 0) {
- float distanceToTravel = (endShift - currentShift) * mTransitionDragLength;
+ float distanceToTravel = (endShift - currentShift) * mTransitionDragLength;
- // we want the page's snap velocity to approximately match the velocity at
- // which the user flings, so we scale the duration by a value near to the
- // derivative of the scroll interpolator at zero, ie. 2.
- long baseDuration = Math.round(Math.abs(distanceToTravel / velocity.y));
- duration = Math.min(MAX_SWIPE_DURATION, 2 * baseDuration);
+ // we want the page's snap velocity to approximately match the velocity at
+ // which the user flings, so we scale the duration by a value near to the
+ // derivative of the scroll interpolator at zero, ie. 2.
+ long baseDuration = Math.round(Math.abs(distanceToTravel / velocityPxPerMs.y));
+ duration = Math.min(MAX_SWIPE_DURATION, 2 * baseDuration);
}
}
Interpolator interpolator;
@@ -1293,7 +1305,7 @@
onPageTransitionEnd.run();
}
- animateToProgress(startShift, endShift, duration, interpolator, endTarget, velocity);
+ animateToProgress(startShift, endShift, duration, interpolator, endTarget, velocityPxPerMs);
}
private void doLogGesture(GestureEndTarget endTarget, @Nullable TaskView targetTask) {
diff --git a/quickstep/src/com/android/quickstep/inputconsumers/OtherActivityInputConsumer.java b/quickstep/src/com/android/quickstep/inputconsumers/OtherActivityInputConsumer.java
index db243da..a7ae6b5 100644
--- a/quickstep/src/com/android/quickstep/inputconsumers/OtherActivityInputConsumer.java
+++ b/quickstep/src/com/android/quickstep/inputconsumers/OtherActivityInputConsumer.java
@@ -397,16 +397,16 @@
mInteractionHandler.onGestureCancelled();
} else {
mVelocityTracker.computeCurrentVelocity(PX_PER_MS);
- float velocityX = mVelocityTracker.getXVelocity(mActivePointerId);
- float velocityY = mVelocityTracker.getYVelocity(mActivePointerId);
- float velocity = mNavBarPosition.isRightEdge()
- ? velocityX
+ float velocityXPxPerMs = mVelocityTracker.getXVelocity(mActivePointerId);
+ float velocityYPxPerMs = mVelocityTracker.getYVelocity(mActivePointerId);
+ float velocityPxPerMs = mNavBarPosition.isRightEdge()
+ ? velocityXPxPerMs
: mNavBarPosition.isLeftEdge()
- ? -velocityX
- : velocityY;
+ ? -velocityXPxPerMs
+ : velocityYPxPerMs;
mInteractionHandler.updateDisplacement(getDisplacement(ev) - mStartDisplacement);
- mInteractionHandler.onGestureEnded(velocity, new PointF(velocityX, velocityY),
- mDownPos);
+ mInteractionHandler.onGestureEnded(
+ velocityPxPerMs, new PointF(velocityXPxPerMs, velocityYPxPerMs), mDownPos);
}
} else {
// Since we start touch tracking on DOWN, we may reach this state without actually