diff options
| author | 2016-06-13 20:31:32 +0000 | |
|---|---|---|
| committer | 2016-06-13 20:31:32 +0000 | |
| commit | a28f0003eb27edbe298ce36c0e6b70dde42a4f09 (patch) | |
| tree | e4259e36d5858ad5ee5798abc21cca0c87014e6a | |
| parent | fead52ebf412b2aa3e4b55c16991d8d3ad488f69 (diff) | |
| parent | 42d39300cf7554a37ad26c1f06c18ae614b09e7f (diff) | |
Merge \"Fix setCurrentPlayTime for started but not yet pulsed animations\" into nyc-dev
am: 42d39300cf
Change-Id: I7c1f2adb31ece266b082ffb9ea85b17c083b518c
| -rw-r--r-- | core/java/android/animation/ValueAnimator.java | 20 |
1 files changed, 18 insertions, 2 deletions
diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java index 4edf249ce065..0c7ee2c8c2fe 100644 --- a/core/java/android/animation/ValueAnimator.java +++ b/core/java/android/animation/ValueAnimator.java @@ -602,7 +602,9 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio long currentTime = AnimationUtils.currentAnimationTimeMillis(); mStartTime = currentTime - seekTime; mStartTimeCommitted = true; // do not allow start time to be compensated for jank - if (!mRunning) { + if (!isPulsingInternal()) { + // If the animation loop hasn't started, the startTime will be adjusted in the first + // frame based on seek fraction. mSeekFraction = fraction; } mOverallFraction = fraction; @@ -980,6 +982,10 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio mStarted = true; mPaused = false; mRunning = false; + // Resets mLastFrameTime when start() is called, so that if the animation was running, + // calling start() would put the animation in the + // started-but-not-yet-reached-the-first-frame phase. + mLastFrameTime = 0; AnimationHandler animationHandler = AnimationHandler.getInstance(); animationHandler.addAnimationFrameCallback(this, (long) (mStartDelay * sDurationScale)); @@ -1095,7 +1101,7 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio */ @Override public void reverse() { - if (mRunning) { + if (isPulsingInternal()) { long currentTime = AnimationUtils.currentAnimationTimeMillis(); long currentPlayTime = currentTime - mStartTime; long timeLeft = getScaledDuration() - currentPlayTime; @@ -1103,6 +1109,7 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio mStartTimeCommitted = true; // do not allow start time to be compensated for jank mReversing = !mReversing; } else if (mStarted) { + mReversing = !mReversing; end(); } else { start(true); @@ -1177,6 +1184,15 @@ public class ValueAnimator extends Animator implements AnimationHandler.Animatio } /** + * Internal only: This tracks whether the animation has gotten on the animation loop. Note + * this is different than {@link #isRunning()} in that the latter tracks the time after start() + * is called (or after start delay if any), which may be before the animation loop starts. + */ + private boolean isPulsingInternal() { + return mLastFrameTime > 0; + } + + /** * Returns the name of this animator for debugging purposes. */ String getNameForTrace() { |