am 8228e424: Merge "Fix huge bounce-back in ListView when double-flinging" into mnc-dev
* commit '8228e4247c320632ba1e401259eceae7aa2738d1': Fix huge bounce-back in ListView when double-flinging
This commit is contained in:
committed by
Android Git Automerger
commit
01acdd9fea
@@ -731,7 +731,7 @@ public class OverScroller {
|
|||||||
// mStartTime has been set
|
// mStartTime has been set
|
||||||
mFinished = false;
|
mFinished = false;
|
||||||
mState = CUBIC;
|
mState = CUBIC;
|
||||||
mStart = start;
|
mCurrentPosition = mStart = start;
|
||||||
mFinal = end;
|
mFinal = end;
|
||||||
final int delta = start - end;
|
final int delta = start - end;
|
||||||
mDeceleration = getDeceleration(delta);
|
mDeceleration = getDeceleration(delta);
|
||||||
@@ -797,7 +797,9 @@ public class OverScroller {
|
|||||||
private void fitOnBounceCurve(int start, int end, int velocity) {
|
private void fitOnBounceCurve(int start, int end, int velocity) {
|
||||||
// Simulate a bounce that started from edge
|
// Simulate a bounce that started from edge
|
||||||
final float durationToApex = - velocity / mDeceleration;
|
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 distanceToEdge = Math.abs(end - start);
|
||||||
final float totalDuration = (float) Math.sqrt(
|
final float totalDuration = (float) Math.sqrt(
|
||||||
2.0 * (distanceToApex + distanceToEdge) / Math.abs(mDeceleration));
|
2.0 * (distanceToApex + distanceToEdge) / Math.abs(mDeceleration));
|
||||||
@@ -848,12 +850,14 @@ public class OverScroller {
|
|||||||
|
|
||||||
private void onEdgeReached() {
|
private void onEdgeReached() {
|
||||||
// mStart, mVelocity and mStartTime were adjusted to their values when edge was reached.
|
// 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);
|
final float sign = Math.signum(mVelocity);
|
||||||
|
|
||||||
if (distance > mOver) {
|
if (distance > mOver) {
|
||||||
// Default deceleration is not sufficient to slow us down before boundary
|
// 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;
|
distance = mOver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user