com.bumptech.glide
Class DrawableRequestBuilder<ModelType>

java.lang.Object
  extended by com.bumptech.glide.GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
      extended by com.bumptech.glide.DrawableRequestBuilder<ModelType>
Type Parameters:
ModelType - The type of model that will be loaded into the target.
Direct Known Subclasses:
DrawableTypeRequest

public class DrawableRequestBuilder<ModelType>
extends GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>

A class for creating a request to load a GlideDrawable.

Warning - It is not safe to use this builder after calling into(), it may be pooled and reused.


Method Summary
 DrawableRequestBuilder<ModelType> animate(Animation animation)
          Sets an animation to run on the wrapped target when a resource load finishes.
 DrawableRequestBuilder<ModelType> animate(int animationId)
          Sets an animation to run on the wrapped target when an resource load finishes.
 DrawableRequestBuilder<ModelType> animate(ViewPropertyAnimation.Animator animator)
          Sets an animator to run a ViewPropertyAnimator on a view that the target may be wrapping when a resource load finishes.
 DrawableRequestBuilder<ModelType> bitmapTransform(Transformation<Bitmap>... bitmapTransformations)
          Transform GlideDrawables using the given Bitmap transformations.
 DrawableRequestBuilder<ModelType> cacheDecoder(ResourceDecoder<File,GifBitmapWrapper> cacheDecoder)
          Sets the ResourceDecoder to use to load the resource from the disk cache.
 DrawableRequestBuilder<ModelType> centerCrop()
          Transform GlideDrawables using CenterCrop.
 DrawableRequestBuilder<ModelType> crossFade()
          Applies a cross fade transformation that fades from the placeholder to the loaded Drawable.
 DrawableRequestBuilder<ModelType> crossFade(Animation animation, int duration)
          Applies a cross fade transformation that des from the placeholder to the loaded Drawable.
 DrawableRequestBuilder<ModelType> crossFade(int duration)
          Applies a cross fade transformation that fades from the placeholder to the loaded Drawable.
 DrawableRequestBuilder<ModelType> crossFade(int animationId, int duration)
          Applies a cross fade transformation that des from the placeholder to the loaded Drawable.
 DrawableRequestBuilder<ModelType> decoder(ResourceDecoder<ImageVideoWrapper,GifBitmapWrapper> decoder)
          Sets the ResourceDecoder to use to load the resource from the original data.
 DrawableRequestBuilder<ModelType> diskCacheStrategy(DiskCacheStrategy strategy)
          Sets the DiskCacheStrategy to use for this load.
 DrawableRequestBuilder<ModelType> dontAnimate()
          Removes any existing animation set on the builder.
 DrawableRequestBuilder<ModelType> dontTransform()
          Removes the current Transformation.
 DrawableRequestBuilder<ModelType> encoder(ResourceEncoder<GifBitmapWrapper> encoder)
          Sets the Encoder to use to encode the original data directly to cache.
 DrawableRequestBuilder<ModelType> error(Drawable drawable)
          Sets a Drawable to display if a load fails.
 DrawableRequestBuilder<ModelType> error(int resourceId)
          Sets a resource to display if a load fails.
 DrawableRequestBuilder<ModelType> fitCenter()
          Transform GlideDrawables using FitCenter.
 Target<GlideDrawable> into(ImageView view)
          Sets the ImageView the resource will be loaded into, cancels any existing loads into the view, and frees any resources Glide may have previously loaded into the view so they may be reused.
 DrawableRequestBuilder<ModelType> listener(RequestListener<ModelType,GlideDrawable> requestListener)
          Sets a RequestBuilder listener to monitor the resource load.
 DrawableRequestBuilder<ModelType> override(int width, int height)
          Overrides the Target's width and height with the given values.
 DrawableRequestBuilder<ModelType> placeholder(Drawable drawable)
          Sets an Drawable to display while a resource is loading.
 DrawableRequestBuilder<ModelType> placeholder(int resourceId)
          Sets an Android resource id for a Drawable resourceto display while a resource is loading.
 DrawableRequestBuilder<ModelType> priority(Priority priority)
          Sets the priority for this load.
 DrawableRequestBuilder<ModelType> sizeMultiplier(float sizeMultiplier)
          Applies a multiplier to the Target's size before loading the resource.
 DrawableRequestBuilder<ModelType> skipMemoryCache(boolean skip)
          Allows the loaded resource to skip the memory cache.
 DrawableRequestBuilder<ModelType> sourceEncoder(Encoder<ImageVideoWrapper> sourceEncoder)
          Sets the source encoder to use to encode the data retrieved by this request directly into cache.
 DrawableRequestBuilder<ModelType> thumbnail(DrawableRequestBuilder<ModelType> thumbnailRequest)
          Loads and displays the GlideDrawable retrieved by the given thumbnail request if it finishes before this request.
 DrawableRequestBuilder<ModelType> thumbnail(float sizeMultiplier)
          Loads a resource in an identical manner to this request except with the dimensions of the target multiplied by the given size multiplier.
 DrawableRequestBuilder<ModelType> thumbnail(GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable> thumbnailRequest)
          Loads and displays the resource retrieved by the given thumbnail request if it finishes before this request.
 DrawableRequestBuilder<ModelType> transcoder(ResourceTranscoder<GifBitmapWrapper,GlideDrawable> transcoder)
          Sets the ResourceTranscoder to use for this load.
 DrawableRequestBuilder<ModelType> transform(BitmapTransformation... transformations)
          Transform GlideDrawables using the given BitmapTransformations.
 DrawableRequestBuilder<ModelType> transform(Transformation<GifBitmapWrapper>... transformation)
          Transform resources with the given Transformations.
 
Methods inherited from class com.bumptech.glide.GenericRequestBuilder
into, into
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

thumbnail

public DrawableRequestBuilder<ModelType> thumbnail(DrawableRequestBuilder<ModelType> thumbnailRequest)
Loads and displays the GlideDrawable retrieved by the given thumbnail request if it finishes before this request. Best used for loading thumbnail GlideDrawables that are smaller and will be loaded more quickly than the fullsize GlideDrawable. There are no guarantees about the order in which the requests will actually finish. However, if the thumb request completes after the full request, the thumb GlideDrawable will never replace the full image.

Parameters:
thumbnailRequest - The request to use to load the thumbnail.
Returns:
This builder object.
See Also:

Note - Any options on the main request will not be passed on to the thumbnail request. For example, if you want an animation to occur when either the full {@link GlideDrawable} loads or the thumbnail loads, you need to call {@link #animate(int)} on both the thumb and the full request. For a simpler thumbnail option where these options are applied to the humbnail as well, see {@link #thumbnail(float)}.

Only the thumbnail call on the main request will be obeyed, recursive calls to this method are ignored.


thumbnail

public DrawableRequestBuilder<ModelType> thumbnail(GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable> thumbnailRequest)
Loads and displays the resource retrieved by the given thumbnail request if it finishes before this request. Best used for loading thumbnail resources that are smaller and will be loaded more quickly than the fullsize resource. There are no guarantees about the order in which the requests will actually finish. However, if the thumb request completes after the full request, the thumb resource will never replace the full resource.

Overrides:
thumbnail in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
thumbnailRequest - The request to use to load the thumbnail.
Returns:
This request builder.
See Also:

Note - Any options on the main request will not be passed on to the thumbnail request. For example, if you want an animation to occur when either the full resource loads or the thumbnail loads, you need to call {@link #animate(int)} on both the thumb and the full request. For a simpler thumbnail option, see {@link #thumbnail(float)}.

Only the thumbnail call on the main request will be obeyed.


thumbnail

public DrawableRequestBuilder<ModelType> thumbnail(float sizeMultiplier)
Loads a resource in an identical manner to this request except with the dimensions of the target multiplied by the given size multiplier. If the thumbnail load completes before the fullsize load, the thumbnail will be shown. If the thumbnail load completes afer the fullsize load, the thumbnail will not be shown.

Note - The thumbnail resource will be smaller than the size requested so the target (or ImageView) must be able to scale the thumbnail appropriately. See ImageView.ScaleType.

Almost all options will be copied from the original load, including the ModelLoader, ResourceDecoder, and Transformations. However, GenericRequestBuilder.placeholder(int) and GenericRequestBuilder.error(int), and GenericRequestBuilder.listener(RequestListener) will only be used on the fullsize load and will not be copied for the thumbnail load.

Only the thumbnail call on the main request will be obeyed.

Overrides:
thumbnail in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
sizeMultiplier - The multiplier to apply to the Target's dimensions when loading the thumbnail.
Returns:
This request builder.

sizeMultiplier

public DrawableRequestBuilder<ModelType> sizeMultiplier(float sizeMultiplier)
Applies a multiplier to the Target's size before loading the resource. Useful for loading thumbnails or trying to avoid loading huge resources (particularly Bitmaps on devices with overly dense screens.

Overrides:
sizeMultiplier in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
sizeMultiplier - The multiplier to apply to the Target's dimensions when loading the resource.
Returns:
This request builder.

decoder

public DrawableRequestBuilder<ModelType> decoder(ResourceDecoder<ImageVideoWrapper,GifBitmapWrapper> decoder)
Sets the ResourceDecoder to use to load the resource from the original data. By default, this decoder will only be used if the final transformed resource is not in the disk cache.

Overrides:
decoder in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
decoder - The ResourceDecoder to use to decode the resource.
Returns:
This request builder.
See Also:
GenericRequestBuilder.cacheDecoder(com.bumptech.glide.load.ResourceDecoder), DiskCacheStrategy

cacheDecoder

public DrawableRequestBuilder<ModelType> cacheDecoder(ResourceDecoder<File,GifBitmapWrapper> cacheDecoder)
Sets the ResourceDecoder to use to load the resource from the disk cache. By default, this decoder will only be used if the final transformed resource is already in the disk cache.

Overrides:
cacheDecoder in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
cacheDecoder - The decoder to use.
Returns:
This request builder.
See Also:
GenericRequestBuilder.decoder(com.bumptech.glide.load.ResourceDecoder), DiskCacheStrategy

encoder

public DrawableRequestBuilder<ModelType> encoder(ResourceEncoder<GifBitmapWrapper> encoder)
Sets the Encoder to use to encode the original data directly to cache. Will only be used if the original data is not already in cache and if the DiskCacheStrategy is set to DiskCacheStrategy.SOURCE or DiskCacheStrategy.ALL.

Overrides:
encoder in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
encoder - The encoder to use.
Returns:
This request builder.
See Also:
GenericRequestBuilder.sourceEncoder(com.bumptech.glide.load.Encoder), DiskCacheStrategy

priority

public DrawableRequestBuilder<ModelType> priority(Priority priority)
Sets the priority for this load.

Overrides:
priority in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
priority - A priority.
Returns:
This request builder.

transform

public DrawableRequestBuilder<ModelType> transform(BitmapTransformation... transformations)
Transform GlideDrawables using the given BitmapTransformations.

Note - Bitmap transformations will apply individually to each frame of animated GIF images and also to individual Bitmaps.

Parameters:
transformations - The transformations to apply in order.
Returns:
This request builder.
See Also:
centerCrop(), fitCenter(), bitmapTransform(com.bumptech.glide.load.Transformation[]), transform(com.bumptech.glide.load.Transformation[])

centerCrop

public DrawableRequestBuilder<ModelType> centerCrop()
Transform GlideDrawables using CenterCrop.

Returns:
This request builder.
See Also:
fitCenter(), transform(com.bumptech.glide.load.resource.bitmap.BitmapTransformation...), bitmapTransform(com.bumptech.glide.load.Transformation[]), transform(com.bumptech.glide.load.Transformation[])

fitCenter

public DrawableRequestBuilder<ModelType> fitCenter()
Transform GlideDrawables using FitCenter.

Returns:
This request builder.
See Also:
centerCrop(), transform(com.bumptech.glide.load.resource.bitmap.BitmapTransformation...), bitmapTransform(com.bumptech.glide.load.Transformation[]), transform(com.bumptech.glide.load.Transformation[])

bitmapTransform

public DrawableRequestBuilder<ModelType> bitmapTransform(Transformation<Bitmap>... bitmapTransformations)
Transform GlideDrawables using the given Bitmap transformations. Replaces any previous transformations.

Returns:
This request builder.
See Also:
fitCenter(), centerCrop(), transform(com.bumptech.glide.load.resource.bitmap.BitmapTransformation...), transform(com.bumptech.glide.load.Transformation[])

transform

public DrawableRequestBuilder<ModelType> transform(Transformation<GifBitmapWrapper>... transformation)
Transform resources with the given Transformations. Replaces any existing transformation or transformations.

Overrides:
transform in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
transformation - the transformations to apply in order.
Returns:
This request builder.
See Also:
bitmapTransform(com.bumptech.glide.load.Transformation[]), centerCrop(), fitCenter()

transcoder

public DrawableRequestBuilder<ModelType> transcoder(ResourceTranscoder<GifBitmapWrapper,GlideDrawable> transcoder)
Sets the ResourceTranscoder to use for this load.

Overrides:
transcoder in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
transcoder - The transcoder to use.
Returns:
This request builder.
See Also:
UnitTranscoder, GlideBitmapDrawableTranscoder, GifBitmapWrapperDrawableTranscoder

crossFade

public DrawableRequestBuilder<ModelType> crossFade()
Applies a cross fade transformation that fades from the placeholder to the loaded Drawable. If no placeholder is set, the Drawable will instead simply fade in.

Returns:
This request builder.
See Also:
crossFade(int), crossFade(int, int), crossFade(android.view.animation.Animation, int)

crossFade

public DrawableRequestBuilder<ModelType> crossFade(int duration)
Applies a cross fade transformation that fades from the placeholder to the loaded Drawable. If no placeholder is set the Drawable will instead simply fade in.

Parameters:
duration - The duration of the cross fade and initial fade in.
Returns:
This request builder.
See Also:
crossFade(), crossFade(int, int), crossFade(android.view.animation.Animation, int)

crossFade

public DrawableRequestBuilder<ModelType> crossFade(Animation animation,
                                                   int duration)
Applies a cross fade transformation that des from the placeholder to the loaded Drawable. If no placeholder is set, the Drawable will instead be animated in using the given Animation.

Parameters:
animation - The Animation to use if no placeholder is set.
duration - The duration of the cross fade animation.
Returns:
This request builder.
See Also:
crossFade(), crossFade(int), crossFade(int, int)

crossFade

public DrawableRequestBuilder<ModelType> crossFade(int animationId,
                                                   int duration)
Applies a cross fade transformation that des from the placeholder to the loaded Drawable. If no placeholder is set, the Drawable will instead be animated in using the Animation loaded from the given animation id.

Parameters:
animationId - The id of the Animation to use if no placeholder is set.
duration - The duration of the cross fade animation.
Returns:
This request builder.
See Also:
crossFade(), crossFade(int), crossFade(android.view.animation.Animation, int)

dontAnimate

public DrawableRequestBuilder<ModelType> dontAnimate()
Removes any existing animation set on the builder. Will be overridden by subsequent calls that set an animation.

Overrides:
dontAnimate in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Returns:
This request builder.

animate

public DrawableRequestBuilder<ModelType> animate(ViewPropertyAnimation.Animator animator)
Sets an animator to run a ViewPropertyAnimator on a view that the target may be wrapping when a resource load finishes. Will only be run if the load was loaded asynchronously (ie was not in the memory cache).

Overrides:
animate in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
animator - The ViewPropertyAnimation.Animator to run.
Returns:
This request builder.

animate

public DrawableRequestBuilder<ModelType> animate(int animationId)
Sets an animation to run on the wrapped target when an resource load finishes. Will only be run if the resource was loaded asynchronously (ie was not in the memory cache)

Overrides:
animate in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
animationId - The resource id of the animation to run
Returns:
This request builder.

animate

public DrawableRequestBuilder<ModelType> animate(Animation animation)
Sets an animation to run on the wrapped target when a resource load finishes. Will only be run if the resource was loaded asynchronously (ie was not in the memory cache)

Overrides:
animate in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
animation - The animation to run
Returns:
This request builder.

placeholder

public DrawableRequestBuilder<ModelType> placeholder(int resourceId)
Sets an Android resource id for a Drawable resourceto display while a resource is loading.

Overrides:
placeholder in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
resourceId - The id of the resource to use as a placeholder
Returns:
This request builder.

placeholder

public DrawableRequestBuilder<ModelType> placeholder(Drawable drawable)
Sets an Drawable to display while a resource is loading.

Overrides:
placeholder in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
drawable - The drawable to display as a placeholder.
Returns:
This request builder.

error

public DrawableRequestBuilder<ModelType> error(int resourceId)
Sets a resource to display if a load fails.

Overrides:
error in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
resourceId - The id of the resource to use as a placeholder.
Returns:
This request builder.

error

public DrawableRequestBuilder<ModelType> error(Drawable drawable)
Sets a Drawable to display if a load fails.

Overrides:
error in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
drawable - The drawable to display.
Returns:
This request builder.

listener

public DrawableRequestBuilder<ModelType> listener(RequestListener<ModelType,GlideDrawable> requestListener)
Sets a RequestBuilder listener to monitor the resource load. It's best to create a single instance of an exception handler per type of request (usually activity/fragment) rather than pass one in per request to avoid some redundant object allocation.

Overrides:
listener in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
requestListener - The request listener to use.
Returns:
This request builder.

diskCacheStrategy

public DrawableRequestBuilder<ModelType> diskCacheStrategy(DiskCacheStrategy strategy)
Sets the DiskCacheStrategy to use for this load. Defaults to DiskCacheStrategy.RESULT.

For most applications DiskCacheStrategy.RESULT is ideal. Applications that use the same resource multiple times in multiple sizes and are willing to trade off some speed and disk space in return for lower bandwidth usage may want to consider using DiskCacheStrategy.SOURCE or DiskCacheStrategy.RESULT. Any download only operations should typically use DiskCacheStrategy.SOURCE.

Overrides:
diskCacheStrategy in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
strategy - The strategy to use.
Returns:
This request builder.

skipMemoryCache

public DrawableRequestBuilder<ModelType> skipMemoryCache(boolean skip)
Allows the loaded resource to skip the memory cache.

Note - this is not a guarantee. If a request is already pending for this resource and that request is not also skipping the memory cache, the resource will be cached in memory.

Overrides:
skipMemoryCache in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
skip - True to allow the resource to skip the memory cache.
Returns:
This request builder.

override

public DrawableRequestBuilder<ModelType> override(int width,
                                                  int height)
Overrides the Target's width and height with the given values. This is useful almost exclusively for thumbnails, and should only be used when you both need a very specific sized image and when it is impossible or impractical to return that size from Target.getSize(com.bumptech.glide.request.target.SizeReadyCallback).

Overrides:
override in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
width - The width to use to load the resource.
height - The height to use to load the resource.
Returns:
This request builder.

sourceEncoder

public DrawableRequestBuilder<ModelType> sourceEncoder(Encoder<ImageVideoWrapper> sourceEncoder)
Sets the source encoder to use to encode the data retrieved by this request directly into cache. The returned resource will then be decoded from the cached data.

Overrides:
sourceEncoder in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
sourceEncoder - The encoder to use.
Returns:
This request builder.
See Also:
DiskCacheStrategy

dontTransform

public DrawableRequestBuilder<ModelType> dontTransform()
Removes the current Transformation.

Overrides:
dontTransform in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Returns:
This request builder.

into

public Target<GlideDrawable> into(ImageView view)
Sets the ImageView the resource will be loaded into, cancels any existing loads into the view, and frees any resources Glide may have previously loaded into the view so they may be reused.

Note - If no transformation is set for this load, a default transformation will be applied based on the value returned from ImageView.getScaleType(). To avoid this default transformation, use dontTransform().

Overrides:
into in class GenericRequestBuilder<ModelType,ImageVideoWrapper,GifBitmapWrapper,GlideDrawable>
Parameters:
view - The view to cancel previous loads for and load the new resource into.
Returns:
The Target used to wrap the given ImageView.
See Also:
Glide.clear(android.view.View)