summaryrefslogtreecommitdiffstats
path: root/src/com/android/launcher3/touch
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/android/launcher3/touch')
-rw-r--r--src/com/android/launcher3/touch/AbstractStateChangeTouchController.java5
-rw-r--r--src/com/android/launcher3/touch/SwipeDetector.java71
2 files changed, 60 insertions, 16 deletions
diff --git a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
index 86deb43e0..40b030f62 100644
--- a/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
+++ b/src/com/android/launcher3/touch/AbstractStateChangeTouchController.java
@@ -69,6 +69,7 @@ public abstract class AbstractStateChangeTouchController
protected final Launcher mLauncher;
protected final SwipeDetector mDetector;
+ protected final SwipeDetector.Direction mSwipeDirection;
private boolean mNoIntercept;
protected int mStartContainerType;
@@ -105,6 +106,7 @@ public abstract class AbstractStateChangeTouchController
public AbstractStateChangeTouchController(Launcher l, SwipeDetector.Direction dir) {
mLauncher = l;
mDetector = new SwipeDetector(l, this, dir);
+ mSwipeDirection = dir;
}
protected long getAtomicDuration() {
@@ -262,7 +264,8 @@ public abstract class AbstractStateChangeTouchController
float deltaProgress = mProgressMultiplier * (displacement - mDisplacementShift);
float progress = deltaProgress + mStartProgress;
updateProgress(progress);
- boolean isDragTowardPositive = (displacement - mDisplacementShift) < 0;
+ boolean isDragTowardPositive = mSwipeDirection.isPositive(
+ displacement - mDisplacementShift);
if (progress <= 0) {
if (reinitCurrentAnimation(false, isDragTowardPositive)) {
mDisplacementShift = displacement;
diff --git a/src/com/android/launcher3/touch/SwipeDetector.java b/src/com/android/launcher3/touch/SwipeDetector.java
index a0a410e0d..e558fc7c7 100644
--- a/src/com/android/launcher3/touch/SwipeDetector.java
+++ b/src/com/android/launcher3/touch/SwipeDetector.java
@@ -24,6 +24,8 @@ import android.view.MotionEvent;
import android.view.VelocityTracker;
import android.view.ViewConfiguration;
+import com.android.launcher3.Utilities;
+
import androidx.annotation.NonNull;
import androidx.annotation.VisibleForTesting;
@@ -64,20 +66,25 @@ public class SwipeDetector {
public static abstract class Direction {
- abstract float getDisplacement(MotionEvent ev, int pointerIndex, PointF refPoint);
+ abstract float getDisplacement(MotionEvent ev, int pointerIndex, PointF refPoint,
+ boolean isRtl);
/**
* Distance in pixels a touch can wander before we think the user is scrolling.
*/
abstract float getActiveTouchSlop(MotionEvent ev, int pointerIndex, PointF downPos);
- abstract float getVelocity(VelocityTracker tracker);
+ abstract float getVelocity(VelocityTracker tracker, boolean isRtl);
+
+ abstract boolean isPositive(float displacement);
+
+ abstract boolean isNegative(float displacement);
}
public static final Direction VERTICAL = new Direction() {
@Override
- float getDisplacement(MotionEvent ev, int pointerIndex, PointF refPoint) {
+ float getDisplacement(MotionEvent ev, int pointerIndex, PointF refPoint, boolean isRtl) {
return ev.getY(pointerIndex) - refPoint.y;
}
@@ -87,16 +94,32 @@ public class SwipeDetector {
}
@Override
- float getVelocity(VelocityTracker tracker) {
+ float getVelocity(VelocityTracker tracker, boolean isRtl) {
return tracker.getYVelocity();
}
+
+ @Override
+ boolean isPositive(float displacement) {
+ // Up
+ return displacement < 0;
+ }
+
+ @Override
+ boolean isNegative(float displacement) {
+ // Down
+ return displacement > 0;
+ }
};
public static final Direction HORIZONTAL = new Direction() {
@Override
- float getDisplacement(MotionEvent ev, int pointerIndex, PointF refPoint) {
- return ev.getX(pointerIndex) - refPoint.x;
+ float getDisplacement(MotionEvent ev, int pointerIndex, PointF refPoint, boolean isRtl) {
+ float displacement = ev.getX(pointerIndex) - refPoint.x;
+ if (isRtl) {
+ displacement = -displacement;
+ }
+ return displacement;
}
@Override
@@ -105,8 +128,24 @@ public class SwipeDetector {
}
@Override
- float getVelocity(VelocityTracker tracker) {
- return tracker.getXVelocity();
+ float getVelocity(VelocityTracker tracker, boolean isRtl) {
+ float velocity = tracker.getXVelocity();
+ if (isRtl) {
+ velocity = -velocity;
+ }
+ return velocity;
+ }
+
+ @Override
+ boolean isPositive(float displacement) {
+ // Right
+ return displacement > 0;
+ }
+
+ @Override
+ boolean isNegative(float displacement) {
+ // Left
+ return displacement < 0;
}
};
@@ -159,6 +198,7 @@ public class SwipeDetector {
private final PointF mDownPos = new PointF();
private final PointF mLastPos = new PointF();
private final Direction mDir;
+ private final boolean mIsRtl;
private final float mTouchSlop;
private final float mMaxVelocity;
@@ -183,14 +223,15 @@ public class SwipeDetector {
}
public SwipeDetector(@NonNull Context context, @NonNull Listener l, @NonNull Direction dir) {
- this(ViewConfiguration.get(context), l, dir);
+ this(ViewConfiguration.get(context), l, dir, Utilities.isRtl(context.getResources()));
}
@VisibleForTesting
protected SwipeDetector(@NonNull ViewConfiguration config, @NonNull Listener l,
- @NonNull Direction dir) {
+ @NonNull Direction dir, boolean isRtl) {
mListener = l;
mDir = dir;
+ mIsRtl = isRtl;
mTouchSlop = config.getScaledTouchSlop();
mMaxVelocity = config.getScaledMaximumFlingVelocity();
}
@@ -212,8 +253,8 @@ public class SwipeDetector {
}
// Check if the client is interested in scroll in current direction.
- if (((mScrollConditions & DIRECTION_NEGATIVE) > 0 && mDisplacement > 0) ||
- ((mScrollConditions & DIRECTION_POSITIVE) > 0 && mDisplacement < 0)) {
+ if (((mScrollConditions & DIRECTION_NEGATIVE) > 0 && mDir.isNegative(mDisplacement)) ||
+ ((mScrollConditions & DIRECTION_POSITIVE) > 0 && mDir.isPositive(mDisplacement))) {
return true;
}
return false;
@@ -259,7 +300,7 @@ public class SwipeDetector {
if (pointerIndex == INVALID_POINTER_ID) {
break;
}
- mDisplacement = mDir.getDisplacement(ev, pointerIndex, mDownPos);
+ mDisplacement = mDir.getDisplacement(ev, pointerIndex, mDownPos, mIsRtl);
// handle state and listener calls.
if (mState != ScrollState.DRAGGING && shouldScrollStart(ev, pointerIndex)) {
@@ -315,7 +356,7 @@ public class SwipeDetector {
* @see #DIRECTION_BOTH
*/
public boolean wasInitialTouchPositive() {
- return mSubtractDisplacement < 0;
+ return mDir.isPositive(mSubtractDisplacement);
}
private boolean reportDragging() {
@@ -332,7 +373,7 @@ public class SwipeDetector {
private void reportDragEnd() {
mVelocityTracker.computeCurrentVelocity(1000, mMaxVelocity);
- float velocity = mDir.getVelocity(mVelocityTracker) / 1000;
+ float velocity = mDir.getVelocity(mVelocityTracker, mIsRtl) / 1000;
if (DBG) {
Log.d(TAG, String.format("onScrollEnd disp=%.1f, velocity=%.1f",
mDisplacement, velocity));