use of com.facebook.drawee.drawable.FadeDrawable in project fresco by facebook.
the class GenericDraweeHierarchyTest method testControlling_WithPlaceholderOnly.
@Test
public void testControlling_WithPlaceholderOnly() throws Exception {
GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage, null).setActualImageScaleType(null).setFadeDuration(250).build();
// image indexes in DH tree
final int placeholderImageIndex = 1;
final int actualImageIndex = 2;
FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
assertEquals(mPlaceholderImage, fadeDrawable.getDrawable(placeholderImageIndex));
assertEquals(ForwardingDrawable.class, fadeDrawable.getDrawable(actualImageIndex).getClass());
ForwardingDrawable actualImageSettableDrawable = (ForwardingDrawable) fadeDrawable.getDrawable(actualImageIndex);
// initial state -> final image (non-immediate)
// initial state
assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set final image (non-immediate)
dh.setImage(mActualImage1, 1f, false);
assertEquals(mActualImage1, actualImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
// initial state -> final image (immediate)
// reset hierarchy to initial state
dh.reset();
assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set final image (immediate)
dh.setImage(mActualImage2, 1f, true);
assertEquals(mActualImage2, actualImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// initial state -> retry
// reset hierarchy to initial state
dh.reset();
assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set retry
dh.setRetry(new RuntimeException());
assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
// initial state -> failure
// reset hierarchy to initial state
dh.reset();
assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set failure
dh.setFailure(new RuntimeException());
assertEquals(ColorDrawable.class, actualImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
}
use of com.facebook.drawee.drawable.FadeDrawable in project fresco by facebook.
the class GenericDraweeHierarchyTest method testControlling_WithAllLayers.
@Test
public void testControlling_WithAllLayers() throws Exception {
GenericDraweeHierarchy dh = mBuilder.setBackground(mBackground).setOverlays(Arrays.asList(mOverlay1, mOverlay2)).setPlaceholderImage(mPlaceholderImage, null).setRetryImage(mRetryImage, null).setFailureImage(mFailureImage, null).setProgressBarImage(mProgressBarImage, null).setActualImageScaleType(null).setFadeDuration(250).build();
// image indexes in DH tree
final int backgroundIndex = 0;
final int placeholderImageIndex = 1;
final int actualImageIndex = 2;
final int progressBarImageIndex = 3;
final int retryImageIndex = 4;
final int failureImageIndex = 5;
final int overlaysIndex = 6;
int numOverlays = 2;
FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
assertEquals(mPlaceholderImage, fadeDrawable.getDrawable(placeholderImageIndex));
assertEquals(mProgressBarImage, fadeDrawable.getDrawable(progressBarImageIndex));
assertEquals(mRetryImage, fadeDrawable.getDrawable(retryImageIndex));
assertEquals(mFailureImage, fadeDrawable.getDrawable(failureImageIndex));
assertEquals(ForwardingDrawable.class, fadeDrawable.getDrawable(actualImageIndex).getClass());
ForwardingDrawable finalImageSettableDrawable = (ForwardingDrawable) fadeDrawable.getDrawable(actualImageIndex);
// initial state -> final image (immediate)
// initial state, show progress bar
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
dh.setProgress(0f, true);
assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set final image (immediate)
dh.setImage(mActualImage2, 1f, true);
assertEquals(mActualImage2, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// initial state -> final image (non-immediate)
// reset hierarchy to initial state, show progress bar
dh.reset();
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
dh.setProgress(0f, true);
assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set final image (non-immediate)
dh.setImage(mActualImage2, 1f, false);
assertEquals(mActualImage2, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
// initial state -> temporary image (immediate) -> final image (non-immediate)
// reset hierarchy to initial state, show progress bar
dh.reset();
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
dh.setProgress(0f, true);
assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set temporary image (immediate)
dh.setImage(mActualImage1, 0.5f, true);
assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set final image (non-immediate)
dh.setImage(mActualImage2, 1f, false);
assertEquals(mActualImage2, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
// initial state -> temporary image (non-immediate) -> final image (non-immediate)
// reset hierarchy to initial state, show progress bar
dh.reset();
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
dh.setProgress(0f, true);
assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set temporary image (non-immediate)
dh.setImage(mActualImage1, 0.5f, false);
assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
// set final image (non-immediate)
dh.setImage(mActualImage2, 1f, false);
assertEquals(mActualImage2, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
// initial state -> temporary image (immediate) -> retry
// reset hierarchy to initial state, show progress bar
dh.reset();
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
dh.setProgress(0f, true);
assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set temporary image (immediate)
dh.setImage(mActualImage1, 0.5f, true);
assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set retry
dh.setRetry(new RuntimeException());
assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
// initial state -> temporary image (immediate) -> failure
// reset hierarchy to initial state, show progress bar
dh.reset();
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
dh.setProgress(0f, true);
assertEquals(ColorDrawable.class, finalImageSettableDrawable.getCurrent().getClass());
assertEquals(true, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set temporary image (immediate)
dh.setImage(mActualImage1, 0.5f, true);
assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState());
// set failure
dh.setFailure(new RuntimeException());
assertEquals(mActualImage1, finalImageSettableDrawable.getCurrent());
assertEquals(false, fadeDrawable.isLayerOn(placeholderImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(actualImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(progressBarImageIndex));
assertEquals(false, fadeDrawable.isLayerOn(retryImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(failureImageIndex));
assertEquals(true, fadeDrawable.isLayerOn(backgroundIndex));
assertLayersOn(fadeDrawable, overlaysIndex, numOverlays);
assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState());
assertEquals(250, fadeDrawable.getTransitionDuration());
}
use of com.facebook.drawee.drawable.FadeDrawable in project fresco by facebook.
the class GenericDraweeHierarchyTest method testHierarchy_WithProgressBarImage.
@Test
public void testHierarchy_WithProgressBarImage() throws Exception {
GenericDraweeHierarchy dh = mBuilder.setProgressBarImage(mProgressBarImage, ScaleType.CENTER).build();
RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent();
assertScaleTypeAndDrawable(mProgressBarImage, ScaleType.CENTER, fadeDrawable.getDrawable(3));
verifyCallback(rootDrawable, mProgressBarImage);
}
use of com.facebook.drawee.drawable.FadeDrawable in project fresco by facebook.
the class GenericDraweeHierarchyTest method testHierarchy_WithSingleOverlay.
@Test
public void testHierarchy_WithSingleOverlay() throws Exception {
GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage, null).setOverlay(mOverlay1).build();
RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable();
FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent();
assertEquals(7, fadeDrawable.getNumberOfLayers());
assertSame(mOverlay1, fadeDrawable.getDrawable(6));
verifyCallback(rootDrawable, mOverlay1);
}
use of com.facebook.drawee.drawable.FadeDrawable in project fresco by facebook.
the class GenericDraweeHierarchyTest method testSetActualImageFocusPoint.
@Test
public void testSetActualImageFocusPoint() {
GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage).setProgressBarImage(mProgressBarImage).setActualImageScaleType(ScaleType.FOCUS_CROP).build();
// actual image index in DH tree
final int imageIndex = 2;
FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent();
ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) fadeDrawable.getDrawable(imageIndex);
assertNull(scaleTypeDrawable.getFocusPoint());
PointF focus1 = new PointF(0.3f, 0.4f);
dh.setActualImageFocusPoint(focus1);
AndroidGraphicsTestUtils.assertEquals(focus1, scaleTypeDrawable.getFocusPoint(), 0f);
PointF focus2 = new PointF(0.6f, 0.7f);
dh.setActualImageFocusPoint(focus2);
AndroidGraphicsTestUtils.assertEquals(focus2, scaleTypeDrawable.getFocusPoint(), 0f);
}
Aggregations