From 3b466875bc9b931fce339b95aeaa7d19bb3fc640 Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Fri, 3 Feb 2017 16:49:20 -0800 Subject: [PATCH] Fix start delay for ValueAnimator This CL ensures that doAnimationFrame() is called the frame after start() is called, so that AnimatorSet can pulse frames into single animators as soon as they are start()'ed. Test: new cts test in same topic branch Change-Id: I4f9522ce9e1a54ca3bcad6c696e6b248c945ff90 --- core/java/android/animation/ValueAnimator.java | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java index 470523fc42522..2ffc574a974cb 100644 --- a/core/java/android/animation/ValueAnimator.java +++ b/core/java/android/animation/ValueAnimator.java @@ -631,13 +631,16 @@ public class ValueAnimator extends Animator { public void setCurrentFraction(float fraction) { initAnimation(); fraction = clampFraction(fraction); - long seekTime = (long) (getScaledDuration() * fraction); - long currentTime = AnimationUtils.currentAnimationTimeMillis(); - mStartTime = currentTime - seekTime; mStartTimeCommitted = true; // do not allow start time to be compensated for jank - if (!isPulsingInternal()) { - // If the animation loop hasn't started, the startTime will be adjusted in the first - // frame based on seek fraction. + if (isPulsingInternal()) { + long seekTime = (long) (getScaledDuration() * fraction); + long currentTime = AnimationUtils.currentAnimationTimeMillis(); + // Only modify the start time when the animation is running. Seek fraction will ensure + // non-running animations skip to the correct start time. + mStartTime = currentTime - seekTime; + } else { + // If the animation loop hasn't started, or during start delay, the startTime will be + // adjusted once the delay has passed based on seek fraction. mSeekFraction = fraction; } mOverallFraction = fraction; @@ -1022,7 +1025,7 @@ public class ValueAnimator extends Animator { // started-but-not-yet-reached-the-first-frame phase. mLastFrameTime = -1; mFirstFrameTime = -1; - addAnimationCallback((long) (mStartDelay * sDurationScale)); + addAnimationCallback(0); if (mStartDelay == 0 || mSeekFraction >= 0 || mReversing) { // If there's no start delay, init the animation and notify start listeners right away