Search in sources :

Example 6 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeSpanSimpleTextFragment method updateText.

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);
}
Also used : ColorDrawable(android.graphics.drawable.ColorDrawable) DraweeController(com.facebook.drawee.interfaces.DraweeController) DraweeSpanStringBuilder(com.facebook.drawee.span.DraweeSpanStringBuilder) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy)

Example 7 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeMocks method mockGenericDraweeHierarchyBuilder.

/**
 * 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;
}
Also used : GenericDraweeHierarchyBuilder(com.facebook.drawee.generic.GenericDraweeHierarchyBuilder) InvocationOnMock(org.mockito.invocation.InvocationOnMock) GenericDraweeHierarchy(com.facebook.drawee.generic.GenericDraweeHierarchy) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy)

Example 8 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeViewTest method testSetHierarchy.

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

Example 9 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeViewTest method setUp.

@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);
}
Also used : Activity(android.app.Activity) DraweeHierarchy(com.facebook.drawee.interfaces.DraweeHierarchy) Before(org.junit.Before)

Example 10 with DraweeHierarchy

use of com.facebook.drawee.interfaces.DraweeHierarchy in project fresco by facebook.

the class DraweeHolderTest method testSetNewHierarchyWithInvalidController.

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

Aggregations

DraweeHierarchy (com.facebook.drawee.interfaces.DraweeHierarchy)12 Test (org.junit.Test)6 GenericDraweeHierarchy (com.facebook.drawee.generic.GenericDraweeHierarchy)2 InvocationOnMock (org.mockito.invocation.InvocationOnMock)2 Activity (android.app.Activity)1 Rect (android.graphics.Rect)1 ColorDrawable (android.graphics.drawable.ColorDrawable)1 MotionEvent (android.view.MotionEvent)1 ScaleTypeDrawable (com.facebook.drawee.drawable.ScaleTypeDrawable)1 ScaleType (com.facebook.drawee.drawable.ScalingUtils.ScaleType)1 GenericDraweeHierarchyBuilder (com.facebook.drawee.generic.GenericDraweeHierarchyBuilder)1 DraweeController (com.facebook.drawee.interfaces.DraweeController)1 SettableDraweeHierarchy (com.facebook.drawee.interfaces.SettableDraweeHierarchy)1 DraweeSpanStringBuilder (com.facebook.drawee.span.DraweeSpanStringBuilder)1 Before (org.junit.Before)1 Answer (org.mockito.stubbing.Answer)1