Search in sources :

Example 1 with ScaleTypeDrawable

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

the class PipelineDraweeController method maybeUpdateDebugOverlay.

private void maybeUpdateDebugOverlay(@Nullable CloseableImage image) {
    if (!mDrawDebugOverlay) {
        return;
    }
    Drawable controllerOverlay = getControllerOverlay();
    if (controllerOverlay == null) {
        controllerOverlay = new DebugControllerOverlayDrawable();
        setControllerOverlay(controllerOverlay);
    }
    if (controllerOverlay instanceof DebugControllerOverlayDrawable) {
        DebugControllerOverlayDrawable debugOverlay = (DebugControllerOverlayDrawable) controllerOverlay;
        debugOverlay.setControllerId(getId());
        final DraweeHierarchy draweeHierarchy = getHierarchy();
        ScaleType scaleType = null;
        if (draweeHierarchy != null) {
            final ScaleTypeDrawable scaleTypeDrawable = ScalingUtils.getActiveScaleTypeDrawable(draweeHierarchy.getTopLevelDrawable());
            scaleType = scaleTypeDrawable != null ? scaleTypeDrawable.getScaleType() : null;
        }
        debugOverlay.setScaleType(scaleType);
        if (image != null) {
            debugOverlay.setDimensions(image.getWidth(), image.getHeight());
            debugOverlay.setImageSize(image.getSizeInBytes());
        } else {
            debugOverlay.reset();
        }
    }
}
Also used : DebugControllerOverlayDrawable(com.facebook.drawee.debug.DebugControllerOverlayDrawable) ScaleType(com.facebook.drawee.drawable.ScalingUtils.ScaleType) Drawable(android.graphics.drawable.Drawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) OrientedDrawable(com.facebook.drawee.drawable.OrientedDrawable) BitmapDrawable(android.graphics.drawable.BitmapDrawable) DebugControllerOverlayDrawable(com.facebook.drawee.debug.DebugControllerOverlayDrawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) SettableDraweeHierarchy(com.facebook.drawee.interfaces.SettableDraweeHierarchy) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy)

Example 2 with ScaleTypeDrawable

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

the class GenericDraweeHierarchyTest method assertScaleTypeAndDrawable.

private void assertScaleTypeAndDrawable(Drawable expectedChild, ScaleType expectedScaleType, Drawable actualBranch) {
    assertNotNull(actualBranch);
    ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) actualBranch;
    assertSame(expectedChild, scaleTypeDrawable.getCurrent());
    assertSame(expectedScaleType, scaleTypeDrawable.getScaleType());
}
Also used : ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable)

Example 3 with ScaleTypeDrawable

use of com.facebook.drawee.drawable.ScaleTypeDrawable 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);
}
Also used : PointF(android.graphics.PointF) FadeDrawable(com.facebook.drawee.drawable.FadeDrawable) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable) Test(org.junit.Test)

Example 4 with ScaleTypeDrawable

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

the class WrappingUtils method wrapChildWithScaleType.

/**
   * Wraps the parent's child with a ScaleTypeDrawable.
   */
static ScaleTypeDrawable wrapChildWithScaleType(DrawableParent parent, ScaleType scaleType) {
    Drawable child = parent.setDrawable(sEmptyDrawable);
    child = maybeWrapWithScaleType(child, scaleType);
    parent.setDrawable(child);
    Preconditions.checkNotNull(child, "Parent has no child drawable!");
    return (ScaleTypeDrawable) child;
}
Also used : 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) ScaleTypeDrawable(com.facebook.drawee.drawable.ScaleTypeDrawable)

Example 5 with ScaleTypeDrawable

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

the class GenericDraweeHierarchyTest method testSetActualImageScaleType.

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

Aggregations

ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)6 BitmapDrawable (android.graphics.drawable.BitmapDrawable)2 Drawable (android.graphics.drawable.Drawable)2 FadeDrawable (com.facebook.drawee.drawable.FadeDrawable)2 ScaleType (com.facebook.drawee.drawable.ScalingUtils.ScaleType)2 Test (org.junit.Test)2 PointF (android.graphics.PointF)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 DebugControllerOverlayDrawable (com.facebook.drawee.debug.DebugControllerOverlayDrawable)1 ForwardingDrawable (com.facebook.drawee.drawable.ForwardingDrawable)1 MatrixDrawable (com.facebook.drawee.drawable.MatrixDrawable)1 OrientedDrawable (com.facebook.drawee.drawable.OrientedDrawable)1 RoundedBitmapDrawable (com.facebook.drawee.drawable.RoundedBitmapDrawable)1 RoundedColorDrawable (com.facebook.drawee.drawable.RoundedColorDrawable)1 RoundedCornersDrawable (com.facebook.drawee.drawable.RoundedCornersDrawable)1 DraweeHierarchy (com.facebook.drawee.interfaces.DraweeHierarchy)1 SettableDraweeHierarchy (com.facebook.drawee.interfaces.SettableDraweeHierarchy)1