public class

GenericDraweeHierarchy

extends Object
implements SettableDraweeHierarchy
java.lang.Object
   ↳ com.facebook.drawee.generic.GenericDraweeHierarchy

Class Overview

A SettableDraweeHierarchy that displays placeholder image until the actual image is set. If provided, failure image will be used in case of failure (placeholder otherwise). If provided, retry image will be used in case of failure when retrying is enabled. If provided, progressbar will be displayed until fully loaded. Each image can be displayed with a different scale type (or no scaling at all). Fading between the layers is supported. Rounding is supported.

Example hierarchy with a placeholder, retry, failure and the actual image:

  o RootDrawable (top level drawable)
  |
  +--o FadeDrawable
     |
     +--o ScaleTypeDrawable (placeholder branch, optional)
     |  |
     |  +--o Drawable (placeholder image)
     |
     +--o ScaleTypeDrawable (actual image branch)
     |  |
     |  +--o ForwardingDrawable (actual image wrapper)
     |     |
     |     +--o Drawable (actual image)
     |
     +--o null (progress bar branch, optional)
     |
     +--o Drawable (retry image branch, optional)
     |
     +--o ScaleTypeDrawable (failure image branch, optional)
        |
        +--o Drawable (failure image)
  

Note:

  • RootDrawable and FadeDrawable are always created.
  • All branches except the actual image branch are optional (placeholder, failure, retry, progress bar). If some branch is not specified it won't be created. Index in FadeDrawable will still be reserved though.
  • If overlays and/or background are specified, they are added to the same fade drawable, and are always being displayed.
  • ScaleType and Matrix transformations will be added only if specified. If both are unspecified, then the branch for that image is attached to FadeDrawable directly. Matrix transformation is only supported for the actual image, and it is not recommended to be used.
  • Rounding, if specified, is applied to all layers. Rounded drawable can either wrap FadeDrawable, or if leaf rounding is specified, each leaf drawable will be rounded separately.
  • A particular drawable instance should be used by only one DH. If more than one DH is being built with the same builder, different drawable instances must be specified for each DH.

Summary

Public Methods
void getActualImageBounds(RectF outBounds)
Gets the non-cropped post-scaling bounds of the actual image.
PointF getActualImageFocusPoint()
ScalingUtils.ScaleType getActualImageScaleType()
Rect getBounds()
int getFadeDuration()
Gets the fade duration.
RoundingParams getRoundingParams()
Gets the rounding params.
Drawable getTopLevelDrawable()
Returns the top level drawable in the corresponding hierarchy.
boolean hasImage()
boolean hasPlaceholderImage()
void reset()
Called by controller when the hierarchy should be reset to its initial state.
void setActualImageColorFilter(ColorFilter colorfilter)
Sets the color filter to be applied on the actual image.
void setActualImageFocusPoint(PointF focusPoint)
Sets the actual image focus point.
void setActualImageScaleType(ScalingUtils.ScaleType scaleType)
Sets the actual image scale type.
void setBackgroundImage(Drawable drawable)
Sets the background image if allowed.
void setControllerOverlay(Drawable drawable)
Called by controller if it needs to display some controller overlay.
void setFadeDuration(int durationMs)
Sets the fade duration.
void setFailure(Throwable throwable)
Called by controller when the future that provides the actual image completes with failure.
void setFailureImage(Drawable drawable)
Sets a new failure drawable with old scale type.
void setFailureImage(Drawable drawable, ScalingUtils.ScaleType scaleType)
Sets a new failure drawable with scale type.
void setFailureImage(int resourceId, ScalingUtils.ScaleType scaleType)
Sets a new failure drawable with scale type.
void setFailureImage(int resourceId)
Sets a new failure drawable with old scale type.
void setImage(Drawable drawable, float progress, boolean immediate)
Called by controller when the future that provides the actual image completes successfully.
void setOnFadeListener(FadeDrawable.OnFadeListener onFadeFinished)
void setOverlayImage(int index, Drawable drawable)
Sets a new overlay image at the specified index.
void setOverlayImage(Drawable drawable)
Sets the overlay image if allowed.
void setPlaceholderImage(Drawable drawable)
Sets a new placeholder drawable with old scale type.
void setPlaceholderImage(int resourceId, ScalingUtils.ScaleType scaleType)
Sets a new placeholder drawable with scale type.
void setPlaceholderImage(Drawable drawable, ScalingUtils.ScaleType scaleType)
Sets a new placeholder drawable with scale type.
void setPlaceholderImage(int resourceId)
Sets a new placeholder drawable with old scale type.
void setPlaceholderImageFocusPoint(PointF focusPoint)
Sets the placeholder image focus point.
void setProgress(float progress, boolean immediate)
Called by controller to update the progress.
void setProgressBarImage(int resourceId, ScalingUtils.ScaleType scaleType)
Sets a new progress bar drawable with scale type.
void setProgressBarImage(Drawable drawable)
Sets a new progress bar drawable with old scale type.
void setProgressBarImage(Drawable drawable, ScalingUtils.ScaleType scaleType)
Sets a new progress bar drawable with scale type.
void setProgressBarImage(int resourceId)
Sets a new progress bar drawable with old scale type.
void setRetry(Throwable throwable)
Called by controller when the future that provides the actual image completes with failure, but the controller is prepared to kick off a retry when the user clicks on the image.
void setRetryImage(int resourceId, ScalingUtils.ScaleType scaleType)
Sets a new retry drawable with scale type.
void setRetryImage(int resourceId)
Sets a new retry drawable with old scale type.
void setRetryImage(Drawable drawable, ScalingUtils.ScaleType scaleType)
Sets a new retry drawable with scale type.
void setRetryImage(Drawable drawable)
Sets a new retry drawable with old scale type.
void setRoundingParams(RoundingParams roundingParams)
Sets the rounding params.
[Expand]
Inherited Methods
From class java.lang.Object
From interface com.facebook.drawee.interfaces.DraweeHierarchy
From interface com.facebook.drawee.interfaces.SettableDraweeHierarchy

Public Methods

public void getActualImageBounds (RectF outBounds)

Gets the non-cropped post-scaling bounds of the actual image.

public PointF getActualImageFocusPoint ()

public ScalingUtils.ScaleType getActualImageScaleType ()

public Rect getBounds ()

public int getFadeDuration ()

Gets the fade duration.

public RoundingParams getRoundingParams ()

Gets the rounding params.

public Drawable getTopLevelDrawable ()

Returns the top level drawable in the corresponding hierarchy. Hierarchy should always have the same instance of its top level drawable.

Returns
  • top level drawable

public boolean hasImage ()

public boolean hasPlaceholderImage ()

Returns
  • true if there is a placeholder image set.

public void reset ()

Called by controller when the hierarchy should be reset to its initial state. Any image previously set by setImage should be detached and not used anymore.

public void setActualImageColorFilter (ColorFilter colorfilter)

Sets the color filter to be applied on the actual image.

public void setActualImageFocusPoint (PointF focusPoint)

Sets the actual image focus point.

public void setActualImageScaleType (ScalingUtils.ScaleType scaleType)

Sets the actual image scale type.

public void setBackgroundImage (Drawable drawable)

Sets the background image if allowed.

public void setControllerOverlay (Drawable drawable)

Called by controller if it needs to display some controller overlay.

Parameters
drawable drawable to be displayed as controller overlay

public void setFadeDuration (int durationMs)

Sets the fade duration.

public void setFailure (Throwable throwable)

Called by controller when the future that provides the actual image completes with failure. Hierarchy can choose to display between different images based on cause of failure.

Parameters
throwable cause of failure

public void setFailureImage (Drawable drawable)

Sets a new failure drawable with old scale type.

public void setFailureImage (Drawable drawable, ScalingUtils.ScaleType scaleType)

Sets a new failure drawable with scale type.

public void setFailureImage (int resourceId, ScalingUtils.ScaleType scaleType)

Sets a new failure drawable with scale type.

Parameters
resourceId an identifier of an Android drawable or color resource.

public void setFailureImage (int resourceId)

Sets a new failure drawable with old scale type.

Parameters
resourceId an identifier of an Android drawable or color resource.

public void setImage (Drawable drawable, float progress, boolean immediate)

Called by controller when the future that provides the actual image completes successfully. Hierarchy should display the actual image.

Parameters
drawable drawable to be set as the temporary image
progress number in range [0, 1] that indicates progress
immediate if true, image will be shown immediately (without fade effect)

public void setOnFadeListener (FadeDrawable.OnFadeListener onFadeFinished)

public void setOverlayImage (int index, Drawable drawable)

Sets a new overlay image at the specified index.

This method will throw if the given index is out of bounds.

Parameters
drawable background image

public void setOverlayImage (Drawable drawable)

Sets the overlay image if allowed.

public void setPlaceholderImage (Drawable drawable)

Sets a new placeholder drawable with old scale type.

public void setPlaceholderImage (int resourceId, ScalingUtils.ScaleType scaleType)

Sets a new placeholder drawable with scale type.

Parameters
resourceId an identifier of an Android drawable or color resource.

public void setPlaceholderImage (Drawable drawable, ScalingUtils.ScaleType scaleType)

Sets a new placeholder drawable with scale type.

public void setPlaceholderImage (int resourceId)

Sets a new placeholder drawable with old scale type.

Parameters
resourceId an identifier of an Android drawable or color resource.

public void setPlaceholderImageFocusPoint (PointF focusPoint)

Sets the placeholder image focus point.

public void setProgress (float progress, boolean immediate)

Called by controller to update the progress. Hierarchy can choose to hide the progressbar when progress is set to its final value of 1.

Parameters
progress number in range [0, 1] that indicates progress
immediate if true, progressbar will be shown/hidden immediately (without fade effect)

public void setProgressBarImage (int resourceId, ScalingUtils.ScaleType scaleType)

Sets a new progress bar drawable with scale type.

Parameters
resourceId an identifier of an Android drawable or color resource.

public void setProgressBarImage (Drawable drawable)

Sets a new progress bar drawable with old scale type.

public void setProgressBarImage (Drawable drawable, ScalingUtils.ScaleType scaleType)

Sets a new progress bar drawable with scale type.

public void setProgressBarImage (int resourceId)

Sets a new progress bar drawable with old scale type.

Parameters
resourceId an identifier of an Android drawable or color resource.

public void setRetry (Throwable throwable)

Called by controller when the future that provides the actual image completes with failure, but the controller is prepared to kick off a retry when the user clicks on the image. Hierarchy can choose to display a retry image.

Parameters
throwable cause of failure

public void setRetryImage (int resourceId, ScalingUtils.ScaleType scaleType)

Sets a new retry drawable with scale type.

Parameters
resourceId an identifier of an Android drawable or color resource.

public void setRetryImage (int resourceId)

Sets a new retry drawable with old scale type.

Parameters
resourceId an identifier of an Android drawable or color resource.

public void setRetryImage (Drawable drawable, ScalingUtils.ScaleType scaleType)

Sets a new retry drawable with scale type.

public void setRetryImage (Drawable drawable)

Sets a new retry drawable with old scale type.

public void setRoundingParams (RoundingParams roundingParams)

Sets the rounding params.