Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 1687d42d authored by Philip Quinn's avatar Philip Quinn
Browse files

Move ViewConfiguration#AMBIGUOUS_GESTURE_MULTIPLIER to config.xml.

Bug: 132648945
Test: run cts -m android.view.cts
Change-Id: Iea918b4cfbff617e495d3d3180a08a9b62bd0b68
parent 48ed89fa
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -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();
+6 −3
Original line number Diff line number Diff line
@@ -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) {
+12 −5
Original line number Diff line number Diff line
@@ -4910,6 +4910,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.
     */
@@ -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
+30 −7
Original line number Diff line number Diff line
@@ -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,21 +961,34 @@ 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.
     *
+3 −0
Original line number Diff line number Diff line
@@ -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>

Loading