Java 类com.facebook.drawee.drawable.ScaleTypeDrawable 实例源码

项目:GitHub    文件:GenericDraweeHierarchyTest.java   
@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);
}
项目:GitHub    文件:GenericDraweeHierarchyTest.java   
@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());
}
项目:fresco    文件:GenericDraweeHierarchyTest.java   
@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);
}
项目:fresco    文件:GenericDraweeHierarchyTest.java   
@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());
}
项目: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    文件:WrappingUtils.java   
/**
 * 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;
}
项目:GitHub    文件:WrappingUtils.java   
/**
 * 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;
}
项目:GitHub    文件:GenericDraweeHierarchy.java   
/**
 * 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);
  }
}
项目:GitHub    文件:GenericDraweeHierarchyTest.java   
private void assertScaleTypeAndDrawable(
    Drawable expectedChild,
    ScaleType expectedScaleType,
    Drawable actualBranch) {
  assertNotNull(actualBranch);
  ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) actualBranch;
  assertSame(expectedChild, scaleTypeDrawable.getCurrent());
  assertSame(expectedScaleType, scaleTypeDrawable.getScaleType());
}
项目:GitHub    文件:GenericDraweeHierarchyTest.java   
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);
}
项目: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    文件:WrappingUtils.java   
/**
 * 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;
}
项目:fresco    文件:WrappingUtils.java   
/**
 * 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;
}
项目:fresco    文件:GenericDraweeHierarchy.java   
/**
 * 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);
  }
}
项目:fresco    文件:GenericDraweeHierarchyTest.java   
private void assertScaleTypeAndDrawable(
    Drawable expectedChild,
    ScaleType expectedScaleType,
    Drawable actualBranch) {
  assertNotNull(actualBranch);
  ScaleTypeDrawable scaleTypeDrawable = (ScaleTypeDrawable) actualBranch;
  assertSame(expectedChild, scaleTypeDrawable.getCurrent());
  assertSame(expectedScaleType, scaleTypeDrawable.getScaleType());
}
项目:fresco    文件:GenericDraweeHierarchyTest.java   
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);
}
项目:S1-Go    文件:ImageLoader.java   
public static Drawable wrapWithScaleType(
        Drawable drawable,
        @Nullable ScalingUtils.ScaleType scaleType) {
    Preconditions.checkNotNull(drawable);
    if (scaleType == null) {
        return drawable;
    }
    return new ScaleTypeDrawable(drawable, scaleType);
}
项目:GitHub    文件:GenericDraweeHierarchy.java   
/**
 * Returns whether the given layer has a scale type drawable.
 */
private boolean hasScaleTypeDrawableAtIndex(int index) {
  DrawableParent parent = getParentDrawableAtIndex(index);
  return (parent instanceof ScaleTypeDrawable);
}
项目:fresco    文件:GenericDraweeHierarchy.java   
/**
 * Returns whether the given layer has a scale type drawable.
 */
private boolean hasScaleTypeDrawableAtIndex(int index) {
  DrawableParent parent = getParentDrawableAtIndex(index);
  return (parent instanceof ScaleTypeDrawable);
}