Java 类com.facebook.drawee.interfaces.DraweeHierarchy 实例源码

项目:GitHub    文件:DraweeSpanStringBuilder.java   
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);
}
项目:GitHub    文件:DraweeSpanStringBuilder.java   
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);
}
项目:fresco    文件:DraweeSpanStringBuilder.java   
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);
}
项目:fresco    文件:DraweeSpanStringBuilder.java   
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);
}
项目:GitHub    文件:PipelineDraweeController.java   
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();
    }
  }
}
项目:GitHub    文件:DraweeHolder.java   
/**
 * 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;
}
项目:GitHub    文件:AbstractDraweeController.java   
/**
 * 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);
  }
}
项目:GitHub    文件:DraweeViewTest.java   
@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);
}
项目:GitHub    文件:DraweeViewTest.java   
@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());
}
项目:GitHub    文件:DraweeHolderTest.java   
@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());
}
项目:GitHub    文件:DraweeHolderTest.java   
@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());
}
项目:GitHub    文件:DraweeHolderTest.java   
@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());
}
项目:GitHub    文件:DraweeHolderTest.java   
@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();
}
项目:GitHub    文件:DraweeHolderTest.java   
@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));
}
项目:GitHub    文件:DraweeMocks.java   
/**
 * 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;
}
项目:fresco    文件:PipelineDraweeController.java   
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();
    }
  }
}
项目:fresco    文件:DraweeHolder.java   
/**
 * 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;
}
项目:fresco    文件:AbstractDraweeController.java   
/**
 * 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);
  }
}
项目:fresco    文件:DraweeViewTest.java   
@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);
}
项目:fresco    文件:DraweeViewTest.java   
@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());
}
项目:fresco    文件:DraweeHolderTest.java   
@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());
}
项目:fresco    文件:DraweeHolderTest.java   
@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());
}
项目:fresco    文件:DraweeHolderTest.java   
@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());
}
项目:fresco    文件:DraweeHolderTest.java   
@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();
}
项目:fresco    文件:DraweeHolderTest.java   
@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));
}
项目:fresco    文件:DraweeMocks.java   
/**
 * 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;
}
项目:GitHub    文件:PipelineDraweeController.java   
@Override
public void setHierarchy(@Nullable DraweeHierarchy hierarchy) {
  super.setHierarchy(hierarchy);
  maybeUpdateDebugOverlay(null);
}
项目:GitHub    文件:AbstractDraweeController.java   
/** Gets the hierarchy */
@Override
public @Nullable
DraweeHierarchy getHierarchy() {
  return mSettableDraweeHierarchy;
}
项目:GitHub    文件:DraweeSpanSimpleTextFragment.java   
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);
}
项目:FrescoLoader    文件:FrescoLoader.java   
public DraweeHierarchy getHierarchy() {
    if (mDraweeHolder != null) {
        return mDraweeHolder.getHierarchy();
    }
    return null;
}
项目:fresco    文件:PipelineDraweeController.java   
@Override
public void setHierarchy(@Nullable DraweeHierarchy hierarchy) {
  super.setHierarchy(hierarchy);
  maybeUpdateDebugOverlay(null);
}
项目:fresco    文件:AbstractDraweeController.java   
/** Gets the hierarchy */
@Override
public @Nullable
DraweeHierarchy getHierarchy() {
  return mSettableDraweeHierarchy;
}
项目:fresco    文件:DraweeSpanSimpleTextFragment.java   
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);
}