Fix ValueAnimator.getCurrentPlayTime()
Return a valid value for the current play time if the animator has
been seeked to a play time or fraction, but not yet started.
Issue #24717972 animator.getCurrentPlayTime() is all messed up
Change-Id: I15f1329b65410b4b0366a23a3419b5987305a865
diff --git a/core/java/android/animation/ValueAnimator.java b/core/java/android/animation/ValueAnimator.java
index 1995ef5..9b905bd 100644
--- a/core/java/android/animation/ValueAnimator.java
+++ b/core/java/android/animation/ValueAnimator.java
@@ -625,14 +625,19 @@
/**
* Gets the current position of the animation in time, which is equal to the current
* time minus the time that the animation started. An animation that is not yet started will
- * return a value of zero.
+ * return a value of zero, unless the animation has has its play time set via
+ * {@link #setCurrentPlayTime(long)} or {@link #setCurrentFraction(float)}, in which case
+ * it will return the time that was set.
*
* @return The current position in time of the animation.
*/
public long getCurrentPlayTime() {
- if (!mInitialized || !mStarted) {
+ if (!mInitialized || (!mStarted && mSeekFraction < 0)) {
return 0;
}
+ if (mSeekFraction >= 0) {
+ return (long) (mUnscaledDuration * mSeekFraction);
+ }
return AnimationUtils.currentAnimationTimeMillis() - mStartTime;
}