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.
Direct Known Subclasses:
BitmapRequestBuilder, DrawableRequestBuilder, GenericTranscodeRequest, GifRequestBuilder

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

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

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


Method Summary
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> animate(Animation animation)
          Sets an animation to run on the wrapped target when a resource load finishes.
 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> 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.
 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<ModelType,TranscodeType> requestListener)
          Sets a RequestBuilder listener to monitor the resource load.
 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.
 GenericRequestBuilder<ModelType,DataType,ResourceType,TranscodeType> priority(Priority priority)
          Sets the priority for this load.
 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<ModelType,DataType,ResourceType,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
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

thumbnail

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

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 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.

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

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

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

Parameters:
animation - The animation to run
Returns:
This request builder.

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.

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<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 to use to load the resource.
height - The height to use to load the resource.
Returns:
This request builder.

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 (note this will be overriden by override(int, int) if previously called.
height - The desired height (note this will be overriden by override(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)