summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorPawit Pornkitprasan <p.pawit@gmail.com>2014-11-17 18:59:57 +0100
committeralk3pInjection <webmaster@raspii.tech>2022-05-07 00:20:58 +0800
commite72fa88e2ace0497c3518e17b0082dcb2eb2dd4a (patch)
tree884b9fc22f76713878979b34a7edb7a4c4b5a181 /core
parentcdd0e0a781762fe4882f1557a2cde5560a520995 (diff)
AbsListView: 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: Iad52a35120212c871ffd35df6184aeb678ee44aa Signed-off-by: Alex Naidis <alex.naidis@linux.com>
Diffstat (limited to 'core')
-rwxr-xr-xcore/java/android/widget/AbsListView.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/core/java/android/widget/AbsListView.java b/core/java/android/widget/AbsListView.java
index ac21d952765d..d404a7f02168 100755
--- a/core/java/android/widget/AbsListView.java
+++ b/core/java/android/widget/AbsListView.java
@@ -666,6 +666,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
private int mMinimumVelocity;
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P, trackingBug = 124051740)
private int mMaximumVelocity;
+ private int mDecacheThreshold;
private float mVelocityScale = 1.0f;
final boolean[] mIsScrap = new boolean[1];
@@ -957,6 +958,7 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
}
mMinimumVelocity = configuration.getScaledMinimumFlingVelocity();
mMaximumVelocity = configuration.getScaledMaximumFlingVelocity();
+ mDecacheThreshold = mMaximumVelocity / 2;
mOverscrollDistance = configuration.getScaledOverscrollDistance();
mOverflingDistance = configuration.getScaledOverflingDistance();
@@ -4801,7 +4803,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);
}
@@ -4817,6 +4819,11 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
// Use AbsListView#fling(int) instead
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
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);
@@ -4897,6 +4904,10 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
// To interrupt a fling early you should use smoothScrollBy(0,0) instead
@UnsupportedAppUsage(maxTargetSdk = Build.VERSION_CODES.P)
void endFling() {
+ endFling(true);
+ }
+
+ void endFling(boolean clearCache) {
mTouchMode = TOUCH_MODE_REST;
removeCallbacks(this);
@@ -4905,7 +4916,8 @@ public abstract class AbsListView extends AdapterView<ListAdapter> implements Te
if (!mSuppressIdleStateChangeCall) {
reportScrollStateChange(OnScrollListener.SCROLL_STATE_IDLE);
}
- clearScrollingCache();
+ if (clearCache)
+ clearScrollingCache();
mScroller.abortAnimation();
if (mFlingStrictSpan != null) {