Keep OverScroller.SplineOverScroller state consistent.

Currently update() bails out early if it is called
too soon after mStartTime has been set. In this case
mCurrentPosition remains holding an obsolete value
from a previous animation. This causes some strange
behavior (see the referenced bug).

This patch makes sure that mCurrentPosition is
updated every time that mStart is updated.

Bug: 22950559
Change-Id: I07b92f30ebe29856f4e04dc19a4820123713fd7e
This commit is contained in:
Vladislav Kaznacheev
2015-08-04 10:57:04 -07:00
parent fc5a4bf0e1
commit 84ad7e9ee2

View File

@@ -678,7 +678,7 @@ public class OverScroller {
void startScroll(int start, int distance, int duration) {
mFinished = false;
mStart = start;
mCurrentPosition = mStart = start;
mFinal = start + distance;
mStartTime = AnimationUtils.currentAnimationTimeMillis();
@@ -712,7 +712,7 @@ public class OverScroller {
boolean springback(int start, int min, int max) {
mFinished = true;
mStart = mFinal = start;
mCurrentPosition = mStart = mFinal = start;
mVelocity = 0;
mStartTime = AnimationUtils.currentAnimationTimeMillis();
@@ -804,7 +804,7 @@ public class OverScroller {
final float totalDuration = (float) Math.sqrt(
2.0 * (distanceToApex + distanceToEdge) / Math.abs(mDeceleration));
mStartTime -= (int) (1000.0f * (totalDuration - durationToApex));
mStart = end;
mCurrentPosition = mStart = end;
mVelocity = (int) (- mDeceleration * totalDuration);
}
@@ -873,7 +873,7 @@ public class OverScroller {
// Duration from start to null velocity
if (mDuration < mSplineDuration) {
// If the animation was clamped, we reached the edge
mStart = mFinal;
mCurrentPosition = mStart = mFinal;
// TODO Better compute speed when edge was reached
mVelocity = (int) mCurrVelocity;
mDeceleration = getDeceleration(mVelocity);