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

Commit 005ae544 authored by Android (Google) Code Review's avatar Android (Google) Code Review Committed by The Android Open Source Project
Browse files

am 79ec07b3: Merge change 6241 into donut

Merge commit '79ec07b3'

* commit '79ec07b3':
  Fixes #1444844. Set a maximum fling velocity in scrollable views.
parents dd3d10c8 79ec07b3
Loading
Loading
Loading
Loading
+37 −0
Original line number Original line Diff line number Diff line
@@ -143546,6 +143546,21 @@
<parameter name="units" type="int">
<parameter name="units" type="int">
</parameter>
</parameter>
</method>
</method>
<method name="computeCurrentVelocity"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="units" type="int">
</parameter>
<parameter name="maxVelocity" type="float">
</parameter>
</method>
<method name="getXVelocity"
<method name="getXVelocity"
 return="float"
 return="float"
 abstract="false"
 abstract="false"
@@ -147949,6 +147964,17 @@
 visibility="public"
 visibility="public"
>
>
</method>
</method>
<method name="getMaximumFlingVelocity"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="true"
 final="false"
 deprecated="deprecated"
 visibility="public"
>
</method>
<method name="getMinimumFlingVelocity"
<method name="getMinimumFlingVelocity"
 return="int"
 return="int"
 abstract="false"
 abstract="false"
@@ -148015,6 +148041,17 @@
 visibility="public"
 visibility="public"
>
>
</method>
</method>
<method name="getScaledMaximumFlingVelocity"
 return="int"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
</method>
<method name="getScaledMinimumFlingVelocity"
<method name="getScaledMinimumFlingVelocity"
 return="int"
 return="int"
 abstract="false"
 abstract="false"
+4 −1
Original line number Original line Diff line number Diff line
@@ -198,6 +198,7 @@ public class GestureDetector {
    private int mTouchSlopSquare;
    private int mTouchSlopSquare;
    private int mDoubleTapSlopSquare;
    private int mDoubleTapSlopSquare;
    private int mMinimumFlingVelocity;
    private int mMinimumFlingVelocity;
    private int mMaximumFlingVelocity;


    private static final int LONGPRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();
    private static final int LONGPRESS_TIMEOUT = ViewConfiguration.getLongPressTimeout();
    private static final int TAP_TIMEOUT = ViewConfiguration.getTapTimeout();
    private static final int TAP_TIMEOUT = ViewConfiguration.getTapTimeout();
@@ -361,11 +362,13 @@ public class GestureDetector {
            doubleTapSlop = ViewConfiguration.getDoubleTapSlop();
            doubleTapSlop = ViewConfiguration.getDoubleTapSlop();
            //noinspection deprecation
            //noinspection deprecation
            mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
            mMinimumFlingVelocity = ViewConfiguration.getMinimumFlingVelocity();
            mMaximumFlingVelocity = ViewConfiguration.getMaximumFlingVelocity();
        } else {
        } else {
            final ViewConfiguration configuration = ViewConfiguration.get(context);
            final ViewConfiguration configuration = ViewConfiguration.get(context);
            touchSlop = configuration.getScaledTouchSlop();
            touchSlop = configuration.getScaledTouchSlop();
            doubleTapSlop = configuration.getScaledDoubleTapSlop();
            doubleTapSlop = configuration.getScaledDoubleTapSlop();
            mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
            mMinimumFlingVelocity = configuration.getScaledMinimumFlingVelocity();
            mMaximumFlingVelocity = configuration.getScaledMaximumFlingVelocity();
        }
        }
        mTouchSlopSquare = touchSlop * touchSlop;
        mTouchSlopSquare = touchSlop * touchSlop;
        mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop;
        mDoubleTapSlopSquare = doubleTapSlop * doubleTapSlop;
@@ -505,7 +508,7 @@ public class GestureDetector {


                // A fling must travel the minimum tap distance
                // A fling must travel the minimum tap distance
                final VelocityTracker velocityTracker = mVelocityTracker;
                final VelocityTracker velocityTracker = mVelocityTracker;
                velocityTracker.computeCurrentVelocity(1000);
                velocityTracker.computeCurrentVelocity(1000, mMaximumFlingVelocity);
                final float velocityY = velocityTracker.getYVelocity();
                final float velocityY = velocityTracker.getYVelocity();
                final float velocityX = velocityTracker.getXVelocity();
                final float velocityX = velocityTracker.getXVelocity();


+17 −4
Original line number Original line Diff line number Diff line
@@ -166,6 +166,16 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
        }
        }
    }
    }


    /**
     * Equivalent to invoking {@link #computeCurrentVelocity(int, float)} with a maximum
     * velocity of Float.MAX_VALUE.
     * 
     * @see #computeCurrentVelocity(int, float) 
     */
    public void computeCurrentVelocity(int units) {
        computeCurrentVelocity(units, Float.MAX_VALUE);
    }

    /**
    /**
     * Compute the current velocity based on the points that have been
     * Compute the current velocity based on the points that have been
     * collected.  Only call this when you actually want to retrieve velocity
     * collected.  Only call this when you actually want to retrieve velocity
@@ -175,8 +185,11 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
     * 
     * 
     * @param units The units you would like the velocity in.  A value of 1
     * @param units The units you would like the velocity in.  A value of 1
     * provides pixels per millisecond, 1000 provides pixels per second, etc.
     * provides pixels per millisecond, 1000 provides pixels per second, etc.
     * @param maxVelocity The maximum velocity that can be computed by this method.
     * This value must be declared in the same unit as the units parameter. This value
     * must be positive.
     */
     */
    public void computeCurrentVelocity(int units) {
    public void computeCurrentVelocity(int units, float maxVelocity) {
        final float[] pastX = mPastX;
        final float[] pastX = mPastX;
        final float[] pastY = mPastY;
        final float[] pastY = mPastY;
        final long[] pastTime = mPastTime;
        final long[] pastTime = mPastTime;
@@ -210,8 +223,8 @@ public final class VelocityTracker implements Poolable<VelocityTracker> {
            if (accumY == 0) accumY = vel;
            if (accumY == 0) accumY = vel;
            else accumY = (accumY + vel) * .5f;
            else accumY = (accumY + vel) * .5f;
        }
        }
        mXVelocity = accumX;
        mXVelocity = accumX < 0.0f ? Math.max(accumX, -maxVelocity) : Math.min(accumX, maxVelocity);
        mYVelocity = accumY;
        mYVelocity = accumY < 0.0f ? Math.max(accumY, -maxVelocity) : Math.min(accumY, maxVelocity);
        
        
        if (localLOGV) Log.v(TAG, "Y velocity=" + mYVelocity +" X velocity="
        if (localLOGV) Log.v(TAG, "Y velocity=" + mYVelocity +" X velocity="
                + mXVelocity + " N=" + N);
                + mXVelocity + " N=" + N);
+25 −0
Original line number Original line Diff line number Diff line
@@ -107,6 +107,11 @@ public class ViewConfiguration {
     */
     */
    private static final int MINIMUM_FLING_VELOCITY = 50;
    private static final int MINIMUM_FLING_VELOCITY = 50;
    
    
    /**
     * Maximum velocity to initiate a fling, as measured in pixels per second
     */
    private static final int MAXIMUM_FLING_VELOCITY = 4000;

    /**
    /**
     * The maximum size of View's drawing cache, expressed in bytes. This size
     * The maximum size of View's drawing cache, expressed in bytes. This size
     * should be at least equal to the size of the screen in ARGB888 format.
     * should be at least equal to the size of the screen in ARGB888 format.
@@ -122,6 +127,7 @@ public class ViewConfiguration {
    private final int mEdgeSlop;
    private final int mEdgeSlop;
    private final int mFadingEdgeLength;
    private final int mFadingEdgeLength;
    private final int mMinimumFlingVelocity;
    private final int mMinimumFlingVelocity;
    private final int mMaximumFlingVelocity;
    private final int mScrollbarSize;
    private final int mScrollbarSize;
    private final int mTouchSlop;
    private final int mTouchSlop;
    private final int mDoubleTapSlop;
    private final int mDoubleTapSlop;
@@ -139,6 +145,7 @@ public class ViewConfiguration {
        mEdgeSlop = EDGE_SLOP;
        mEdgeSlop = EDGE_SLOP;
        mFadingEdgeLength = FADING_EDGE_LENGTH;
        mFadingEdgeLength = FADING_EDGE_LENGTH;
        mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
        mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
        mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
        mScrollbarSize = SCROLL_BAR_SIZE;
        mScrollbarSize = SCROLL_BAR_SIZE;
        mTouchSlop = TOUCH_SLOP;
        mTouchSlop = TOUCH_SLOP;
        mDoubleTapSlop = DOUBLE_TAP_SLOP;
        mDoubleTapSlop = DOUBLE_TAP_SLOP;
@@ -164,6 +171,7 @@ public class ViewConfiguration {
        mEdgeSlop = (int) (density * EDGE_SLOP + 0.5f);
        mEdgeSlop = (int) (density * EDGE_SLOP + 0.5f);
        mFadingEdgeLength = (int) (density * FADING_EDGE_LENGTH + 0.5f);
        mFadingEdgeLength = (int) (density * FADING_EDGE_LENGTH + 0.5f);
        mMinimumFlingVelocity = (int) (density * MINIMUM_FLING_VELOCITY + 0.5f);
        mMinimumFlingVelocity = (int) (density * MINIMUM_FLING_VELOCITY + 0.5f);
        mMaximumFlingVelocity = (int) (density * MAXIMUM_FLING_VELOCITY + 0.5f);
        mScrollbarSize = (int) (density * SCROLL_BAR_SIZE + 0.5f);
        mScrollbarSize = (int) (density * SCROLL_BAR_SIZE + 0.5f);
        mTouchSlop = (int) (density * TOUCH_SLOP + 0.5f);
        mTouchSlop = (int) (density * TOUCH_SLOP + 0.5f);
        mDoubleTapSlop = (int) (density * DOUBLE_TAP_SLOP + 0.5f);
        mDoubleTapSlop = (int) (density * DOUBLE_TAP_SLOP + 0.5f);
@@ -366,6 +374,23 @@ public class ViewConfiguration {
        return mMinimumFlingVelocity;
        return mMinimumFlingVelocity;
    }
    }


    /**
     * @return Maximum velocity to initiate a fling, as measured in pixels per second.
     *
     * @deprecated Use {@link #getScaledMaximumFlingVelocity()} instead.
     */
    @Deprecated
    public static int getMaximumFlingVelocity() {
        return MAXIMUM_FLING_VELOCITY;
    }

    /**
     * @return Maximum velocity to initiate a fling, as measured in pixels per second.
     */
    public int getScaledMaximumFlingVelocity() {
        return mMaximumFlingVelocity;
    }
    
    /**
    /**
     * The maximum drawing cache size expressed in bytes.
     * The maximum drawing cache size expressed in bytes.
     *
     *
+5 −2
Original line number Original line Diff line number Diff line
@@ -349,6 +349,7 @@ public class WebView extends AbsoluteLayout
     * Helper class to get velocity for fling
     * Helper class to get velocity for fling
     */
     */
    VelocityTracker mVelocityTracker;
    VelocityTracker mVelocityTracker;
    private int mMaximumFling;


    /**
    /**
     * Touch mode
     * Touch mode
@@ -754,7 +755,8 @@ public class WebView extends AbsoluteLayout
        setClickable(true);
        setClickable(true);
        setLongClickable(true);
        setLongClickable(true);


        final int slop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
        final ViewConfiguration configuration = ViewConfiguration.get(getContext());
        final int slop = configuration.getScaledTouchSlop();
        mTouchSlopSquare = slop * slop;
        mTouchSlopSquare = slop * slop;
        mMinLockSnapReverseDistance = slop;
        mMinLockSnapReverseDistance = slop;
        final float density = getContext().getResources().getDisplayMetrics().density;
        final float density = getContext().getResources().getDisplayMetrics().density;
@@ -770,6 +772,7 @@ public class WebView extends AbsoluteLayout
        DEFAULT_MIN_ZOOM_SCALE = 0.25f * density;
        DEFAULT_MIN_ZOOM_SCALE = 0.25f * density;
        mMaxZoomScale = DEFAULT_MAX_ZOOM_SCALE;
        mMaxZoomScale = DEFAULT_MAX_ZOOM_SCALE;
        mMinZoomScale = DEFAULT_MIN_ZOOM_SCALE;
        mMinZoomScale = DEFAULT_MIN_ZOOM_SCALE;
        mMaximumFling = configuration.getScaledMaximumFlingVelocity();
    }
    }


    /* package */void updateDefaultZoomDensity(int zoomDensity) {
    /* package */void updateDefaultZoomDensity(int zoomDensity) {
@@ -4309,7 +4312,7 @@ public class WebView extends AbsoluteLayout
        int maxX = Math.max(computeHorizontalScrollRange() - getViewWidth(), 0);
        int maxX = Math.max(computeHorizontalScrollRange() - getViewWidth(), 0);
        int maxY = Math.max(computeVerticalScrollRange() - getViewHeight(), 0);
        int maxY = Math.max(computeVerticalScrollRange() - getViewHeight(), 0);


        mVelocityTracker.computeCurrentVelocity(1000);
        mVelocityTracker.computeCurrentVelocity(1000, mMaximumFling);
        int vx = (int) mVelocityTracker.getXVelocity();
        int vx = (int) mVelocityTracker.getXVelocity();
        int vy = (int) mVelocityTracker.getYVelocity();
        int vy = (int) mVelocityTracker.getYVelocity();


Loading