diff options
| author | Siarhei Vishniakou <svv@google.com> | 2019-01-24 16:04:13 -0800 |
|---|---|---|
| committer | Siarhei Vishniakou <svv@google.com> | 2019-01-31 13:36:07 -0800 |
| commit | 8b047dd850e82e04ce8d5d7f7daa8974a7d660c4 (patch) | |
| tree | ab67cf6ca41c14689090891f7f16ae228cfe8378 /core/java/android | |
| parent | 4a49d7ad9615aa8d6ca85e4c98c1be9f621b726e (diff) | |
Move multiplier to ViewConfiguration
We have defined the same constant twice. Let's move it to
ViewConfiguration to avoid redundancy.
Test: build only
Bug: 123368517
Change-Id: I2ac765a85ccd71584429edc693d3ef33b2515c9d
Diffstat (limited to 'core/java/android')
| -rw-r--r-- | core/java/android/view/GestureDetector.java | 17 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 17 | ||||
| -rw-r--r-- | core/java/android/view/ViewConfiguration.java | 22 |
3 files changed, 31 insertions, 25 deletions
diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java index 7d9ec70a4599..c794a69d3680 100644 --- a/core/java/android/view/GestureDetector.java +++ b/core/java/android/view/GestureDetector.java @@ -237,16 +237,6 @@ public class GestureDetector { private static final int LONG_PRESS = 2; private static final int TAP = 3; - /** - * If a MotionEvent has CLASSIFICATION_AMBIGUOUS_GESTURE set, then certain actions, such as - * scrolling, will be inhibited. However, to account for the possibility of incorrect - * classification, the default scrolling will only be inhibited if the gesture moves beyond - * (default touch slop * AMBIGUOUS_GESTURE_MULTIPLIER). Likewise, the default long press - * timeout will be increased for some situations where the default behaviour - * is to cancel it. - */ - private static final int AMBIGUOUS_GESTURE_MULTIPLIER = 2; - private final Handler mHandler; @UnsupportedAppUsage private final OnGestureListener mListener; @@ -636,6 +626,7 @@ public class GestureDetector { hasPendingLongPress && ambiguousGesture; if (shouldInhibitDefaultAction) { // Inhibit default long press + final float multiplier = ViewConfiguration.getAmbiguousGestureMultiplier(); if (distance > slopSquare) { // The default action here is to remove long press. But if the touch // slop below gets increased, and we never exceed the modified touch @@ -643,15 +634,15 @@ public class GestureDetector { // will happen in response to user input. To prevent this, // reschedule long press with a modified timeout. mHandler.removeMessages(LONG_PRESS); - final int longPressTimeout = ViewConfiguration.getLongPressTimeout(); + final long longPressTimeout = ViewConfiguration.getLongPressTimeout(); mHandler.sendEmptyMessageAtTime(LONG_PRESS, ev.getDownTime() - + longPressTimeout * AMBIGUOUS_GESTURE_MULTIPLIER); + + (long) (longPressTimeout * multiplier)); } // Inhibit default scroll. If a gesture is ambiguous, we prevent scroll // until the gesture is resolved. // However, for safety, simply increase the touch slop in case the // classification is erroneous. Since the value is squared, multiply twice. - slopSquare *= AMBIGUOUS_GESTURE_MULTIPLIER * AMBIGUOUS_GESTURE_MULTIPLIER; + slopSquare *= multiplier * multiplier; } if (distance > slopSquare) { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index ec8ed5b2d5be..992b99617064 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -3986,15 +3986,6 @@ public class View implements Drawable.Callback, KeyEvent.Callback, public static final int SCROLL_AXIS_VERTICAL = 1 << 1; /** - * If a MotionEvent has CLASSIFICATION_AMBIGUOUS_GESTURE set, then certain the default - * long press action will be inhibited. However, to account for the possibility of incorrect - * classification, the default long press timeout will instead be increased for some situations - * by the following factor. - * Likewise, the touch slop for allowing long press will be increased when gesture is uncertain. - */ - private static final int AMBIGUOUS_GESTURE_MULTIPLIER = 2; - - /** * Controls the over-scroll mode for this view. * See {@link #overScrollBy(int, int, int, int, int, int, int, int, boolean)}, * {@link #OVER_SCROLL_ALWAYS}, {@link #OVER_SCROLL_IF_CONTENT_SCROLLS}, @@ -14807,18 +14798,20 @@ public class View implements Drawable.Callback, KeyEvent.Callback, motionClassification == MotionEvent.CLASSIFICATION_AMBIGUOUS_GESTURE; int touchSlop = mTouchSlop; if (ambiguousGesture && hasPendingLongPressCallback()) { + final float ambiguousMultiplier = + ViewConfiguration.getAmbiguousGestureMultiplier(); if (!pointInView(x, y, touchSlop)) { // The default action here is to cancel long press. But instead, we // just extend the timeout here, in case the classification // stays ambiguous. removeLongPressCallback(); - long delay = ViewConfiguration.getLongPressTimeout() - * AMBIGUOUS_GESTURE_MULTIPLIER; + long delay = (long) (ViewConfiguration.getLongPressTimeout() + * ambiguousMultiplier); // Subtract the time already spent delay -= event.getEventTime() - event.getDownTime(); checkForLongClick(delay, x, y); } - touchSlop *= AMBIGUOUS_GESTURE_MULTIPLIER; + touchSlop *= ambiguousMultiplier; } // Be lenient about moving outside of buttons diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index d03d97e1b219..94d1b6d0126a 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -16,6 +16,7 @@ package android.view; +import android.annotation.FloatRange; import android.annotation.TestApi; import android.annotation.UnsupportedAppUsage; import android.app.AppGlobals; @@ -286,6 +287,11 @@ public class ViewConfiguration { private static final int HAS_PERMANENT_MENU_KEY_TRUE = 1; private static final int HAS_PERMANENT_MENU_KEY_FALSE = 2; + /** + * The multiplication factor for inhibiting default gestures. + */ + private static final float AMBIGUOUS_GESTURE_MULTIPLIER = 2f; + private final int mEdgeSlop; private final int mFadingEdgeLength; private final int mMinimumFlingVelocity; @@ -911,6 +917,22 @@ public class ViewConfiguration { } /** + * If a MotionEvent has CLASSIFICATION_AMBIGUOUS_GESTURE set, then certain actions, such as + * scrolling, will be inhibited. + * However, to account for the possibility of incorrect classification, + * the default scrolling will only be inhibited if the pointer travels less than + * (getScaledTouchSlop() * this factor). + * Likewise, the default long press timeout will be increased by this factor for some situations + * where the default behaviour is to cancel it. + * + * @return The multiplication factor for inhibiting default gestures. + */ + @FloatRange(from = 1.0) + public static float getAmbiguousGestureMultiplier() { + return AMBIGUOUS_GESTURE_MULTIPLIER; + } + + /** * Report if the device has a permanent menu key available to the user. * * <p>As of Android 3.0, devices may not have a permanent menu key available. |
