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

Commit 21317d1d authored by Romain Guy's avatar Romain Guy
Browse files

Report scroll state change after cancelling the fling runnable.

Bug #3089972

This change also adds the ability to control the ListView's fling
velocity by introducing a new scale factor.

Change-Id: I4030d3fe3688f72b2b8250ac85bbf000e9adc883
parent 7031e7a6
Loading
Loading
Loading
Loading
+13 −0
Original line number Diff line number Diff line
@@ -225330,6 +225330,19 @@
<parameter name="mode" type="int">
</parameter>
</method>
<method name="setVelocityScale"
 return="void"
 abstract="false"
 native="false"
 synchronized="false"
 static="false"
 final="false"
 deprecated="not deprecated"
 visibility="public"
>
<parameter name="scale" type="float">
</parameter>
</method>
<method name="smoothScrollBy"
 return="void"
 abstract="false"
+16 −5
Original line number Diff line number Diff line
@@ -505,6 +505,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    private Runnable mClearScrollingCache;
    private int mMinimumVelocity;
    private int mMaximumVelocity;
    private float mVelocityScale = 1.0f;
    
    final boolean[] mIsScrap = new boolean[1];
    
@@ -2596,7 +2597,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    } else {
                        final VelocityTracker velocityTracker = mVelocityTracker;
                        velocityTracker.computeCurrentVelocity(1000, mMaximumVelocity);
                        final int initialVelocity = (int) velocityTracker.getYVelocity(mActivePointerId);
                        final int initialVelocity = (int)
                                (velocityTracker.getYVelocity(mActivePointerId) * mVelocityScale);
    
                        if (Math.abs(initialVelocity) > mMinimumVelocity) {
                            if (mFlingRunnable == null) {
@@ -2865,14 +2867,13 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        private void endFling() {
            mTouchMode = TOUCH_MODE_REST;

            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            clearScrollingCache();

            removeCallbacks(this);

            if (mPositionScroller != null) {
                removeCallbacks(mPositionScroller);
            }

            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            clearScrollingCache();
        }

        public void run() {
@@ -3262,6 +3263,16 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        mFlingRunnable.mScroller.setFriction(friction);        
    }

    /**
     * Sets a scale factor for the fling velocity. The initial scale
     * factor is 1.0.
     * 
     * @param scale The scale factor to multiply the velocity by.
     */
    public void setVelocityScale(float scale) {
        mVelocityScale = scale;
    }
    
    /**
     * Smoothly scroll to the specified adapter position. The view will
     * scroll such that the indicated position is displayed.