com.facebook.drawee.drawable.FadeDrawable Java Examples
The following examples show how to use
com.facebook.drawee.drawable.FadeDrawable.
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: UETFresco.java From UETool with MIT License | 6 votes |
private Bitmap getPlaceHolderBitmap(DraweeView draweeView) { GenericDraweeHierarchy hierarchy = getGenericDraweeHierarchy(draweeView); if (hierarchy != null && hierarchy.hasPlaceholderImage()) { try { Field mFadeDrawableField = hierarchy.getClass().getDeclaredField("mFadeDrawable"); mFadeDrawableField.setAccessible(true); FadeDrawable fadeDrawable = (FadeDrawable) mFadeDrawableField.get(hierarchy); Field mLayersField = fadeDrawable.getClass().getDeclaredField("mLayers"); mLayersField.setAccessible(true); Drawable[] layers = (Drawable[]) mLayersField.get(fadeDrawable); // PLACEHOLDER_IMAGE_INDEX == 1 Drawable drawable = layers[1]; return getFrescoDrawableBitmap(drawable); } catch (Exception e) { e.printStackTrace(); } } return null; }
Example #2
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 6 votes |
@Test public void testHierarchy_WithScaleType() throws Exception { GenericDraweeHierarchy dh = mBuilder .setPlaceholderImage(mPlaceholderImage, ScaleType.CENTER) .setRetryImage(mRetryImage, ScaleType.FIT_CENTER) .setFailureImage(mFailureImage, ScaleType.CENTER_INSIDE) .setProgressBarImage(mProgressBarImage, ScaleType.CENTER) .setActualImageScaleType(ScaleType.FOCUS_CROP) .setActualImageFocusPoint(mFocusPoint) .build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(7, fadeDrawable.getNumberOfLayers()); assertNull(fadeDrawable.getDrawable(0)); assertScaleTypeAndDrawable(mPlaceholderImage, ScaleType.CENTER, fadeDrawable.getDrawable(1)); assertActualImageScaleType(ScaleType.FOCUS_CROP, mFocusPoint, fadeDrawable.getDrawable(2)); assertScaleTypeAndDrawable(mProgressBarImage, ScaleType.CENTER, fadeDrawable.getDrawable(3)); assertScaleTypeAndDrawable(mRetryImage, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(4)); assertScaleTypeAndDrawable(mFailureImage, ScaleType.CENTER_INSIDE, fadeDrawable.getDrawable(5)); assertNull(fadeDrawable.getDrawable(6)); verifyCallback(rootDrawable, mPlaceholderImage); }
Example #3
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 6 votes |
@Test public void testHierarchy_NoScaleTypeNorMatrix() throws Exception { GenericDraweeHierarchy dh = mBuilder .setPlaceholderImage(mPlaceholderImage, null) .setRetryImage(mRetryImage, null) .setFailureImage(mFailureImage, null) .setProgressBarImage(mProgressBarImage, null) .setActualImageScaleType(null) .build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(7, fadeDrawable.getNumberOfLayers()); assertNull(fadeDrawable.getDrawable(0)); assertSame(mPlaceholderImage, fadeDrawable.getDrawable(1)); assertSame(ForwardingDrawable.class, fadeDrawable.getDrawable(2).getClass()); assertSame(mProgressBarImage, fadeDrawable.getDrawable(3)); assertSame(mRetryImage, fadeDrawable.getDrawable(4)); assertSame(mFailureImage, fadeDrawable.getDrawable(5)); assertNull(fadeDrawable.getDrawable(6)); verifyCallback(rootDrawable, mPlaceholderImage); }
Example #4
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 6 votes |
private void testSetRoundingParams_ToOverlayFrom(RoundingParams prev) { RoundingParams roundingParams = RoundingParams.fromCornersRadius(7) .setOverlayColor(0xFFFFFFFF) .setBorder(0x12345678, 5) .setPadding(10); GenericDraweeHierarchy dh = testRoundingParams_createHierarchy(prev, roundingParams); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); RoundedCornersDrawable roundedDrawable = (RoundedCornersDrawable) rootDrawable.getCurrent(); assertRoundingParams(roundingParams, roundedDrawable); assertEquals(roundingParams.getOverlayColor(), roundedDrawable.getOverlayColor()); FadeDrawable fadeDrawable = (FadeDrawable) roundedDrawable.getCurrent(); if (prev != null && prev.getRoundingMethod() == RoundingParams.RoundingMethod.BITMAP_ONLY) { // Rounded leafs remain rounded, but with reset params, so no leaf rounding actually occurs testRoundingParams_RoundedLeafs(rootDrawable, fadeDrawable, null); } else { testRoundingParams_NoRoundedLeafs(rootDrawable, fadeDrawable); } }
Example #5
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 #6
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 #7
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 #8
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 6 votes |
@Test public void testHierarchy_WithAllBranches() throws Exception { GenericDraweeHierarchy dh = mBuilder .setPlaceholderImage(mPlaceholderImage, ScaleType.CENTER) .setRetryImage(mRetryImage, ScaleType.FIT_CENTER) .setFailureImage(mFailureImage, ScaleType.FIT_CENTER) .setProgressBarImage(mProgressBarImage, ScaleType.CENTER) .setActualImageScaleType(ScaleType.CENTER_CROP) .build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(7, fadeDrawable.getNumberOfLayers()); assertNull(fadeDrawable.getDrawable(0)); assertScaleTypeAndDrawable(mPlaceholderImage, ScaleType.CENTER, fadeDrawable.getDrawable(1)); assertActualImageScaleType(ScaleType.CENTER_CROP, null, fadeDrawable.getDrawable(2)); assertScaleTypeAndDrawable(mProgressBarImage, ScaleType.CENTER, fadeDrawable.getDrawable(3)); assertScaleTypeAndDrawable(mRetryImage, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(4)); assertScaleTypeAndDrawable(mFailureImage, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(5)); assertNull(fadeDrawable.getDrawable(6)); verifyCallback(rootDrawable, mPlaceholderImage); }
Example #9
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 #10
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithBackgroundAndSingleOverlay() throws Exception { GenericDraweeHierarchy dh = mBuilder.setBackground(mBackground).setOverlay(mOverlay2).build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(7, fadeDrawable.getNumberOfLayers()); assertSame(mBackground, fadeDrawable.getDrawable(0)); assertSame(mOverlay2, fadeDrawable.getDrawable(6)); verifyCallback(rootDrawable, mBackground); verifyCallback(rootDrawable, mOverlay2); }
Example #11
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithRoundedOverlayColor() throws Exception { RoundingParams roundingParams = RoundingParams.fromCornersRadius(10).setOverlayColor(0xFFFFFFFF); GenericDraweeHierarchy dh = mBuilder.setRoundingParams(roundingParams).build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); RoundedCornersDrawable roundedDrawable = (RoundedCornersDrawable) rootDrawable.getCurrent(); assertRoundingParams(roundingParams, roundedDrawable); assertEquals(roundingParams.getOverlayColor(), roundedDrawable.getOverlayColor()); FadeDrawable fadeDrawable = (FadeDrawable) roundedDrawable.getCurrent(); assertNotNull(fadeDrawable); verifyCallback(rootDrawable, fadeDrawable); }
Example #12
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 #13
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
private void testSetDrawable(GenericDraweeHierarchy dh, int index, SetDrawableCallback callback) { FadeDrawable fadeDrawable = (FadeDrawable) dh.getTopLevelDrawable().getCurrent(); // null callback.setDrawable(null); assertNull(fadeDrawable.getDrawable(index)); // null -> null callback.setDrawable(null); assertNull(fadeDrawable.getDrawable(index)); // null -> drawable Drawable drawable1 = DrawableTestUtils.mockDrawable(); callback.setDrawable(drawable1); assertSame(drawable1, fadeDrawable.getDrawable(index)); // drawable -> drawable Drawable drawable2 = DrawableTestUtils.mockDrawable(); callback.setDrawable(drawable2); assertSame(drawable2, fadeDrawable.getDrawable(index)); // drawable -> null callback.setDrawable(null); assertNull(fadeDrawable.getDrawable(index)); // null -> scaletype + drawable Drawable drawable3 = DrawableTestUtils.mockDrawable(); callback.setDrawable(drawable3, ScaleType.FOCUS_CROP); assertScaleTypeAndDrawable(drawable3, ScaleType.FOCUS_CROP, fadeDrawable.getDrawable(index)); // scaletype + drawable -> scaletype + drawable Drawable drawable4 = DrawableTestUtils.mockDrawable(); callback.setDrawable(drawable4, ScaleType.CENTER); assertScaleTypeAndDrawable(drawable4, ScaleType.CENTER, fadeDrawable.getDrawable(index)); // scaletype + drawable -> null callback.setDrawable(null); assertNull(fadeDrawable.getDrawable(index)); // drawable -> scaletype + drawable callback.setDrawable(drawable1); Drawable drawable5 = DrawableTestUtils.mockDrawable(); callback.setDrawable(drawable5, ScaleType.FIT_CENTER); assertScaleTypeAndDrawable(drawable5, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(index)); // scaletype + drawable -> drawable (kep the old scaletype) Drawable drawable6 = DrawableTestUtils.mockDrawable(); callback.setDrawable(drawable6); assertScaleTypeAndDrawable(drawable6, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(index)); }
Example #14
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
private void testSetRoundingParams_ToNoneFrom(RoundingParams prev) { RoundingParams roundingParams = null; GenericDraweeHierarchy dh = testRoundingParams_createHierarchy(prev, roundingParams); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); if (prev != null && prev.getRoundingMethod() == RoundingParams.RoundingMethod.BITMAP_ONLY) { // Rounded leafs remain rounded, but with reset params, so no leaf rounding actually occurs testRoundingParams_RoundedLeafs(rootDrawable, fadeDrawable, roundingParams); } else { testRoundingParams_NoRoundedLeafs(rootDrawable, fadeDrawable); } }
Example #15
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
private void testSetRoundingParams_ToRoundedLeafsFrom(RoundingParams prev) { RoundingParams roundingParams = RoundingParams.asCircle().setBorder(0xAAAAAAAA, 4); GenericDraweeHierarchy dh = testRoundingParams_createHierarchy(prev, roundingParams); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); testRoundingParams_RoundedLeafs(rootDrawable, fadeDrawable, roundingParams); }
Example #16
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
private void testRoundingParams_NoRoundedLeafs( RootDrawable rootDrawable, FadeDrawable fadeDrawable) { assertNotNull(fadeDrawable); assertScaleTypeAndDrawable(mWrappedImage, ScaleType.CENTER, fadeDrawable.getDrawable(1)); assertScaleTypeAndDrawable(mFailureImage, ScaleType.CENTER, fadeDrawable.getDrawable(5)); assertSame(mRetryImage, fadeDrawable.getDrawable(4)); verifyCallback(rootDrawable, mWrappedLeaf); verifyCallback(rootDrawable, mFailureImage); verifyCallback(rootDrawable, mRetryImage); }
Example #17
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 #18
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithBackgroundAndMultipleOverlays() throws Exception { GenericDraweeHierarchy dh = mBuilder .setPlaceholderImage(mPlaceholderImage, ScaleType.CENTER) .setRetryImage(mRetryImage, ScaleType.FIT_CENTER) .setFailureImage(mFailureImage, ScaleType.FIT_CENTER) .setProgressBarImage(mProgressBarImage, ScaleType.CENTER) .setActualImageScaleType(ScaleType.CENTER_CROP) .setBackground(mBackground) .setOverlays(Arrays.asList(mOverlay1, mOverlay2)) .build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(8, fadeDrawable.getNumberOfLayers()); assertSame(mBackground, fadeDrawable.getDrawable(0)); assertScaleTypeAndDrawable(mPlaceholderImage, ScaleType.CENTER, fadeDrawable.getDrawable(1)); assertActualImageScaleType(ScaleType.CENTER_CROP, null, fadeDrawable.getDrawable(2)); assertScaleTypeAndDrawable(mProgressBarImage, ScaleType.CENTER, fadeDrawable.getDrawable(3)); assertScaleTypeAndDrawable(mRetryImage, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(4)); assertScaleTypeAndDrawable(mFailureImage, ScaleType.FIT_CENTER, fadeDrawable.getDrawable(5)); assertSame(mOverlay1, fadeDrawable.getDrawable(6)); assertSame(mOverlay2, fadeDrawable.getDrawable(7)); verifyCallback(rootDrawable, mBackground); verifyCallback(rootDrawable, mPlaceholderImage); verifyCallback(rootDrawable, mOverlay2); }
Example #19
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@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); }
Example #20
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithOverlays() throws Exception { GenericDraweeHierarchy dh = mBuilder.setOverlays(Arrays.asList(mOverlay1, mOverlay2)).build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(8, fadeDrawable.getNumberOfLayers()); assertSame(mOverlay1, fadeDrawable.getDrawable(6)); assertSame(mOverlay2, fadeDrawable.getDrawable(7)); verifyCallback(rootDrawable, mOverlay1); verifyCallback(rootDrawable, mOverlay2); }
Example #21
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithBackground() throws Exception { GenericDraweeHierarchy dh = mBuilder.setBackground(mBackground).build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(7, fadeDrawable.getNumberOfLayers()); assertSame(mBackground, fadeDrawable.getDrawable(0)); verifyCallback(rootDrawable, mBackground); }
Example #22
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@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); }
Example #23
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithRetryImage() throws Exception { GenericDraweeHierarchy dh = mBuilder.setRetryImage(mRetryImage, ScaleType.CENTER).build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertScaleTypeAndDrawable(mRetryImage, ScaleType.CENTER, fadeDrawable.getDrawable(4)); verifyCallback(rootDrawable, mRetryImage); }
Example #24
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithFailureImage() throws Exception { GenericDraweeHierarchy dh = mBuilder.setFailureImage(mFailureImage, ScaleType.CENTER).build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertScaleTypeAndDrawable(mFailureImage, ScaleType.CENTER, fadeDrawable.getDrawable(5)); verifyCallback(rootDrawable, mFailureImage); }
Example #25
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_WithPlaceholderImage() throws Exception { GenericDraweeHierarchy dh = mBuilder.setPlaceholderImage(mPlaceholderImage, ScaleType.CENTER).build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertScaleTypeAndDrawable(mPlaceholderImage, ScaleType.CENTER, fadeDrawable.getDrawable(1)); verifyCallback(rootDrawable, mPlaceholderImage); }
Example #26
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 5 votes |
@Test public void testHierarchy_NoBranches() throws Exception { GenericDraweeHierarchy dh = mBuilder.build(); RootDrawable rootDrawable = (RootDrawable) dh.getTopLevelDrawable(); FadeDrawable fadeDrawable = (FadeDrawable) rootDrawable.getCurrent(); assertEquals(7, fadeDrawable.getNumberOfLayers()); assertNull(fadeDrawable.getDrawable(0)); assertNull(fadeDrawable.getDrawable(1)); assertActualImageScaleType(ScaleType.CENTER_CROP, null, fadeDrawable.getDrawable(2)); assertNull(fadeDrawable.getDrawable(3)); assertNull(fadeDrawable.getDrawable(4)); assertNull(fadeDrawable.getDrawable(5)); assertNull(fadeDrawable.getDrawable(6)); verifyCallback(rootDrawable, fadeDrawable); }
Example #27
Source File: AbstractDraweeController.java From fresco with MIT License | 5 votes |
private void setUpLoggingListener() { if (mSettableDraweeHierarchy instanceof GenericDraweeHierarchy) { ((GenericDraweeHierarchy) mSettableDraweeHierarchy) .setOnFadeFinishedListener( new FadeDrawable.OnFadeFinishedListener() { @Override public void onFadeFinished() { if (mLoggingListener != null) { mLoggingListener.onFadeFinished(mId); } } }); } }
Example #28
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()); }
Example #29
Source File: GenericDraweeHierarchyTest.java From fresco with MIT License | 4 votes |
private void assertLayersOn(FadeDrawable fadeDrawable, int firstLayerIndex, int numberOfLayers) { for (int i = 0; i < numberOfLayers; i++) { assertEquals(true, fadeDrawable.isLayerOn(firstLayerIndex + i)); } }
Example #30
Source File: GenericDraweeHierarchy.java From fresco with MIT License | 4 votes |
public void setOnFadeFinishedListener(FadeDrawable.OnFadeFinishedListener onFadeFinished) { mFadeDrawable.setOnFadeFinishedListener(onFadeFinished); }