com.bumptech.glide
Class GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType>

java.lang.Object
  extended by com.bumptech.glide.GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType>
Type Parameters:
ModelType - The type of model representing the resource.
DataType - The data type that the resource ModelLoader will provide that can be decoded by the ResourceDecoder.
ResourceType - The type of the resource that will be loaded.
TranscodeType - The type of resource the decoded resource will be transcoded to.
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
BitmapRequestBuilder, DrawableRequestBuilder, GenericTranscodeRequest, GifRequestBuilder

public class GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType>
extends Object
implements Cloneable

A generic class that can handle setting options and staring loads for generic resource types.


Field Summary
protected  Context context
           
protected  Glide glide
           
protected  Lifecycle lifecycle
           
protected  Class<ModelType> modelClass
           
protected  RequestTracker requestTracker
           
protected  Class<TranscodeType> transcodeClass
           
 
Method Summary
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> animate(Animation animation)
          Deprecated. If this builder is used for multiple loads, using this method will result in multiple view's being asked to start an animation using a single Animation object which results in views animating repeatedly. Use animate(int) or animate(com.bumptech.glide.request.animation.ViewPropertyAnimation.Animator). Scheduled to be removed in Glide 4.0.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> animate(int animationId)
          Sets an animation to run on the wrapped target when an resource load finishes.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> cacheDecoder(ResourceDecoder<File,ResourceType> cacheDecoder)
          Sets the ResourceDecoder to use to load the resource from the disk cache.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> clone()
          Returns a copy of this request builder with all of the options set so far on this builder.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> decoder(ResourceDecoder<DataType,ResourceType> decoder)
          Sets the ResourceDecoder to use to load the resource from the original data.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> diskCacheStrategy(DiskCacheStrategy strategy)
          Sets the DiskCacheStrategy to use for this load.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> dontAnimate()
          Removes any existing animation set on the builder.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> dontTransform()
          Removes the current Transformation.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> encoder(ResourceEncoder<ResourceType> encoder)
          Sets the Encoder to use to encode the original data directly to cache.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> error(Drawable drawable)
          Sets a Drawable to display if a load fails.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> error(int resourceId)
          Sets a resource to display if a load fails.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> fallback(Drawable drawable)
          Sets an Drawable to display if the model provided to load(Object) is null.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> fallback(int resourceId)
          Sets a resource to display if the model provided to load(Object) is null.
 Target<TranscodeType> 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.
 FutureTarget<TranscodeType> into(int width, int height)
          Returns a future that can be used to do a blocking get on a background thread.
<Y extends Target<TranscodeType>>
Y
into(Y target)
          Set the target the resource will be loaded into.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> listener(RequestListener<? super ModelType,TranscodeType> requestListener)
          Sets a RequestBuilder listener to monitor the resource load.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> load(ModelType model)
          Sets the specific model to load data for.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> override(int width, int height)
          Overrides the Target's width and height with the given values.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> placeholder(Drawable drawable)
          Sets an Drawable to display while a resource is loading.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> placeholder(int resourceId)
          Sets an Android resource id for a Drawable resourceto display while a resource is loading.
 Target<TranscodeType> preload()
          Preloads the resource into the cache using Target.SIZE_ORIGINAL as the target width and height.
 Target<TranscodeType> preload(int width, int height)
          Preloads the resource into the cache using the given width and height.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> priority(Priority priority)
          Sets the priority for this load.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> signature(Key signature)
          Sets some additional data to be mixed in to the memory and disk cache keys allowing the caller more control over when cached data is invalidated.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> sizeMultiplier(float sizeMultiplier)
          Applies a multiplier to the Target's size before loading the resource.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> skipMemoryCache(boolean skip)
          Allows the loaded resource to skip the memory cache.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> sourceEncoder(Encoder<DataType> sourceEncoder)
          Sets the source encoder to use to encode the data retrieved by this request directly into cache.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> thumbnail(GenericRequestBuilder<?,?,?,TranscodeType> thumbnailRequest)
          Loads and displays the resource retrieved by the given thumbnail request if it finishes before this request.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> transcoder(ResourceTranscoder<ResourceType,TranscodeType> transcoder)
          Sets the ResourceTranscoder to use for this load.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> transform(Transformation<ResourceType>... transformations)
          Transform resources with the given Transformations.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

modelClass

protected final Class<ModelType> modelClass

context

protected final Context context

glide

protected final Glide glide

transcodeClass

protected final Class<TranscodeType> transcodeClass

requestTracker

protected final RequestTracker requestTracker

lifecycle

protected final Lifecycle lifecycle
Method Detail

thumbnail

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> thumbnail(GenericRequestBuilder<?,?,?,TranscodeType> 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 full size 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.

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

Recursive calls to thumbnail are supported.


thumbnail

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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, placeholder(int) and error(int), and listener(RequestListener) will only be used on the fullsize load and will not be copied for the thumbnail load.

Recursive calls to thumbnail are supported.

Parameters:
sizeMultiplier - The multiplier to apply to the Target's dimensions when loading the thumbnail.
Returns:
This request builder.

sizeMultiplier

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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.

Parameters:
sizeMultiplier - The multiplier to apply to the Target's dimensions when loading the resource.
Returns:
This request builder.

decoder

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> decoder(ResourceDecoder<DataType,ResourceType> 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.

Parameters:
decoder - The ResourceDecoder to use to decode the resource.
Returns:
This request builder.
See Also:
cacheDecoder(com.bumptech.glide.load.ResourceDecoder), DiskCacheStrategy

cacheDecoder

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> cacheDecoder(ResourceDecoder<File,ResourceType> 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.

Parameters:
cacheDecoder - The decoder to use.
Returns:
This request builder.
See Also:
decoder(com.bumptech.glide.load.ResourceDecoder), DiskCacheStrategy

sourceEncoder

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> sourceEncoder(Encoder<DataType> 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.

Parameters:
sourceEncoder - The encoder to use.
Returns:
This request builder.
See Also:
DiskCacheStrategy

diskCacheStrategy

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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.

Parameters:
strategy - The strategy to use.
Returns:
This request builder.

encoder

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> encoder(ResourceEncoder<ResourceType> 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.

Parameters:
encoder - The encoder to use.
Returns:
This request builder.
See Also:
sourceEncoder(com.bumptech.glide.load.Encoder), DiskCacheStrategy

priority

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> priority(Priority priority)
Sets the priority for this load.

Parameters:
priority - A priority.
Returns:
This request builder.

transform

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> transform(Transformation<ResourceType>... transformations)
Transform resources with the given Transformations. Replaces any existing transformation or transformations.

Parameters:
transformations - the transformations to apply in order.
Returns:
This request builder.

dontTransform

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> dontTransform()
Removes the current Transformation.

Returns:
This request builder.

transcoder

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> transcoder(ResourceTranscoder<ResourceType,TranscodeType> transcoder)
Sets the ResourceTranscoder to use for this load.

Parameters:
transcoder - The transcoder to use.
Returns:
This request builder.
See Also:
UnitTranscoder, GlideBitmapDrawableTranscoder, GifBitmapWrapperDrawableTranscoder

dontAnimate

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

Returns:
This request builder.

animate

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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)

Parameters:
animationId - The resource id of the animation to run
Returns:
This request builder.

animate

@Deprecated
public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> animate(Animation animation)
Deprecated. If this builder is used for multiple loads, using this method will result in multiple view's being asked to start an animation using a single Animation object which results in views animating repeatedly. Use animate(int) or animate(com.bumptech.glide.request.animation.ViewPropertyAnimation.Animator). Scheduled to be removed in Glide 4.0.

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)

Parameters:
animation - The animation to run
Returns:
This request builder.
See Also:
animate(int), animate(com.bumptech.glide.request.animation.ViewPropertyAnimation.Animator)

animate

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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).

Parameters:
animator - The ViewPropertyAnimation.Animator to run.
Returns:
This request builder.

placeholder

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> placeholder(int resourceId)
Sets an Android resource id for a Drawable resourceto display while a resource is loading.

Parameters:
resourceId - The id of the resource to use as a placeholder
Returns:
This request builder.

placeholder

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> placeholder(Drawable drawable)
Sets an Drawable to display while a resource is loading.

Parameters:
drawable - The drawable to display as a placeholder.
Returns:
This request builder.

fallback

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> fallback(Drawable drawable)
Sets an Drawable to display if the model provided to load(Object) is null.

If a fallback is not set, null models will cause the error drawable to be displayed. If the error drawable is not set, the placeholder will be displayed.

Parameters:
drawable - The drawable to display as a placeholder.
Returns:
This request builder.
See Also:
placeholder(Drawable), placeholder(int)

fallback

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> fallback(int resourceId)
Sets a resource to display if the model provided to load(Object) is null.

If a fallback is not set, null models will cause the error drawable to be displayed. If the error drawable is not set, the placeholder will be displayed.

Parameters:
resourceId - The id of the resource to use as a fallback.
Returns:
This request builder.
See Also:
placeholder(Drawable), placeholder(int)

error

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> error(int resourceId)
Sets a resource to display if a load fails.

Parameters:
resourceId - The id of the resource to use as a placeholder.
Returns:
This request builder.

error

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> error(Drawable drawable)
Sets a Drawable to display if a load fails.

Parameters:
drawable - The drawable to display.
Returns:
This request builder.

listener

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> listener(RequestListener<? super ModelType,TranscodeType> 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.

Parameters:
requestListener - The request listener to use.
Returns:
This request builder.

skipMemoryCache

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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.

Parameters:
skip - True to allow the resource to skip the memory cache.
Returns:
This request builder.

override

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> 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).

Parameters:
width - The width in pixels to use to load the resource.
height - The height in pixels to use to load the resource.
Returns:
This request builder.

signature

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> signature(Key signature)
Sets some additional data to be mixed in to the memory and disk cache keys allowing the caller more control over when cached data is invalidated.

Note - The signature does not replace the cache key, it is purely additive.

Parameters:
signature - A unique non-null Key representing the current state of the model that will be mixed in to the cache key.
Returns:
This request builder.
See Also:
StringSignature

load

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> load(ModelType model)
Sets the specific model to load data for.

This method must be called at least once before into(com.bumptech.glide.request.target.Target) is called.

Parameters:
model - The model to load data for, or null.
Returns:
This request builder.

clone

public GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> clone()
Returns a copy of this request builder with all of the options set so far on this builder.

This method returns a "deep" copy in that all non-immutable arguments are copied such that changes to one builder will not affect the other builder. However, in addition to immutable arguments, the current model is not copied copied so changes to the model will affect both builders.

Overrides:
clone in class Object

into

public <Y extends Target<TranscodeType>> Y into(Y target)
Set the target the resource will be loaded into.

Parameters:
target - The target to load the resource into.
Returns:
The given target.
See Also:
Glide.clear(com.bumptech.glide.request.target.Target)

into

public Target<TranscodeType> 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.

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)

into

public FutureTarget<TranscodeType> into(int width,
                                        int height)
Returns a future that can be used to do a blocking get on a background thread.

Parameters:
width - The desired width in pixels, or Target.SIZE_ORIGINAL. This will be overridden by * (int, int) if previously called.
height - The desired height in pixels, or Target.SIZE_ORIGINAL. This will be overridden by * (int, int)} if previously called).
Returns:
An FutureTarget that can be used to obtain the resource in a blocking manner.
See Also:
Glide.clear(com.bumptech.glide.request.FutureTarget)

preload

public Target<TranscodeType> preload(int width,
                                     int height)
Preloads the resource into the cache using the given width and height.

Pre-loading is useful for making sure that resources you are going to to want in the near future are available quickly.

Parameters:
width - The desired width in pixels, or Target.SIZE_ORIGINAL. This will be overridden by * (int, int) if previously called.
height - The desired height in pixels, or Target.SIZE_ORIGINAL. This will be overridden by * (int, int)} if previously called).
Returns:
A Target that can be used to cancel the load via Glide.clear(com.bumptech.glide.request.target.Target).
See Also:
ListPreloader

preload

public Target<TranscodeType> preload()
Preloads the resource into the cache using Target.SIZE_ORIGINAL as the target width and height. Equivalent to calling preload(int, int) with Target.SIZE_ORIGINAL as the width and height.

Returns:
A Target that can be used to cancel the load via Glide.clear(com.bumptech.glide.request.target.Target).
See Also:
preload(int, int)