diff options
| author | 2020-01-24 12:49:46 -0800 | |
|---|---|---|
| committer | 2020-01-24 12:57:24 -0800 | |
| commit | 1687d42d3a86a4aa2d415ec3c5d34aa78a7483e2 (patch) | |
| tree | dd1b68c6accc156b684730d2d1d73646b4bf6314 | |
| parent | 48ed89faa9ee60dd43030528d0be2af94fa855e5 (diff) | |
Move ViewConfiguration#AMBIGUOUS_GESTURE_MULTIPLIER to config.xml.
Bug: 132648945
Test: run cts -m android.view.cts
Change-Id: Iea918b4cfbff617e495d3d3180a08a9b62bd0b68
| -rw-r--r-- | api/current.txt | 3 | ||||
| -rw-r--r-- | core/java/android/view/GestureDetector.java | 9 | ||||
| -rw-r--r-- | core/java/android/view/View.java | 17 | ||||
| -rw-r--r-- | core/java/android/view/ViewConfiguration.java | 37 | ||||
| -rw-r--r-- | core/res/res/values/config.xml | 3 | ||||
| -rw-r--r-- | core/res/res/values/symbols.xml | 1 |
6 files changed, 54 insertions, 16 deletions
diff --git a/api/current.txt b/api/current.txt index 2dfa2e54ce05..5b16a2f15134 100644 --- a/api/current.txt +++ b/api/current.txt @@ -54107,7 +54107,7 @@ package android.view { public class ViewConfiguration { ctor @Deprecated public ViewConfiguration(); method public static android.view.ViewConfiguration get(android.content.Context); - method @FloatRange(from=1.0) public static float getAmbiguousGestureMultiplier(); + method @Deprecated @FloatRange(from=1.0) public static float getAmbiguousGestureMultiplier(); method public static long getDefaultActionModeHideDuration(); method public static int getDoubleTapTimeout(); method @Deprecated public static int getEdgeSlop(); @@ -54121,6 +54121,7 @@ package android.view { method @Deprecated public static int getMaximumFlingVelocity(); method @Deprecated public static int getMinimumFlingVelocity(); method public static int getPressedStateDuration(); + method @FloatRange(from=1.0) public float getScaledAmbiguousGestureMultiplier(); method public int getScaledDoubleTapSlop(); method public int getScaledEdgeSlop(); method public int getScaledFadingEdgeLength(); diff --git a/core/java/android/view/GestureDetector.java b/core/java/android/view/GestureDetector.java index 4d71136d0af1..19793b945ffd 100644 --- a/core/java/android/view/GestureDetector.java +++ b/core/java/android/view/GestureDetector.java @@ -231,6 +231,7 @@ public class GestureDetector { private int mTouchSlopSquare; private int mDoubleTapTouchSlopSquare; private int mDoubleTapSlopSquare; + private float mAmbiguousGestureMultiplier; @UnsupportedAppUsage private int mMinimumFlingVelocity; private int mMaximumFlingVelocity; @@ -452,6 +453,7 @@ public class GestureDetector { //noinspection deprecation mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity(); mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity(); + mAmbiguousGestureMultiplier = ViewConfiguration.getAmbiguousGestureMultiplier(); } else { final ViewConfiguration configuration = ViewConfiguration.get(context); touchSlop = configuration.getScaledTouchSlop(); @@ -459,6 +461,7 @@ public class GestureDetector { doubleTapSlop = configuration.getScaledDoubleTapSlop(); mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity(); mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity(); + mAmbiguousGestureMultiplier = configuration.getScaledAmbiguousGestureMultiplier(); } mTouchSlopSquare = touchSlop * touchSlop; mDoubleTapTouchSlopSquare = doubleTapTouchSlop * doubleTapTouchSlop; @@ -661,7 +664,6 @@ 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 @@ -675,13 +677,14 @@ public class GestureDetector { LONG_PRESS, TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__LONG_PRESS, 0 /* arg2 */), - ev.getDownTime() + (long) (longPressTimeout * multiplier)); + ev.getDownTime() + + (long) (longPressTimeout * mAmbiguousGestureMultiplier)); } // 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 *= multiplier * multiplier; + slopSquare *= mAmbiguousGestureMultiplier * mAmbiguousGestureMultiplier; } if (distance > slopSquare) { diff --git a/core/java/android/view/View.java b/core/java/android/view/View.java index c5f4faf2f462..cdc1c2162a72 100644 --- a/core/java/android/view/View.java +++ b/core/java/android/view/View.java @@ -4911,6 +4911,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, private int mTouchSlop; /** + * Cache the ambiguous gesture multiplier from the context that created the view. + */ + private float mAmbiguousGestureMultiplier; + + /** * Object that handles automatic animation of view properties. */ @UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 115609023) @@ -5224,7 +5229,11 @@ public class View implements Drawable.Callback, KeyEvent.Callback, (TEXT_ALIGNMENT_DEFAULT << PFLAG2_TEXT_ALIGNMENT_MASK_SHIFT) | (PFLAG2_TEXT_ALIGNMENT_RESOLVED_DEFAULT) | (IMPORTANT_FOR_ACCESSIBILITY_DEFAULT << PFLAG2_IMPORTANT_FOR_ACCESSIBILITY_SHIFT); - mTouchSlop = ViewConfiguration.get(context).getScaledTouchSlop(); + + final ViewConfiguration configuration = ViewConfiguration.get(context); + mTouchSlop = configuration.getScaledTouchSlop(); + mAmbiguousGestureMultiplier = configuration.getScaledAmbiguousGestureMultiplier(); + setOverScrollMode(OVER_SCROLL_IF_CONTENT_SCROLLS); mUserPaddingStart = UNDEFINED_PADDING; mUserPaddingEnd = UNDEFINED_PADDING; @@ -15642,15 +15651,13 @@ 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 = (long) (ViewConfiguration.getLongPressTimeout() - * ambiguousMultiplier); + * mAmbiguousGestureMultiplier); // Subtract the time already spent delay -= event.getEventTime() - event.getDownTime(); checkForLongClick( @@ -15659,7 +15666,7 @@ public class View implements Drawable.Callback, KeyEvent.Callback, y, TOUCH_GESTURE_CLASSIFIED__CLASSIFICATION__LONG_PRESS); } - touchSlop *= ambiguousMultiplier; + touchSlop *= mAmbiguousGestureMultiplier; } // Be lenient about moving outside of buttons diff --git a/core/java/android/view/ViewConfiguration.java b/core/java/android/view/ViewConfiguration.java index 774a2dea6311..a66b508cf523 100644 --- a/core/java/android/view/ViewConfiguration.java +++ b/core/java/android/view/ViewConfiguration.java @@ -29,6 +29,7 @@ import android.os.RemoteException; import android.provider.Settings; import android.util.DisplayMetrics; import android.util.SparseArray; +import android.util.TypedValue; /** * Contains methods to standard constants used in the UI for timeouts, sizes, and distances. @@ -313,6 +314,7 @@ public class ViewConfiguration { private final int mPagingTouchSlop; private final int mDoubleTapSlop; private final int mWindowTouchSlop; + private final float mAmbiguousGestureMultiplier; private final int mMaximumDrawingCacheSize; private final int mOverscrollDistance; private final int mOverflingDistance; @@ -351,6 +353,7 @@ public class ViewConfiguration { mPagingTouchSlop = PAGING_TOUCH_SLOP; mDoubleTapSlop = DOUBLE_TAP_SLOP; mWindowTouchSlop = WINDOW_TOUCH_SLOP; + mAmbiguousGestureMultiplier = AMBIGUOUS_GESTURE_MULTIPLIER; //noinspection deprecation mMaximumDrawingCacheSize = MAXIMUM_DRAWING_CACHE_SIZE; mOverscrollDistance = OVERSCROLL_DISTANCE; @@ -397,6 +400,13 @@ public class ViewConfiguration { mDoubleTapSlop = (int) (sizeAndDensity * DOUBLE_TAP_SLOP + 0.5f); mWindowTouchSlop = (int) (sizeAndDensity * WINDOW_TOUCH_SLOP + 0.5f); + final TypedValue multiplierValue = new TypedValue(); + res.getValue( + com.android.internal.R.dimen.config_ambiguousGestureMultiplier, + multiplierValue, + true /*resolveRefs*/); + mAmbiguousGestureMultiplier = multiplierValue.getFloat(); + // Size of the screen in bytes, in ARGB_8888 format final WindowManager win = (WindowManager)context.getSystemService(Context.WINDOW_SERVICE); final Display display = win.getDefaultDisplay(); @@ -951,22 +961,35 @@ public class ViewConfiguration { } /** + * The multiplication factor for inhibiting default gestures. + * * If a MotionEvent has {@link android.view.MotionEvent#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. + * then certain actions, such as scrolling, will be inhibited. However, to account for the + * possibility of an incorrect classification, existing gesture thresholds (e.g. scrolling + * touch slop and the long-press timeout) should be scaled by this factor and remain in effect. * - * @return The multiplication factor for inhibiting default gestures. + * @deprecated Use {@link #getScaledAmbiguousGestureMultiplier()}. */ + @Deprecated @FloatRange(from = 1.0) public static float getAmbiguousGestureMultiplier() { return AMBIGUOUS_GESTURE_MULTIPLIER; } /** + * The multiplication factor for inhibiting default gestures. + * + * If a MotionEvent has {@link android.view.MotionEvent#CLASSIFICATION_AMBIGUOUS_GESTURE} set, + * then certain actions, such as scrolling, will be inhibited. However, to account for the + * possibility of an incorrect classification, existing gesture thresholds (e.g. scrolling + * touch slop and the long-press timeout) should be scaled by this factor and remain in effect. + */ + @FloatRange(from = 1.0) + public float getScaledAmbiguousGestureMultiplier() { + return mAmbiguousGestureMultiplier; + } + + /** * 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. diff --git a/core/res/res/values/config.xml b/core/res/res/values/config.xml index dadb92415839..e98f8ba3cda7 100644 --- a/core/res/res/values/config.xml +++ b/core/res/res/values/config.xml @@ -2281,6 +2281,9 @@ movement threshold under which hover is considered "stationary". --> <dimen name="config_viewConfigurationHoverSlop">4dp</dimen> + <!-- Multiplier for gesture thresholds when a MotionEvent classification is ambiguous. --> + <item name="config_ambiguousGestureMultiplier" format="float" type="dimen">2.0</item> + <!-- Minimum velocity to initiate a fling, as measured in dips per second. --> <dimen name="config_viewMinFlingVelocity">50dp</dimen> diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 18ca003dd8c6..1117fcf5825e 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -482,6 +482,7 @@ <java-symbol type="dimen" name="config_prefDialogWidth" /> <java-symbol type="dimen" name="config_viewConfigurationTouchSlop" /> <java-symbol type="dimen" name="config_viewConfigurationHoverSlop" /> + <java-symbol type="dimen" name="config_ambiguousGestureMultiplier" /> <java-symbol type="dimen" name="config_viewMinFlingVelocity" /> <java-symbol type="dimen" name="config_viewMaxFlingVelocity" /> <java-symbol type="dimen" name="config_scrollbarSize" /> |