@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); }
@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()); }
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(); } } }
/** * Wraps the given drawable with a new {@link ScaleTypeDrawable}. * * <p> If the provided drawable or scale type is null, the given drawable is returned without * being wrapped. * * @return the wrapping scale type drawable, or the original drawable if the wrapping didn't * take place */ @Nullable static Drawable maybeWrapWithScaleType( @Nullable Drawable drawable, @Nullable ScaleType scaleType, @Nullable PointF focusPoint) { if (drawable == null || scaleType == null) { return drawable; } ScaleTypeDrawable scaleTypeDrawable = new ScaleTypeDrawable(drawable, scaleType); if (focusPoint != null) { scaleTypeDrawable.setFocusPoint(focusPoint); } return scaleTypeDrawable; }
/** * 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; }
/** * Gets the ScaleTypeDrawable at the specified index. * In case there is no child at the specified index, a NullPointerException is thrown. * In case there is a child, but the ScaleTypeDrawable does not exist, * the child will be wrapped with a new ScaleTypeDrawable. */ private ScaleTypeDrawable getScaleTypeDrawableAtIndex(int index) { DrawableParent parent = getParentDrawableAtIndex(index); if (parent instanceof ScaleTypeDrawable) { return (ScaleTypeDrawable) parent; } else { return WrappingUtils.wrapChildWithScaleType(parent, ScaleType.FIT_XY); } }
private void assertScaleTypeAndDrawable( Drawable expectedChild, ScaleType expectedScaleType, Drawable actualBranch) { assertNotNull(actualBranch); ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) actualBranch; assertSame(expectedChild, scaleTypeDrawable.getCurrent()); assertSame(expectedScaleType, scaleTypeDrawable.getScaleType()); }
private void assertActualImageScaleType( ScaleType expectedScaleType, PointF expectedFocusPoint, Drawable actualBranch) { assertNotNull(actualBranch); ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) actualBranch; assertSame(expectedScaleType, scaleTypeDrawable.getScaleType()); assertSame(ForwardingDrawable.class, scaleTypeDrawable.getCurrent().getClass()); AndroidGraphicsTestUtils.assertEquals(expectedFocusPoint, scaleTypeDrawable.getFocusPoint(), 0); }
public static Drawable wrapWithScaleType( Drawable drawable, @Nullable ScalingUtils.ScaleType scaleType) { Preconditions.checkNotNull(drawable); if (scaleType == null) { return drawable; } return new ScaleTypeDrawable(drawable, scaleType); }
/** * Returns whether the given layer has a scale type drawable. */ private boolean hasScaleTypeDrawableAtIndex(int index) { DrawableParent parent = getParentDrawableAtIndex(index); return (parent instanceof ScaleTypeDrawable); }