From dd65ab04071fd80007155e8cb4b205370acf759b Mon Sep 17 00:00:00 2001 From: Doris Liu Date: Wed, 8 Feb 2017 14:51:54 -0800 Subject: [PATCH] Add getter for current play time BUG: 30993532 Test: cts tests in the same topic branch Change-Id: I45ee9c61f53051fcac3399eebc378aa2c0ce056d --- api/current.txt | 1 + api/system-current.txt | 1 + api/test-current.txt | 1 + core/java/android/animation/AnimatorSet.java | 25 ++++++++++++++++++++ 4 files changed, 28 insertions(+) diff --git a/api/current.txt b/api/current.txt index e2720f27f2636..62dd5a03919f6 100644 --- a/api/current.txt +++ b/api/current.txt @@ -3137,6 +3137,7 @@ package android.animation { public final class AnimatorSet extends android.animation.Animator { ctor public AnimatorSet(); method public java.util.ArrayList getChildAnimations(); + method public long getCurrentPlayTime(); method public long getDuration(); method public long getStartDelay(); method public boolean isRunning(); diff --git a/api/system-current.txt b/api/system-current.txt index 14120aff98f49..e3cf39ef34070 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -3257,6 +3257,7 @@ package android.animation { public final class AnimatorSet extends android.animation.Animator { ctor public AnimatorSet(); method public java.util.ArrayList getChildAnimations(); + method public long getCurrentPlayTime(); method public long getDuration(); method public long getStartDelay(); method public boolean isRunning(); diff --git a/api/test-current.txt b/api/test-current.txt index 4fb669ad4752e..2bd4192096996 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -3137,6 +3137,7 @@ package android.animation { public final class AnimatorSet extends android.animation.Animator { ctor public AnimatorSet(); method public java.util.ArrayList getChildAnimations(); + method public long getCurrentPlayTime(); method public long getDuration(); method public long getStartDelay(); method public boolean isRunning(); diff --git a/core/java/android/animation/AnimatorSet.java b/core/java/android/animation/AnimatorSet.java index f2533917f828c..2940e865b31be 100644 --- a/core/java/android/animation/AnimatorSet.java +++ b/core/java/android/animation/AnimatorSet.java @@ -934,6 +934,31 @@ public final class AnimatorSet extends Animator implements AnimationHandler.Anim } } + /** + * 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, unless the animation has has its play time set via + * {@link #setCurrentPlayTime(long)}, in which case it will return the time that was set. + * + * @return The current position in time of the animation. + */ + public long getCurrentPlayTime() { + if (mSeekState.isActive()) { + return mSeekState.getPlayTime(); + } + if (mLastFrameTime == -1) { + // Not yet started or during start delay + return 0; + } + float durationScale = ValueAnimator.getDurationScale(); + durationScale = durationScale == 0 ? 1 : durationScale; + if (mReversing) { + return (long) ((mLastFrameTime - mFirstFrame) / durationScale); + } else { + return (long) ((mLastFrameTime - mFirstFrame - mStartDelay) / durationScale); + } + } + private void initChildren() { if (!isInitialized()) { mChildrenInitialized = true;