@@ -102,20 +102,26 @@ public void run() {
102102 final long frameTimeNanos = mChoreographer .getFrameTimeNanos ();
103103 final float timeDelta = (frameTimeNanos - mLastFrameTimeNanos )
104104 * 0.000000001f ;
105- final float amount = timeDelta * mRate / ValueAnimator .getDurationScale ();
106105 mLastFrameTimeNanos = frameTimeNanos ;
107106
108107 // Advance the animated value towards the target at the specified rate
109108 // and clamp to the target. This gives us the new current value but
110109 // we keep the animated value around to allow for fractional increments
111110 // towards the target.
112- int oldCurrentValue = mCurrentValue ;
113- if (mTargetValue > mCurrentValue ) {
114- mAnimatedValue = Math .min (mAnimatedValue + amount , mTargetValue );
111+ final float scale = ValueAnimator .getDurationScale ();
112+ if (scale == 0 ) {
113+ // Animation off.
114+ mAnimatedValue = mTargetValue ;
115115 } else {
116- mAnimatedValue = Math .max (mAnimatedValue - amount , mTargetValue );
116+ final float amount = timeDelta * mRate / scale ;
117+ if (mTargetValue > mCurrentValue ) {
118+ mAnimatedValue = Math .min (mAnimatedValue + amount , mTargetValue );
119+ } else {
120+ mAnimatedValue = Math .max (mAnimatedValue - amount , mTargetValue );
121+ }
117122 }
118- mCurrentValue = (int )Math .round (mAnimatedValue );
123+ final int oldCurrentValue = mCurrentValue ;
124+ mCurrentValue = Math .round (mAnimatedValue );
119125
120126 if (oldCurrentValue != mCurrentValue ) {
121127 mProperty .setValue (mObject , mCurrentValue );
0 commit comments