Search in sources :

Example 1 with TestAnimatedDrawableBackend

use of com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend in project fresco by facebook.

the class AnimatedDrawableCachingBackendImplTest method setup.

@Before
public void setup() {
    mActivityManager = (ActivityManager) RuntimeEnvironment.application.getSystemService(Context.ACTIVITY_SERVICE);
    mFakeClock = new FakeClock();
    mExecutorService = new TestExecutorService(mFakeClock);
    mAnimatedDrawableUtil = new AnimatedDrawableUtil();
    mDrawableBackend = new TestAnimatedDrawableBackend(WIDTH, HEIGHT, FRAME_DURATIONS);
}
Also used : TestAnimatedDrawableBackend(com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend) FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestExecutorService(com.facebook.imagepipeline.testing.TestExecutorService) AnimatedDrawableUtil(com.facebook.imagepipeline.animated.util.AnimatedDrawableUtil) Before(org.junit.Before)

Example 2 with TestAnimatedDrawableBackend

use of com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend in project fresco by facebook.

the class AnimatedDrawableTest method setup.

@Before
public void setup() {
    mFakeClock = new FakeClock();
    mTestScheduledExecutorService = new TestScheduledExecutorService(mFakeClock);
    mBackend = new TestAnimatedDrawableBackend(WIDTH, HEIGHT, FRAME_DURATIONS);
    mCachingBackend = new TestAnimatedDrawableCachingBackend(mBackend);
    mCallback = new MyCallback(mFakeClock);
    mDrawable = new AnimatedDrawable(mTestScheduledExecutorService, mCachingBackend, AnimatedDrawableDiagnosticsNoop.getInstance(), mFakeClock);
    mDrawable.setCallback(mCallback);
}
Also used : TestAnimatedDrawableBackend(com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend) FakeClock(com.facebook.imagepipeline.testing.FakeClock) TestScheduledExecutorService(com.facebook.imagepipeline.testing.TestScheduledExecutorService) Before(org.junit.Before)

Example 3 with TestAnimatedDrawableBackend

use of com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend in project fresco by facebook.

the class AnimatedDrawableTest method testDoNotDropCacheIfFramesAreLongDurationSpecialCase.

@Test
public void testDoNotDropCacheIfFramesAreLongDurationSpecialCase() {
    mBackend = new TestAnimatedDrawableBackend(WIDTH, HEIGHT, FRAME_DURATIONS_LONG);
    mCachingBackend = new TestAnimatedDrawableCachingBackend(mBackend);
    mCallback = new MyCallback(mFakeClock);
    mDrawable = new AnimatedDrawable(mTestScheduledExecutorService, mCachingBackend, AnimatedDrawableDiagnosticsNoop.getInstance(), mFakeClock);
    mDrawable.setCallback(mCallback);
    Bitmap bitmap = Bitmap.createBitmap(WIDTH, HEIGHT, Bitmap.Config.ARGB_8888);
    Canvas canvas = new Canvas(bitmap);
    prepareDrawable();
    // Draw and advance to next frame.
    mDrawable.draw(canvas);
    // After 10 seconds, it should move to the next frame. It shouldn't drop the caches though
    // until it's 2 seconds after the invalidate.
    assertFalse(mDrawable.isWaitingForDraw());
    assertTrue(mDrawable.isWaitingForNextFrame());
    assertEquals(0, mDrawable.getScheduledFrameNumber());
    mFakeClock.incrementBy(10000);
    assertTrue(mDrawable.isWaitingForDraw());
    assertFalse(mDrawable.isWaitingForNextFrame());
    assertEquals(1, mDrawable.getScheduledFrameNumber());
    assertEquals(1, mBackend.getDropCachesCallCount());
    mFakeClock.incrementBy(1000);
    assertEquals(1, mBackend.getDropCachesCallCount());
    mFakeClock.incrementBy(2000);
    assertEquals(2, mBackend.getDropCachesCallCount());
}
Also used : TestAnimatedDrawableBackend(com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend) MyShadowBitmap(com.facebook.imagepipeline.animated.testing.MyShadowBitmap) Bitmap(android.graphics.Bitmap) Canvas(android.graphics.Canvas) MyShadowCanvas(com.facebook.imagepipeline.animated.testing.MyShadowCanvas) Test(org.junit.Test)

Aggregations

TestAnimatedDrawableBackend (com.facebook.imagepipeline.animated.testing.TestAnimatedDrawableBackend)3 FakeClock (com.facebook.imagepipeline.testing.FakeClock)2 Before (org.junit.Before)2 Bitmap (android.graphics.Bitmap)1 Canvas (android.graphics.Canvas)1 MyShadowBitmap (com.facebook.imagepipeline.animated.testing.MyShadowBitmap)1 MyShadowCanvas (com.facebook.imagepipeline.animated.testing.MyShadowCanvas)1 AnimatedDrawableUtil (com.facebook.imagepipeline.animated.util.AnimatedDrawableUtil)1 TestExecutorService (com.facebook.imagepipeline.testing.TestExecutorService)1 TestScheduledExecutorService (com.facebook.imagepipeline.testing.TestScheduledExecutorService)1 Test (org.junit.Test)1