From 07ce61ee388360258777eb3342c87ba6128584d0 Mon Sep 17 00:00:00 2001 From: Michael Date: Thu, 5 Jan 2017 15:18:44 -0800 Subject: [PATCH] Android: add playOnce() Summary: Add `playOnce()` that will play the animation only once and stops at the end Closes https://github.com/facebookincubator/Keyframes/pull/94 Differential Revision: D4385175 Pulled By: lozzle fbshipit-source-id: 8b2f65003bfb9a3cfc040e90385369d13e1025c5 --- README.md | 3 +++ .../com/facebook/keyframes/KeyframesDrawable.java | 7 +++++++ .../keyframes/KeyframesDrawableAnimationCallback.java | 11 +++++++++++ 3 files changed, 21 insertions(+) diff --git a/README.md b/README.md index cac4191..baa3c65 100644 --- a/README.md +++ b/README.md @@ -149,6 +149,9 @@ kfDrawable.stopAnimation(); // Stops the animation when the current animation ends. kfDrawable.stopAnimationAtLoopEnd(); + +// Starts the animation and plays it once. Will stop at the end +kfDrawable.playOnce(); ``` ### Mobile Frameworks diff --git a/android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawable.java b/android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawable.java index f7f40bc..e69a360 100644 --- a/android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawable.java +++ b/android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawable.java @@ -290,6 +290,13 @@ public void startAnimation() { mKeyframesDrawableAnimationCallback.start(); } + /** + * Starts the animation and plays it once + */ + public void playOnce() { + mKeyframesDrawableAnimationCallback.playOnce(); + } + /** * Stops the animation callbacks for this drawable immediately. */ diff --git a/android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawableAnimationCallback.java b/android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawableAnimationCallback.java index a018104..72a4274 100644 --- a/android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawableAnimationCallback.java +++ b/android/keyframes/src/main/java/com/facebook/keyframes/KeyframesDrawableAnimationCallback.java @@ -104,6 +104,17 @@ public void start() { postCallback(); } + /** + * Starts the animation and plays it once + */ + public void playOnce() { + mStopAtLoopEnd = true; + mStartTimeMillis = 0; + mCurrentLoopNumber = 0; + cancelCallback(); + postCallback(); + } + /** * Stops the callbacks animation and resets the start time. */