Search in sources :

Example 1 with Rounded

use of com.facebook.drawee.drawable.Rounded in project fresco by facebook.

the class GenericDraweeHierarchyTest method testHierarchy_WithRoundedLeafs.

@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);
}
Also used : Rounded(com.facebook.drawee.drawable.Rounded) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) Test(org.junit.Test)

Example 2 with Rounded

use of com.facebook.drawee.drawable.Rounded in project fresco by facebook.

the class WrappingUtils method updateLeafRounding.

/**
   * Updates the leaf rounding of the parent's child drawable.
   *
   * <ul>
   * <li>If rounding mode is BITMAP_ONLY and the child is not a rounded drawable,
   * it gets rounded with a new rounded drawable.
   * <li>If rounding mode is BITMAP_ONLY and the child is already rounded,
   * its rounding parameters are updated.
   * <li>If rounding mode is not BITMAP_ONLY and the child is rounded,
   * its rounding parameters are reset so that no rounding occurs.
   * </ul>
   */
static void updateLeafRounding(DrawableParent parent, @Nullable RoundingParams roundingParams, Resources resources) {
    parent = findDrawableParentForLeaf(parent);
    Drawable child = parent.getDrawable();
    if (roundingParams != null && roundingParams.getRoundingMethod() == RoundingParams.RoundingMethod.BITMAP_ONLY) {
        // drawable that will round it.
        if (child instanceof Rounded) {
            Rounded rounded = (Rounded) child;
            applyRoundingParams(rounded, roundingParams);
        } else if (child != null) {
            // Important: remove the child before wrapping it with a new parent!
            parent.setDrawable(sEmptyDrawable);
            Drawable rounded = applyLeafRounding(child, roundingParams, resources);
            parent.setDrawable(rounded);
        }
    } else if (child instanceof Rounded) {
        // No rounding requested - reset rounding params so no rounding occurs.
        resetRoundingParams((Rounded) child);
    }
}
Also used : Rounded(com.facebook.drawee.drawable.Rounded) ColorDrawable(android.graphics.drawable.ColorDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) MatrixDrawable(com.facebook.drawee.drawable.MatrixDrawable) RoundedColorDrawable(com.facebook.drawee.drawable.RoundedColorDrawable) RoundedCornersDrawable(com.facebook.drawee.drawable.RoundedCornersDrawable) ForwardingDrawable(com.facebook.drawee.drawable.ForwardingDrawable) RoundedBitmapDrawable(com.facebook.drawee.drawable.RoundedBitmapDrawable)

Example 3 with Rounded

use of com.facebook.drawee.drawable.Rounded in project fresco by facebook.

the class GenericDraweeHierarchyTest method testRoundingParams_RoundedLeafs.

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);
}
Also used : Rounded(com.facebook.drawee.drawable.Rounded)

Aggregations

Rounded (com.facebook.drawee.drawable.Rounded)3 BitmapDrawable (android.graphics.drawable.BitmapDrawable)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 Drawable (android.graphics.drawable.Drawable)1 FadeDrawable (com.facebook.drawee.drawable.FadeDrawable)1 ForwardingDrawable (com.facebook.drawee.drawable.ForwardingDrawable)1 MatrixDrawable (com.facebook.drawee.drawable.MatrixDrawable)1 RoundedBitmapDrawable (com.facebook.drawee.drawable.RoundedBitmapDrawable)1 RoundedColorDrawable (com.facebook.drawee.drawable.RoundedColorDrawable)1 RoundedCornersDrawable (com.facebook.drawee.drawable.RoundedCornersDrawable)1 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)1 Test (org.junit.Test)1