diff options
| author | Vladislav Kaznacheev <kaznacheev@google.com> | 2015-06-22 09:30:17 +0000 |
|---|---|---|
| committer | Android (Google) Code Review <android-gerrit@google.com> | 2015-06-22 09:30:20 +0000 |
| commit | 8228e4247c320632ba1e401259eceae7aa2738d1 (patch) | |
| tree | fd2ba3a2b62f386bd09825be646fe564f30a5fcf /core | |
| parent | c28695079e3511e02845bad9d730753daefba8a3 (diff) | |
| parent | 160d12ee51672e1482f95a349edb49630398d335 (diff) | |
| download | frameworks_base-8228e4247c320632ba1e401259eceae7aa2738d1.zip frameworks_base-8228e4247c320632ba1e401259eceae7aa2738d1.tar.gz frameworks_base-8228e4247c320632ba1e401259eceae7aa2738d1.tar.bz2 | |
Merge "Fix huge bounce-back in ListView when double-flinging" into mnc-dev
Diffstat (limited to 'core')
| -rw-r--r-- | core/java/android/widget/OverScroller.java | 12 |
1 files changed, 8 insertions, 4 deletions
diff --git a/core/java/android/widget/OverScroller.java b/core/java/android/widget/OverScroller.java index 451e493..98bfd7d 100644 --- a/core/java/android/widget/OverScroller.java +++ b/core/java/android/widget/OverScroller.java @@ -731,7 +731,7 @@ public class OverScroller { // mStartTime has been set mFinished = false; mState = CUBIC; - mStart = start; + mCurrentPosition = mStart = start; mFinal = end; final int delta = start - end; mDeceleration = getDeceleration(delta); @@ -797,7 +797,9 @@ public class OverScroller { private void fitOnBounceCurve(int start, int end, int velocity) { // Simulate a bounce that started from edge final float durationToApex = - velocity / mDeceleration; - final float distanceToApex = velocity * velocity / 2.0f / Math.abs(mDeceleration); + // The float cast below is necessary to avoid integer overflow. + final float velocitySquared = (float) velocity * velocity; + final float distanceToApex = velocitySquared / 2.0f / Math.abs(mDeceleration); final float distanceToEdge = Math.abs(end - start); final float totalDuration = (float) Math.sqrt( 2.0 * (distanceToApex + distanceToEdge) / Math.abs(mDeceleration)); @@ -848,12 +850,14 @@ public class OverScroller { private void onEdgeReached() { // mStart, mVelocity and mStartTime were adjusted to their values when edge was reached. - float distance = mVelocity * mVelocity / (2.0f * Math.abs(mDeceleration)); + // The float cast below is necessary to avoid integer overflow. + final float velocitySquared = (float) mVelocity * mVelocity; + float distance = velocitySquared / (2.0f * Math.abs(mDeceleration)); final float sign = Math.signum(mVelocity); if (distance > mOver) { // Default deceleration is not sufficient to slow us down before boundary - mDeceleration = - sign * mVelocity * mVelocity / (2.0f * mOver); + mDeceleration = - sign * velocitySquared / (2.0f * mOver); distance = mOver; } |
