public void setImageSpan( Context context, DraweeHierarchy draweeHierarchy, DraweeController draweeController, int index, final int drawableWidthPx, final int drawableHeightPx, boolean enableResizing, @BetterImageSpan.BetterImageSpanAlignment int verticalAlignment) { setImageSpan( context, draweeHierarchy, draweeController, index, index, drawableWidthPx, drawableHeightPx, enableResizing, verticalAlignment); }
public void setImageSpan( Context context, DraweeHierarchy draweeHierarchy, DraweeController draweeController, int startIndex, int endIndex, final int drawableWidthPx, final int drawableHeightPx, boolean enableResizing, @BetterImageSpan.BetterImageSpanAlignment int verticalAlignment) { DraweeHolder draweeHolder = DraweeHolder.create(draweeHierarchy, context); draweeHolder.setController(draweeController); setImageSpan( draweeHolder, startIndex, endIndex, drawableWidthPx, drawableHeightPx, enableResizing, verticalAlignment); }
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(); } } }
/** * Creates a new instance of DraweeHolder that detaches / attaches controller whenever context * notifies it about activity's onStop and onStart callbacks. * * <p>It is recommended to pass a {@link ListenableActivity} as context. This will help in a future release. */ public static <DH extends DraweeHierarchy> DraweeHolder<DH> create( @Nullable DH hierarchy, Context context) { DraweeHolder<DH> holder = new DraweeHolder<DH>(hierarchy); holder.registerWithContext(context); return holder; }
/** * Sets the hierarchy. * * <p>The controller should be detached when this method is called. * @param hierarchy This must be an instance of {@link SettableDraweeHierarchy} */ @Override public void setHierarchy(@Nullable DraweeHierarchy hierarchy) { if (FLog.isLoggable(FLog.VERBOSE)) { FLog.v( TAG, "controller %x %s: setHierarchy: %s", System.identityHashCode(this), mId, hierarchy); } mEventTracker.recordEvent( (hierarchy != null) ? Event.ON_SET_HIERARCHY : Event.ON_CLEAR_HIERARCHY); // force release in case request was submitted if (mIsRequestSubmitted) { mDeferredReleaser.cancelDeferredRelease(this); release(); } // clear the existing hierarchy if (mSettableDraweeHierarchy != null) { mSettableDraweeHierarchy.setControllerOverlay(null); mSettableDraweeHierarchy = null; } // set the new hierarchy if (hierarchy != null) { Preconditions.checkArgument(hierarchy instanceof SettableDraweeHierarchy); mSettableDraweeHierarchy = (SettableDraweeHierarchy) hierarchy; mSettableDraweeHierarchy.setControllerOverlay(mControllerOverlay); } }
@Before public void setUp() { Activity activity = Robolectric.buildActivity(Activity.class).create().get(); mDrawable = DrawableTestUtils.mockDrawable(); mTopLevelDrawable = DrawableTestUtils.mockDrawable(); mDraweeHierarchy = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable); mController = DraweeMocks.mockController(); mDraweeView = new DraweeView<DraweeHierarchy>(activity); }
@Test public void testSetHierarchy() { mDraweeView.setHierarchy(mDraweeHierarchy); assertSame(mDraweeHierarchy, mDraweeView.getHierarchy()); assertSame(mTopLevelDrawable, mDraweeView.getDrawable()); DraweeHierarchy hierarchy2 = DraweeMocks.mockDraweeHierarchy(); mDraweeView.setHierarchy(hierarchy2); assertSame(hierarchy2, mDraweeView.getHierarchy()); assertSame(hierarchy2.getTopLevelDrawable(), mDraweeView.getDrawable()); }
@Test public void testOverrideControllerHierarchy() { DraweeHierarchy otherHierarchy = mock(DraweeHierarchy.class); mController.setHierarchy(otherHierarchy); assertSame(otherHierarchy, mController.getHierarchy()); mDraweeHolder.setController(mController); assertSame(mController, mDraweeHolder.getController()); assertSame(mDraweeHierarchy, mDraweeHolder.getHierarchy()); assertSame(mDraweeHierarchy, mController.getHierarchy()); }
@Test public void testSetNewControllerWithInvalidController() { final DraweeHierarchy draweeHierarchy2 = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable); final DraweeHolder draweeHolder2 = new DraweeHolder(draweeHierarchy2); mDraweeHolder.onAttach(); mDraweeHolder.setController(mController); draweeHolder2.setController(mController); mDraweeHolder.setController(null); verify(mController, never()).onDetach(); assertEquals(draweeHierarchy2, mController.getHierarchy()); }
@Test public void testSetNewHierarchyWithInvalidController() { final DraweeHierarchy draweeHierarchy2 = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable); final DraweeHolder draweeHolder2 = new DraweeHolder(draweeHierarchy2); mDraweeHolder.setController(mController); draweeHolder2.setController(mController); final DraweeHierarchy draweeHierarchy3 = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable); mDraweeHolder.setHierarchy(draweeHierarchy3); assertEquals(draweeHierarchy2, mController.getHierarchy()); }
@Test public void testOnDetachWithInvalidController() { final DraweeHierarchy draweeHierarchy2 = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable); final DraweeHolder draweeHolder2 = new DraweeHolder(draweeHierarchy2); mDraweeHolder.onAttach(); mDraweeHolder.setController(mController); draweeHolder2.setController(mController); mDraweeHolder.onDetach(); verify(mController, never()).onDetach(); }
@Test public void testTouchEventWithInvalidController() { final DraweeHierarchy draweeHierarchy2 = DraweeMocks.mockDraweeHierarchyOf(mTopLevelDrawable); final DraweeHolder draweeHolder2 = new DraweeHolder(draweeHierarchy2); mDraweeHolder.setController(mController); draweeHolder2.setController(mController); mDraweeHolder.onTouchEvent(mock(MotionEvent.class)); verify(mController, never()).onTouchEvent(any(MotionEvent.class)); }
/** * Creates a mock GenericDraweeHierarchyBuilder that builds a new DH instance each time. * @return mock GenericDraweeHierarchyBuilder */ public static GenericDraweeHierarchyBuilder mockGenericDraweeHierarchyBuilder() { GenericDraweeHierarchyBuilder builder = mock(GenericDraweeHierarchyBuilder.class, CALLS_REAL_METHODS); doAnswer( new Answer<Object>() { @Override public DraweeHierarchy answer(InvocationOnMock invocation) throws Throwable { return mockDraweeHierarchy(); } }).when(builder).build(); return builder; }
@Override public void setHierarchy(@Nullable DraweeHierarchy hierarchy) { super.setHierarchy(hierarchy); maybeUpdateDebugOverlay(null); }
/** Gets the hierarchy */ @Override public @Nullable DraweeHierarchy getHierarchy() { return mSettableDraweeHierarchy; }
private void updateText() { // The # will be replaced with the image. String text = getString(R.string.drawee_span_simple_text); int imagePosition = text.indexOf('#'); DraweeSpanStringBuilder draweeSpanStringBuilder = new DraweeSpanStringBuilder(text); DraweeHierarchy draweeHierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()) .setPlaceholderImage(new ColorDrawable(Color.RED)) .setActualImageScaleType(mScaleType) .build(); DraweeController controller = Fresco.newDraweeControllerBuilder() .setUri(mInlineImageUri) .build(); draweeSpanStringBuilder.setImageSpan( getContext(), /* Context */ draweeHierarchy, /* hierarchy to be used */ controller, /* controller to be used to update the hierarchy */ imagePosition, /* image index within the text */ 200, /* image width */ 200, /* image height */ false, /* auto resize */ DraweeSpan.ALIGN_CENTER); /* alignment */ int imagePosition2 = text.indexOf('%'); DraweeHierarchy draweeAnimatedHierarchy = GenericDraweeHierarchyBuilder.newInstance(getResources()) .setPlaceholderImage(new ColorDrawable(Color.RED)) .setActualImageScaleType(mScaleType) .build(); DraweeController animatedController = Fresco.newDraweeControllerBuilder() .setUri(mInlineAnimatedImageUri) .setAutoPlayAnimations(true) .build(); draweeSpanStringBuilder.setImageSpan( getContext(), /* Context */ draweeAnimatedHierarchy, /* hierarchy to be used */ animatedController, /* controller to be used to update the hierarchy */ imagePosition2, /* image index within the text */ 200, /* image width */ 200, /* image height */ false, /* auto resize */ DraweeSpan.ALIGN_CENTER); /* alignment */ mDraweeSpanTextView.setDraweeSpanStringBuilder(draweeSpanStringBuilder); }
public DraweeHierarchy getHierarchy() { if (mDraweeHolder != null) { return mDraweeHolder.getHierarchy(); } return null; }