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

Commit 8497369c authored by undefined's avatar undefined Committed by Steve Kondik
Browse files

Improve scrolling cache

Scrolling cache helps make short scrolls/flings smooth but will
cause stutter when long flings are made. This patch disables
scrolling cache when long flings are made.

This patch also fixes a related bug where scrolling cache will
not be enabled properly when transitioning from flinging to scrolling.

Patch Set 2: Calculate threshold based on maximum velocity (Sang Tae Park)

Credits: Pawit Pornkitprasan

Change-Id: Iad52a35120212c871ffd35df6184aeb678ee44aa
parent 562ca17c
Loading
Loading
Loading
Loading
+14 −2
Original line number Diff line number Diff line
@@ -604,6 +604,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
    Runnable mPositionScrollAfterLayout;
    private int mMinimumVelocity;
    private int mMaximumVelocity;
    private int mDecacheThreshold;
    private float mVelocityScale = 1.0f;

    final boolean[] mIsScrap = new boolean[1];
@@ -861,6 +862,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        mTouchSlop = configuration.getScaledTouchSlop();
        mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
        mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
        mDecacheThreshold = mMaximumVelocity / 2;
        mOverscrollDistance = configuration.getScaledOverscrollDistance();
        mOverflingDistance = configuration.getScaledOverflingDistance();

@@ -4345,7 +4347,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
                    // Keep the fling alive a little longer
                    postDelayed(this, FLYWHEEL_TIMEOUT);
                } else {
                    endFling();
                    endFling(false); // Don't disable the scrolling cache right after it was enabled
                    mTouchMode = TOUCH_MODE_SCROLL;
                    reportScrollStateChange(OnScrollListener.SCROLL_STATE_TOUCH_SCROLL);
                }
@@ -4359,6 +4361,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }

        void start(int initialVelocity) {
            if (Math.abs(initialVelocity) > mDecacheThreshold) {
                // For long flings, scrolling cache causes stutter, so don't use it
                clearScrollingCache();
            }

            int initialY = initialVelocity < 0 ? Integer.MAX_VALUE : 0;
            mLastFlingY = initialY;
            mScroller.setInterpolator(null);
@@ -4431,12 +4438,17 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
        }

        void endFling() {
            endFling(true);
        }

        void endFling(boolean clearCache) {
            mTouchMode = TOUCH_MODE_REST;

            removeCallbacks(this);
            removeCallbacks(mCheckFlywheel);

            reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
            if (clearCache)
                clearScrollingCache();
            mScroller.abortAnimation();