Skip to content

Commit

Permalink
Improve scrolling cache
Browse files Browse the repository at this point in the history
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
  • Loading branch information
pawitp authored and knzy committed Sep 13, 2012
1 parent c4b53ae commit f675673
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions core/java/android/widget/AbsListView.java
Original file line number Diff line number Diff line change
Expand Up @@ -581,6 +581,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];
Expand Down Expand Up @@ -810,6 +811,7 @@ private void initAbsListView() {
mTouchSlop = configuration.getScaledTouchSlop();
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
mDecacheThreshold = mMaximumVelocity / 2;
mOverscrollDistance = configuration.getScaledOverscrollDistance();
mOverflingDistance = configuration.getScaledOverflingDistance();

Expand Down Expand Up @@ -4027,7 +4029,7 @@ public void run() {
// 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);
}
Expand All @@ -4041,6 +4043,11 @@ public void run() {
}

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);
Expand Down Expand Up @@ -4113,13 +4120,18 @@ void startScroll(int distance, int duration, boolean linear) {
}

void endFling() {
endFling(true);
}

void endFling(boolean clearCache) {
mTouchMode = TOUCH_MODE_REST;

removeCallbacks(this);
removeCallbacks(mCheckFlywheel);

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

if (mFlingStrictSpan != null) {
Expand Down

0 comments on commit f675673

Please sign in to comment.