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

Commit 92ce8508 authored by Pawit Pornkitprasan's avatar Pawit Pornkitprasan
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)

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

    final boolean[] mIsScrap = new boolean[1];
@@ -786,6 +787,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();

@@ -3650,7 +3652,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);
                }
@@ -3664,6 +3666,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.fling(0, initialY, 0, initialVelocity,
@@ -3733,12 +3740,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();