com.bumptech.glide
Class BitmapRequestBuilder<ModelType,TranscodeType>

java.lang.Object
  extended by com.bumptech.glide.GenericRequestBuilder<ModelType,ImageVideoWrapper,Bitmap,TranscodeType>
      extended by com.bumptech.glide.BitmapRequestBuilder<ModelType,TranscodeType>
Type Parameters:
ModelType - The type of model that will be loaded into the target.
TranscodeType - The type of the transcoded resource that the target will receive
Direct Known Subclasses:
BitmapTypeRequest

public class BitmapRequestBuilder<ModelType,TranscodeType>
extends GenericRequestBuilder<ModelType,ImageVideoWrapper,Bitmap,TranscodeType>

A class for creating a request to load a bitmap for an image or from a video. Sets a variety of type independent options including resizing, animations, and placeholders.

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


Method Summary
 BitmapRequestBuilder<ModelType,TranscodeType> animate(Animation animation)
          Sets an animation to run on the wrapped target when a resource load finishes.
 BitmapRequestBuilder<ModelType,TranscodeType> animate(int animationId)
          Sets an animation to run on the wrapped target when an resource load finishes.
 BitmapRequestBuilder<ModelType,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.
 BitmapRequestBuilder<ModelType,TranscodeType> approximate()
          Load images at a size near the size of the target using Downsampler.AT_LEAST.
 BitmapRequestBuilder<ModelType,TranscodeType> asIs()
          Load images at their original size using Downsampler.NONE.
 BitmapRequestBuilder<ModelType,TranscodeType> atMost()
          Load images at a size that is at most exactly as big as the target using Downsampler.AT_MOST.
 BitmapRequestBuilder<ModelType,TranscodeType> cacheDecoder(ResourceDecoder<File,Bitmap> cacheDecoder)
          Sets the ResourceDecoder to use to load the resource from the disk cache.
 BitmapRequestBuilder<ModelType,TranscodeType> centerCrop()
          Transform images using CenterCrop.
 BitmapRequestBuilder<ModelType,TranscodeType> decoder(ResourceDecoder<ImageVideoWrapper,Bitmap> decoder)
          Sets the ResourceDecoder to use to load the resource from the original data.
 BitmapRequestBuilder<ModelType,TranscodeType> diskCacheStrategy(DiskCacheStrategy strategy)
          Sets the DiskCacheStrategy to use for this load.
 BitmapRequestBuilder<ModelType,TranscodeType> dontAnimate()
          Removes any existing animation set on the builder.
 BitmapRequestBuilder<ModelType,TranscodeType> dontTransform()
          Removes the current Transformation.
 BitmapRequestBuilder<ModelType,TranscodeType> encoder(ResourceEncoder<Bitmap> encoder)
          Sets the Encoder to use to encode the original data directly to cache.
 BitmapRequestBuilder<ModelType,TranscodeType> error(Drawable drawable)
          Sets a Drawable to display if a load fails.
 BitmapRequestBuilder<ModelType,TranscodeType> error(int resourceId)
          Sets a resource to display if a load fails.
 BitmapRequestBuilder<ModelType,TranscodeType> fitCenter()
          Transform images using FitCenter.
 BitmapRequestBuilder<ModelType,TranscodeType> format(DecodeFormat format)
          Sets the preferred format for Bitmaps decoded in this request.
 BitmapRequestBuilder<ModelType,TranscodeType> imageDecoder(ResourceDecoder<InputStream,Bitmap> decoder)
          Sets the ResourceDecoder that will be used to decode Bitmaps obtained from an InputStream.
 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.
 BitmapRequestBuilder<ModelType,TranscodeType> listener(RequestListener<ModelType,TranscodeType> requestListener)
          Sets a RequestBuilder listener to monitor the resource load.
 BitmapRequestBuilder<ModelType,TranscodeType> override(int width, int height)
          Overrides the Target's width and height with the given values.
 BitmapRequestBuilder<ModelType,TranscodeType> placeholder(Drawable drawable)
          Sets an Drawable to display while a resource is loading.
 BitmapRequestBuilder<ModelType,TranscodeType> placeholder(int resourceId)
          Sets an Android resource id for a Drawable resourceto display while a resource is loading.
 BitmapRequestBuilder<ModelType,TranscodeType> priority(Priority priority)
          Sets the priority for this load.
 BitmapRequestBuilder<ModelType,TranscodeType> sizeMultiplier(float sizeMultiplier)
          Applies a multiplier to the Target's size before loading the resource.
 BitmapRequestBuilder<ModelType,TranscodeType> skipMemoryCache(boolean skip)
          Allows the loaded resource to skip the memory cache.
 BitmapRequestBuilder<ModelType,TranscodeType> sourceEncoder(Encoder<ImageVideoWrapper> sourceEncoder)
          Sets the source encoder to use to encode the data retrieved by this request directly into cache.
 BitmapRequestBuilder<ModelType,TranscodeType> thumbnail(BitmapRequestBuilder<ModelType,TranscodeType> thumbnailRequest)
          Loads and displays the Bitmap retrieved by the given thumbnail request if it finishes before this request.
 BitmapRequestBuilder<ModelType,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.
 BitmapRequestBuilder<ModelType,TranscodeType> thumbnail(GenericRequestBuilder<ModelType,ImageVideoWrapper,Bitmap,TranscodeType> thumbnailRequest)
          Loads and displays the resource retrieved by the given thumbnail request if it finishes before this request.
 BitmapRequestBuilder<ModelType,TranscodeType> transcoder(ResourceTranscoder<Bitmap,TranscodeType> transcoder)
          Sets the ResourceTranscoder to use for this load.
 BitmapRequestBuilder<ModelType,TranscodeType> transform(BitmapTransformation... transformations)
          Transform images using the given BitmapTransformations.
 BitmapRequestBuilder<ModelType,TranscodeType> transform(Transformation<Bitmap>... transformations)
          Transform resources with the given Transformations.
 BitmapRequestBuilder<ModelType,TranscodeType> videoDecoder(ResourceDecoder<ParcelFileDescriptor,Bitmap> decoder)
          Sets the ResourceDecoder that will be used to decode Bitmaps obtained from an ParcelFileDescriptor.
 
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

approximate

public BitmapRequestBuilder<ModelType,TranscodeType> approximate()
Load images at a size near the size of the target using Downsampler.AT_LEAST.

Returns:
This request builder.
See Also:
downsample(Downsampler)

asIs

public BitmapRequestBuilder<ModelType,TranscodeType> asIs()
Load images at their original size using Downsampler.NONE.

Returns:
This request builder.
See Also:
downsample(Downsampler)

atMost

public BitmapRequestBuilder<ModelType,TranscodeType> atMost()
Load images at a size that is at most exactly as big as the target using Downsampler.AT_MOST.

Returns:
This request builder.
See Also:
downsample(com.bumptech.glide.load.resource.bitmap.Downsampler)

thumbnail

public BitmapRequestBuilder<ModelType,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, 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,Bitmap,TranscodeType>
Parameters:
sizeMultiplier - The multiplier to apply to the Target's dimensions when loading the thumbnail.
Returns:
This request builder.

thumbnail

public BitmapRequestBuilder<ModelType,TranscodeType> thumbnail(BitmapRequestBuilder<ModelType,TranscodeType> thumbnailRequest)
Loads and displays the Bitmap retrieved by the given thumbnail request if it finishes before this request. Best used for loading thumbnail Bitmaps that are smaller and will be loaded more quickly than the fullsize Bitmap. 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 Bitmap will never replace the full image.

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 {@link android.graphics.Bitmap} 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.


sizeMultiplier

public BitmapRequestBuilder<ModelType,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.

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

decoder

public BitmapRequestBuilder<ModelType,TranscodeType> decoder(ResourceDecoder<ImageVideoWrapper,Bitmap> 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,Bitmap,TranscodeType>
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 BitmapRequestBuilder<ModelType,TranscodeType> cacheDecoder(ResourceDecoder<File,Bitmap> 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,Bitmap,TranscodeType>
Parameters:
cacheDecoder - The decoder to use.
Returns:
This request builder.
See Also:
GenericRequestBuilder.decoder(com.bumptech.glide.load.ResourceDecoder), DiskCacheStrategy

encoder

public BitmapRequestBuilder<ModelType,TranscodeType> encoder(ResourceEncoder<Bitmap> 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,Bitmap,TranscodeType>
Parameters:
encoder - The encoder to use.
Returns:
This request builder.
See Also:
GenericRequestBuilder.sourceEncoder(com.bumptech.glide.load.Encoder), DiskCacheStrategy

imageDecoder

public BitmapRequestBuilder<ModelType,TranscodeType> imageDecoder(ResourceDecoder<InputStream,Bitmap> decoder)
Sets the ResourceDecoder that will be used to decode Bitmaps obtained from an InputStream.

Parameters:
decoder - The decoder to use to decode Bitmaps.
Returns:
This request builder.
See Also:
videoDecoder

videoDecoder

public BitmapRequestBuilder<ModelType,TranscodeType> videoDecoder(ResourceDecoder<ParcelFileDescriptor,Bitmap> decoder)
Sets the ResourceDecoder that will be used to decode Bitmaps obtained from an ParcelFileDescriptor.

Parameters:
decoder - The decoder to use to decode Bitmaps.
Returns:
This request builder.

format

public BitmapRequestBuilder<ModelType,TranscodeType> format(DecodeFormat format)
Sets the preferred format for Bitmaps decoded in this request. Defaults to DecodeFormat.PREFER_RGB_565. This replaces any previous calls to imageDecoder(ResourceDecoder), videoDecoder(ResourceDecoder) and decoder(ResourceDecoder) with default decoders with the appropriate options set.

Note - If using a Transformation that expect bitmaps to support transparency, this should always be set to ALWAYS_ARGB_8888. RGB_565 requires fewer bytes per pixel and is generally preferable, but it does not support transparency.

Parameters:
format - The format to use.
Returns:
This request builder.
See Also:
DecodeFormat

priority

public BitmapRequestBuilder<ModelType,TranscodeType> priority(Priority priority)
Description copied from class: GenericRequestBuilder
Sets the priority for this load.

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

transform

public BitmapRequestBuilder<ModelType,TranscodeType> transform(BitmapTransformation... transformations)
Transform images using the given BitmapTransformations.

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

centerCrop

public BitmapRequestBuilder<ModelType,TranscodeType> centerCrop()
Transform images using CenterCrop.

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

fitCenter

public BitmapRequestBuilder<ModelType,TranscodeType> fitCenter()
Transform images using FitCenter.

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

transform

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

Overrides:
transform in class GenericRequestBuilder<ModelType,ImageVideoWrapper,Bitmap,TranscodeType>
Parameters:
transformations - the transformations to apply in order.
Returns:
This request builder.
See Also:
fitCenter(), centerCrop()

transcoder

public BitmapRequestBuilder<ModelType,TranscodeType> transcoder(ResourceTranscoder<Bitmap,TranscodeType> transcoder)
Sets the ResourceTranscoder to use for this load.

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

dontAnimate

public BitmapRequestBuilder<ModelType,TranscodeType> 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,Bitmap,TranscodeType>
Returns:
This request builder.

animate

public BitmapRequestBuilder<ModelType,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)

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

animate

public BitmapRequestBuilder<ModelType,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)

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

animate

public BitmapRequestBuilder<ModelType,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).

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

placeholder

public BitmapRequestBuilder<ModelType,TranscodeType> 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,Bitmap,TranscodeType>
Parameters:
resourceId - The id of the resource to use as a placeholder
Returns:
This request builder.

placeholder

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

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

error

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

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

error

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

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

listener

public BitmapRequestBuilder<ModelType,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.

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

skipMemoryCache

public BitmapRequestBuilder<ModelType,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.

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

diskCacheStrategy

public BitmapRequestBuilder<ModelType,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.

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

override

public BitmapRequestBuilder<ModelType,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).

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

thumbnail

public BitmapRequestBuilder<ModelType,TranscodeType> thumbnail(GenericRequestBuilder<ModelType,ImageVideoWrapper,Bitmap,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.

Overrides:
thumbnail in class GenericRequestBuilder<ModelType,ImageVideoWrapper,Bitmap,TranscodeType>
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.


sourceEncoder

public BitmapRequestBuilder<ModelType,TranscodeType> 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,Bitmap,TranscodeType>
Parameters:
sourceEncoder - The encoder to use.
Returns:
This request builder.
See Also:
DiskCacheStrategy

dontTransform

public BitmapRequestBuilder<ModelType,TranscodeType> dontTransform()
Removes the current Transformation.

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

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.

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,Bitmap,TranscodeType>
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)