/** * Starts the animation from the first frame. Can only be called while animation is not running. */ // Public API. @SuppressWarnings("unused") public void startFromFirstFrame() { Preconditions.checkArgument(!isRunning, "You cannot restart a currently running animation."); state.frameLoader.setNextStartFromFirstFrame(); start(); }
@Test public void testRequestsNextFrameOnStartWithoutCallToSetVisible() { drawable.start(); verify(frameLoader).subscribe(eq(drawable)); }
@Test public void testDoesNotRequestNextFrameOnStartIfGotCallToSetVisibleWithVisibleFalse() { drawable.setVisible(false, false); drawable.start(); verify(frameLoader, never()).subscribe(eq(drawable)); }
@Test public void testShouldInvalidateSelfOnRun() { drawable.setVisible(true, true); drawable.start(); verify(cb).invalidateDrawable(eq(drawable)); }
@Test public void testDoesNotRequestNextFrameOnStartIfHasSingleFrame() { when(frameLoader.getFrameCount()).thenReturn(1); drawable.setVisible(true, false); drawable.start(); verify(frameLoader, never()).subscribe(eq(drawable)); }
@Test public void testRequestsNextFrameOnStart() { drawable.setVisible(true, true); drawable.start(); verify(frameLoader).subscribe(eq(drawable)); }
@Test public void testInvalidatesSelfOnStartIfHasSingleFrame() { when(frameLoader.getFrameCount()).thenReturn(1); drawable.setVisible(true, false); drawable.start(); verify(cb).invalidateDrawable(eq(drawable)); }
@Test public void testDoesNotDrawFrameAfterRecycle() { Bitmap bitmap = Bitmap.createBitmap(100, 112341, Bitmap.Config.RGB_565); drawable.setVisible(true, true); drawable.start(); when(frameLoader.getCurrentFrame()).thenReturn(bitmap); drawable.onFrameReady(); drawable.recycle(); Canvas canvas = mock(Canvas.class); drawable.draw(canvas); verify(canvas, never()).drawBitmap(eq(bitmap), isARect(), isARect(), isAPaint()); }
@Test public void testLoopsForeverIfLoopCountIsLoopIntrinsicAndTotalIterationCountIsForever() { final int frameCount = 3; final int loopCount = 40; when(frameLoader.getLoopCount()).thenReturn(GifDecoder.TOTAL_ITERATION_COUNT_FOREVER); when(frameLoader.getFrameCount()).thenReturn(frameCount); drawable.setLoopCount(GifDrawable.LOOP_INTRINSIC); drawable.setVisible(true, true); drawable.start(); runLoops(loopCount, frameCount); verifyRanLoops(loopCount, frameCount); assertTrue("drawable should be still running", drawable.isRunning()); }
@Test public void testReturnsTrueFromIsRunningWhenRunning() { drawable.setVisible(true, true); drawable.start(); assertTrue(drawable.isRunning()); }
@Test public void testSetsIsRunningFalseOnStop() { drawable.start(); drawable.stop(); assertFalse(drawable.isRunning()); }
@Test public void testLoopsASingleTimeIfLoopCountIsSetToOne() { final int loopCount = 1; final int frameCount = 2; when(frameLoader.getFrameCount()).thenReturn(frameCount); drawable.setLoopCount(loopCount); drawable.setVisible(true, true); drawable.start(); runLoops(loopCount, frameCount); verifyRanLoops(loopCount, frameCount); assertFalse("drawable should be stopped after loop is completed", drawable.isRunning()); }
@Test public void onFrameReady_whenAttachedtoDrawableCallbackWithViewCallbackParent_doesNotStop() { TransitionDrawable topLevel = new TransitionDrawable(new Drawable[] { drawable }); drawable.setCallback(topLevel); topLevel.setCallback(new View(context)); drawable.start(); drawable.onFrameReady(); assertThat(drawable.isRunning()).isTrue(); }
@Test public void testLoopsThreeTimesIfLoopCountIsSetToThree() { final int loopCount = 3; final int frameCount = 2; when(frameLoader.getFrameCount()).thenReturn(frameCount); drawable.setLoopCount(loopCount); drawable.setVisible(true, true); drawable.start(); runLoops(loopCount, frameCount); verifyRanLoops(loopCount, frameCount); assertFalse("drawable should be stopped after loop is completed", drawable.isRunning()); }
@Test public void testStartsOnSetVisibleTrueIfRunning() { drawable.start(); drawable.setVisible(false, false); drawable.setVisible(true, true); assertTrue(drawable.isRunning()); }
@Test public void testLoopsForeverIfLoopCountIsSetToLoopForever() { final int loopCount = 40; final int frameCount = 2; when(frameLoader.getFrameCount()).thenReturn(frameCount); drawable.setLoopCount(GifDrawable.LOOP_FOREVER); drawable.setVisible(true, true); drawable.start(); runLoops(loopCount, frameCount); verifyRanLoops(loopCount, frameCount); assertTrue("drawable should be still running", drawable.isRunning()); }
@Test public void testLoopsOnceIfLoopCountIsSetToOneWithThreeFrames() { final int loopCount = 1; final int frameCount = 3; when(frameLoader.getFrameCount()).thenReturn(frameCount); drawable.setLoopCount(loopCount); drawable.setVisible(true, true); drawable.start(); runLoops(loopCount, frameCount); verifyRanLoops(loopCount, frameCount); assertFalse("drawable should be stopped after loop is completed", drawable.isRunning()); }
@Test public void testDoesNotStartOnSetVisibleIfStartedAndStopped() { drawable.start(); drawable.stop(); drawable.setVisible(true, true); assertFalse(drawable.isRunning()); }
@Test public void onFrameReady_whenAttachedToDrawableCallbackButNotViewCallback_stops() { TransitionDrawable topLevel = new TransitionDrawable(new Drawable[] { drawable }); drawable.setCallback(topLevel); topLevel.setCallback(null); drawable.start(); drawable.onFrameReady(); assertThat(drawable.isRunning()).isFalse(); }