diff options
author | Bo Duan <boduan402@gmail.com> | 2019-11-06 15:23:18 -0800 |
---|---|---|
committer | Gabriel Peal <gpeal@users.noreply.github.com> | 2019-11-06 15:23:18 -0800 |
commit | 3a5d706bad862a4eec9e3b4bc10a0c693077987e (patch) | |
tree | 31700dc97133678f86121e890f6b527dd1354acc | |
parent | 3cf8ff4e79abefeb18dfa0c5d73ed72bfe5318b9 (diff) | |
download | lottie-3a5d706bad862a4eec9e3b4bc10a0c693077987e.tar.gz |
Improve testability when systemAnimation is disabled. (#1420)
- render the very last frame.
- call animation end in case app listens to the callback.
-rw-r--r-- | lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java | 8 | ||||
-rw-r--r-- | lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java | 40 |
2 files changed, 47 insertions, 1 deletions
diff --git a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java index bf999de7..17a21ce9 100644 --- a/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java +++ b/lottie/src/main/java/com/airbnb/lottie/LottieDrawable.java @@ -402,6 +402,7 @@ public class LottieDrawable extends Drawable implements Drawable.Callback, Anima } if (!systemAnimationsEnabled) { setFrame((int) (getSpeed() < 0 ? getMinFrame() : getMaxFrame())); + animator.endAnimation(); } } @@ -426,9 +427,14 @@ public class LottieDrawable extends Drawable implements Drawable.Callback, Anima }); return; } - if (systemAnimationsEnabled) { + + if (systemAnimationsEnabled || getRepeatCount() == 0) { animator.resumeAnimation(); } + if (!systemAnimationsEnabled) { + setFrame((int) (getSpeed() < 0 ? getMinFrame() : getMaxFrame())); + animator.endAnimation(); + } } /** diff --git a/lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java b/lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java index 263d5f97..7d3f2e61 100644 --- a/lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java +++ b/lottie/src/test/java/com/airbnb/lottie/LottieDrawableTest.java @@ -1,5 +1,6 @@ package com.airbnb.lottie; +import android.animation.Animator; import android.graphics.Rect; import androidx.collection.LongSparseArray; import androidx.collection.SparseArrayCompat; @@ -7,16 +8,31 @@ import com.airbnb.lottie.model.Font; import com.airbnb.lottie.model.FontCharacter; import com.airbnb.lottie.model.Marker; import com.airbnb.lottie.model.layer.Layer; + +import org.junit.Before; import org.junit.Test; +import org.mockito.Mock; +import org.mockito.MockitoAnnotations; import java.util.ArrayList; import java.util.HashMap; import java.util.List; import static junit.framework.Assert.assertEquals; +import static org.mockito.ArgumentMatchers.any; +import static org.mockito.ArgumentMatchers.eq; +import static org.mockito.Mockito.atLeastOnce; +import static org.mockito.Mockito.verify; public class LottieDrawableTest extends BaseTest { + @Mock Animator.AnimatorListener animatorListener; + + @Before + public void setup() { + MockitoAnnotations.initMocks(this); + } + @SuppressWarnings("SameParameterValue") private LottieComposition createComposition(int startFrame, int endFrame) { LottieComposition composition = new LottieComposition(); @@ -63,4 +79,28 @@ public class LottieDrawableTest extends BaseTest { assertEquals(121f, drawable.getMinFrame()); assertEquals(182.99f, drawable.getMaxFrame()); } + + @Test + public void testPlayWhenSystemAnimationDisabled() { + LottieComposition composition = createComposition(31, 391); + LottieDrawable drawable = new LottieDrawable(); + drawable.addAnimatorListener(animatorListener); + drawable.setSystemAnimationsAreEnabled(false); + drawable.setComposition(composition); + drawable.playAnimation(); + assertEquals(391, drawable.getFrame()); + verify(animatorListener, atLeastOnce()).onAnimationEnd(any(Animator.class), eq(false)); + } + + @Test + public void testResumeWhenSystemAnimationDisabled() { + LottieComposition composition = createComposition(31, 391); + LottieDrawable drawable = new LottieDrawable(); + drawable.addAnimatorListener(animatorListener); + drawable.setSystemAnimationsAreEnabled(false); + drawable.setComposition(composition); + drawable.resumeAnimation(); + assertEquals(391, drawable.getFrame()); + verify(animatorListener, atLeastOnce()).onAnimationEnd(any(Animator.class), eq(false)); + } } |