Java Code Examples for com.facebook.drawee.drawable.FadeDrawable#getDrawable()
The following examples show how to use
com.facebook.drawee.drawable.FadeDrawable#getDrawable() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 6 votes |
@Test public void testHierarchy_WithRoundedLeafs() throws Exception { RoundingParams roundingParams = RoundingParams.asCircle(); GenericDraweeHierarchy dh = mBuilder .setPlaceholderImage(mWrappedImage, ScaleType.CENTER) .setFailureImage(mFailureImage, ScaleType.CENTER) .setRetryImage(mRetryImage, null) .setRoundingParams(roundingParams) .build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertNotNull(fadeDrawable); assertScaleTypeAndDrawable(mWrappedImage, ScaleType.CENTER, fadeDrawable.getDrawable(1)); Rounded roundedPlaceholder = (Rounded) mWrappedImage.getCurrent().getCurrent(); assertRoundingParams(roundingParams, roundedPlaceholder); Rounded roundedFailureImage = (Rounded) fadeDrawable.getDrawable(5).getCurrent(); assertRoundingParams(roundingParams, roundedFailureImage); Rounded roundedRetryImage = (Rounded) fadeDrawable.getDrawable(4); assertRoundingParams(roundingParams, roundedRetryImage); verifyCallback(rootDrawable, mWrappedImage.getCurrent().getCurrent()); verifyCallback(rootDrawable, (Drawable) roundedFailureImage); verifyCallback(rootDrawable, (Drawable) roundedRetryImage); }
Example 2
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 6 votes |
@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); }
Example 3
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 6 votes |
@Test public void testSetActualImageScaleType() { GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage).build(); // actual image index in DH tree final int imageIndex = 2; FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent(); ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) fadeDrawable.getDrawable(imageIndex); ScaleType scaleType1 = ScaleType.FOCUS_CROP; dh.setActualImageScaleType(scaleType1); assertEquals(scaleType1, scaleTypeDrawable.getScaleType()); ScaleType scaleType2 = ScaleType.CENTER; dh.setActualImageScaleType(scaleType2); assertEquals(scaleType2, scaleTypeDrawable.getScaleType()); }
Example 4
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithPressedStateOverlay() throws Exception { GenericDraweeHierarchy dh = mBuilder.setOverlay(mOverlay2).setPressedStateOverlay(mOverlay1).build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(8, fadeDrawable.getNumberOfLayers()); assertSame(mOverlay2, fadeDrawable.getDrawable(6)); StateListDrawable stateListDrawable = (StateListDrawable) fadeDrawable.getDrawable(7); assertNotNull(stateListDrawable); }
Example 5
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testControlling_WithCornerRadii() throws Exception { GenericDraweeHierarchy dh = mBuilder .setPlaceholderImage(mPlaceholderImage, null) .setActualImageScaleType(null) .setRoundingParams(RoundingParams.fromCornersRadius(10)) .setFadeDuration(250) .build(); // actual image index in DH tree final int imageIndex = 2; FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent(); ForwardingDrawable settableDrawable = (ForwardingDrawable) fadeDrawable.getDrawable(imageIndex); // set temporary image dh.setImage(mActualImage1, 0.5f, true); assertNotSame(mActualImage1, settableDrawable.getCurrent()); assertEquals(RoundedBitmapDrawable.class, settableDrawable.getCurrent().getClass()); assertEquals(true, fadeDrawable.isLayerOn(imageIndex)); assertEquals(FadeDrawable.TRANSITION_NONE, fadeDrawable.getTransitionState()); verifyCallback(dh.getTopLevelDrawable(), settableDrawable.getCurrent()); // set final image dh.setImage(mActualImage2, 1f, false); assertNotSame(mActualImage2, settableDrawable.getCurrent()); assertEquals(RoundedBitmapDrawable.class, settableDrawable.getCurrent().getClass()); assertEquals(true, fadeDrawable.isLayerOn(imageIndex)); assertEquals(FadeDrawable.TRANSITION_STARTING, fadeDrawable.getTransitionState()); assertEquals(250, fadeDrawable.getTransitionDuration()); verifyCallback(dh.getTopLevelDrawable(), settableDrawable.getCurrent()); }
Example 6
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
private void testRoundingParams_RoundedLeafs( RootDrawable rootDrawable, FadeDrawable fadeDrawable, RoundingParams roundingParams) { assertNotNull(fadeDrawable); assertScaleTypeAndDrawable(mWrappedImage, ScaleType.CENTER, fadeDrawable.getDrawable(1)); Rounded roundedPlaceholder = (Rounded) mWrappedImage.getCurrent().getCurrent(); assertRoundingParams(roundingParams, roundedPlaceholder); Rounded roundedFailureImage = (Rounded) fadeDrawable.getDrawable(5).getCurrent(); assertRoundingParams(roundingParams, roundedFailureImage); Rounded roundedRetryImage = (Rounded) fadeDrawable.getDrawable(4); assertRoundingParams(roundingParams, roundedRetryImage); verifyCallback(rootDrawable, (Drawable) roundedPlaceholder); verifyCallback(rootDrawable, (Drawable) roundedFailureImage); verifyCallback(rootDrawable, (Drawable) roundedRetryImage); }
Example 7
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 4 votes |
@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()); }