TranscodeType
- The type of resource that will be delivered to the
Target
.public class RequestBuilder<TranscodeType> extends Object implements Cloneable
Modifier and Type | Field and Description |
---|---|
protected static RequestOptions |
DOWNLOAD_ONLY_OPTIONS |
protected RequestOptions |
requestOptions |
Modifier | Constructor and Description |
---|---|
protected |
RequestBuilder(Class<TranscodeType> transcodeClass,
RequestBuilder<?> other) |
protected |
RequestBuilder(Glide glide,
RequestManager requestManager,
Class<TranscodeType> transcodeClass,
Context context) |
Modifier and Type | Method and Description |
---|---|
RequestBuilder<TranscodeType> |
apply(RequestOptions requestOptions)
Applies the given options to the request, options set or unset in the given options will
replace those previously set in options in this class.
|
RequestBuilder<TranscodeType> |
clone()
Returns a copy of this request builder with all of the options put so far on this builder.
|
FutureTarget<File> |
downloadOnly(int width,
int height)
Deprecated.
|
<Y extends Target<File>> |
downloadOnly(Y target)
Deprecated.
|
RequestBuilder<TranscodeType> |
error(RequestBuilder<TranscodeType> errorBuilder)
Sets a
RequestBuilder that is built and run iff the load started by this
RequestBuilder fails. |
protected RequestBuilder<File> |
getDownloadOnlyRequest() |
protected RequestOptions |
getMutableOptions() |
ViewTarget<ImageView,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)
Deprecated.
Use
submit(int, int) instead. |
<Y extends Target<TranscodeType>> |
into(Y target)
Set the target the resource will be loaded into.
|
RequestBuilder<TranscodeType> |
listener(RequestListener<TranscodeType> requestListener)
Sets a
RequestListener to monitor the resource load. |
RequestBuilder<TranscodeType> |
load(Bitmap bitmap)
Returns an object to load the given
Bitmap . |
RequestBuilder<TranscodeType> |
load(byte[] model)
Returns a request to load the given byte array.
|
RequestBuilder<TranscodeType> |
load(Drawable drawable)
Returns a request builder to load the given
Drawable . |
RequestBuilder<TranscodeType> |
load(File file)
Returns a request builder to load the given
File . |
RequestBuilder<TranscodeType> |
load(Integer resourceId)
Returns a request builder that uses the
ModelLoaderFactory currently registered or
Integer to load the image represented by the given Integer resource id. |
RequestBuilder<TranscodeType> |
load(Object model)
Sets the specific model to load data for.
|
RequestBuilder<TranscodeType> |
load(String string)
Returns a request builder to load the given
String . |
RequestBuilder<TranscodeType> |
load(Uri uri)
Returns a request builder to load the given
Uri . |
RequestBuilder<TranscodeType> |
load(URL url)
Deprecated.
The
URL class has
a number of performance problems and should generally be
avoided when possible. Prefer load(android.net.Uri) or load(String) . |
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.
|
FutureTarget<TranscodeType> |
submit()
Returns a future that can be used to do a blocking get on a background thread.
|
FutureTarget<TranscodeType> |
submit(int width,
int height)
Returns a future that can be used to do a blocking get on a background thread.
|
RequestBuilder<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.
|
RequestBuilder<TranscodeType> |
thumbnail(RequestBuilder<TranscodeType>... thumbnails)
Recursively applies
thumbnail(RequestBuilder) so that the RequestBuilder s are
loaded as thumbnails in the given priority order. |
RequestBuilder<TranscodeType> |
thumbnail(RequestBuilder<TranscodeType> thumbnailRequest)
Loads and displays the resource retrieved by the given thumbnail request if it finishes before
this request.
|
RequestBuilder<TranscodeType> |
transition(TransitionOptions<?,? super TranscodeType> transitionOptions)
Sets the
TransitionOptions to use to transition from the placeholder or thumbnail when
this load completes. |
protected static final RequestOptions DOWNLOAD_ONLY_OPTIONS
@NonNull protected RequestOptions requestOptions
protected RequestBuilder(Glide glide, RequestManager requestManager, Class<TranscodeType> transcodeClass, Context context)
protected RequestBuilder(Class<TranscodeType> transcodeClass, RequestBuilder<?> other)
@CheckResult public RequestBuilder<TranscodeType> apply(@NonNull RequestOptions requestOptions)
RequestOptions.apply(RequestOptions)
protected RequestOptions getMutableOptions()
@CheckResult public RequestBuilder<TranscodeType> transition(@NonNull TransitionOptions<?,? super TranscodeType> transitionOptions)
TransitionOptions
to use to transition from the placeholder or thumbnail when
this load completes.
The given TransitionOptions
will replace any TransitionOptions
set
previously.
@CheckResult public RequestBuilder<TranscodeType> listener(@Nullable RequestListener<TranscodeType> requestListener)
RequestListener
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.requestListener
- The request listener to use.public RequestBuilder<TranscodeType> error(@Nullable RequestBuilder<TranscodeType> errorBuilder)
RequestBuilder
that is built and run iff the load started by this
RequestBuilder
fails.
If this RequestBuilder
uses a thumbnail that succeeds the given error
RequestBuilder
will be started anyway if the non-thumbnail request fails.
Recursive calls to this method as well as calls to thumbnail(float)
and
thumbnail(RequestBuilder)
are supported for the given error RequestBuilder
.
Unlike thumbnail(RequestBuilder)
and thumbnail(float)
, no options from
this primary RequestBuilder
are propagated to the given error RequestBuilder
.
Options like priority, override widths and heights and transitions must be applied
independently to the error builder.
The given RequestBuilder
will start and potentially override a fallback drawable
if it's set on this RequestBuilder
via
RequestOptions.fallback(android.graphics.drawable.Drawable)
or
RequestOptions.fallback(int)
.
RequestBuilder
.@CheckResult public RequestBuilder<TranscodeType> thumbnail(@Nullable RequestBuilder<TranscodeType> thumbnailRequest)
Recursive calls to thumbnail are supported.
Overrides any previous calls to this method, thumbnail(float)
and
thumbnail(RequestBuilder[])
.
thumbnailRequest
- The request to use to load the thumbnail.thumbnail(float)
,
thumbnail(RequestBuilder[])
@CheckResult public RequestBuilder<TranscodeType> thumbnail(@Nullable RequestBuilder<TranscodeType>... thumbnails)
thumbnail(RequestBuilder)
so that the RequestBuilder
s are
loaded as thumbnails in the given priority order.
thumbnail(RequestBuilder)
is applied in the order given so that the
RequestBuilder
at position 0 has the RequestBuilder
at position 1 applied
as using its thumbnail method, the RequestBuilder
at position 1 has the
RequestBuilder
at position 2 applied using its thumbnail method and so on.
Calling this method with an null
array of RequestBuilder
thumbnails or
an empty array of RequestBuilder
thumbnails is equivalent to calling
thumbnail(RequestBuilder)
with null
.
Any individual RequestBuilder
in the array of thumbnails provided here may be
null
. null
RequestBuilder
s are ignored and excluded from the recursive
chain.
The RequestBuilder
objects provided here may be mutated and have any previous
calls to this method or thumbnail(RequestBuilder)
methods overridden.
Overrides any previous calls to thumbnail(RequestBuilder)
,
thumbnail(float)
and this method.
thumbnail(float)
,
thumbnail(RequestBuilder)
@CheckResult public RequestBuilder<TranscodeType> thumbnail(float sizeMultiplier)
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 Transformation
s. However,
RequestOptions.placeholder(int)
and
RequestOptions.error(int)
, and
listener(RequestListener)
will only be used on the full size load and will not be
copied for the thumbnail load.
Recursive calls to thumbnail are supported.
Overrides any previous calls to this method, thumbnail(RequestBuilder[])
,
and thumbnail(RequestBuilder)
.
sizeMultiplier
- The multiplier to apply to the Target
's dimensions when loading
the thumbnail.thumbnail(RequestBuilder)
,
thumbnail(RequestBuilder[])
@CheckResult public RequestBuilder<TranscodeType> load(@Nullable Object model)
model
- The model to load data for, or null.@CheckResult public RequestBuilder<TranscodeType> load(@Nullable Bitmap bitmap)
Bitmap
.
It's almost always better to allow Glide to load Bitmap
s than
pass Bitmap
s into Glide. If you have a custom way to obtain Bitmap
s that is
not supported by Glide by default, consider registering a custom
ModelLoader
or
ResourceDecoder
instead of using this method.
The DiskCacheStrategy
is set to DiskCacheStrategy.NONE
. Previous calls to
apply(RequestOptions)
or previously applied DiskCacheStrategy
s will be
overridden by this method. Applying an DiskCacheStrategy
other than
DiskCacheStrategy.NONE
after calling this method may result in undefined behavior.
In memory caching relies on Object equality. The contents of the Bitmap
s are not
compared.
load(Object)
@CheckResult public RequestBuilder<TranscodeType> load(@Nullable Drawable drawable)
Drawable
.
It's almost always better to allow Glide to load Bitmap
s than to pass
Bitmap
s into Glide using this method . If you have a custom way to obtain
Bitmap
s that is not supported by Glide by default, consider registering a custom
ModelLoader
or
ResourceDecoder
instead of using this method.
The DiskCacheStrategy
is set to DiskCacheStrategy.NONE
. Previous calls to
apply(RequestOptions)
or previously applied DiskCacheStrategy
s will be
overridden by this method. Applying an DiskCacheStrategy
other than
DiskCacheStrategy.NONE
after calling this method may result in undefined behavior.
In memory caching relies on Object equality. The contents of the Drawable
s are not
compared.
load(Object)
@CheckResult public RequestBuilder<TranscodeType> load(@Nullable String string)
String
.
Note - this method caches data using only the given String as the cache key. If the data is
a Uri outside of your control, or you otherwise expect the data represented by the given String
to change without the String identifier changing, Consider using
RequestOptions.signature(com.bumptech.glide.load.Key)
to
mixin a signature you create that identifies the data currently at the given String that will
invalidate the cache if that data changes. Alternatively, using
DiskCacheStrategy.NONE
and/or
RequestOptions.skipMemoryCache(boolean)
may be
appropriate.
string
- A file path, or a uri or url handled by
UriLoader
.load(Object)
@CheckResult public RequestBuilder<TranscodeType> load(@Nullable Uri uri)
Uri
.
Note - this method caches data at Uris using only the Uri itself as the cache key. The data
represented by Uris from some content providers may change without the Uri changing, which
means using this method can lead to displaying stale data. Consider using
RequestOptions.signature(com.bumptech.glide.load.Key)
to
mixin a signature you create based on the data at the given Uri that will invalidate the cache
if that data changes. Alternatively, using
DiskCacheStrategy.NONE
and/or
RequestOptions.skipMemoryCache(boolean)
may be
appropriate.
uri
- The Uri representing the image. Must be of a type handled by
UriLoader
.load(Object)
@CheckResult public RequestBuilder<TranscodeType> load(@Nullable File file)
File
.
Note - this method caches data for Files using only the file path itself as the cache key.
The data in the File can change so using this method can lead to displaying stale data. If you
expect the data in the File to change, Consider using
RequestOptions.signature(com.bumptech.glide.load.Key)
to mixin a signature you create that identifies the data currently in the File that will
invalidate the cache if that data changes. Alternatively, using
DiskCacheStrategy.NONE
and/or
RequestOptions.skipMemoryCache(boolean)
may be
appropriate.
file
- The File containing the imageload(Object)
@CheckResult public RequestBuilder<TranscodeType> load(@RawRes @DrawableRes @Nullable Integer resourceId)
ModelLoaderFactory
currently registered or
Integer
to load the image represented by the given Integer
resource id.
Defaults to ResourceLoader
to load resource id models.
By default this method adds a version code based signature to the cache key used to cache
this resource in Glide. This signature is sufficient to guarantee that end users will see the
most up to date versions of your Drawables, but during development if you do not increment your
version code before each install and you replace a Drawable with different data without
changing the Drawable name, you may see inconsistent cached data. To get around this, consider
using DiskCacheStrategy.NONE
via
RequestOptions.diskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy)
during development, and re-enabling the default
DiskCacheStrategy.RESOURCE
for release builds.
This method will load non-Bitmap
resources like
VectorDrawable
s. Although Glide makes a best effort to apply
Transformation
s to these Drawable
s by either extracting
the underlying Bitmap
or by converting the Drawable
to a Bitmap
, Glide
is still not able to transform all types of resources. Animated Drawable
s cannot be
transformed (other than GifDrawable
). To avoid
load failures if a Drawable
can't be transformed, use the optional transformation
methods like RequestOptions.optionalTransform(Class, Transformation)
.
In some cases converting Drawable
s to Bitmap
s may be inefficient. Use this
method, especially in conjunction with Transformation
s with
caution for non-Bitmap
Drawable
s.
load(Integer)
,
ApplicationVersionSignature
@Deprecated @CheckResult public RequestBuilder<TranscodeType> load(@Nullable URL url)
URL
class has
a number of performance problems and should generally be
avoided when possible. Prefer load(android.net.Uri)
or load(String)
.URL
.url
- The URL representing the image.load(Object)
@CheckResult public RequestBuilder<TranscodeType> load(@Nullable byte[] model)
Note - by default loads for bytes are not cached in either the memory or the disk cache.
model
- the data to load.load(Object)
@CheckResult public RequestBuilder<TranscodeType> clone()
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.
public <Y extends Target<TranscodeType>> Y into(@NonNull Y target)
target
- The target to load the resource into.RequestManager.clear(Target)
public ViewTarget<ImageView,TranscodeType> into(ImageView view)
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.view
- The view to cancel previous loads for and load the new resource into.Target
used to wrap the given ImageView
.RequestManager.clear(Target)
@Deprecated public FutureTarget<TranscodeType> into(int width, int height)
submit(int, int)
instead.width
- The desired width in pixels, or Target.SIZE_ORIGINAL
. This will be
overridden by
RequestOptions.override(int, int)
if
previously called.height
- The desired height in pixels, or Target.SIZE_ORIGINAL
. This will be
overridden by
RequestOptions.override(int, int)
} if
previously called).RequestManager.clear(Target)
public FutureTarget<TranscodeType> submit()
This method defaults to Target.SIZE_ORIGINAL
for the width and the height. However,
since the width and height will be overridden by values passed to RequestOptions.override(int, int)
, this method can be used whenever RequestOptions
with override values are applied, or whenever you want to retrieve the image in its original
size.
submit(int, int)
,
into(Target)
public FutureTarget<TranscodeType> submit(int width, int height)
width
- The desired width in pixels, or Target.SIZE_ORIGINAL
. This will be
overridden by
RequestOptions.override(int, int)
if
previously called.height
- The desired height in pixels, or Target.SIZE_ORIGINAL
. This will be
overridden by
RequestOptions.override(int, int)
} if
previously called).public Target<TranscodeType> preload(int width, int height)
Pre-loading is useful for making sure that resources you are going to to want in the near future are available quickly.
width
- The desired width in pixels, or Target.SIZE_ORIGINAL
. This will be
overridden by
RequestOptions.override(int, int)
if
previously called.height
- The desired height in pixels, or Target.SIZE_ORIGINAL
. This will be
overridden by
RequestOptions.override(int, int)
} if
previously called).Target
that can be used to cancel the load via
RequestManager.clear(Target)
.ListPreloader
public Target<TranscodeType> preload()
Target.SIZE_ORIGINAL
as the target width and
height. Equivalent to calling preload(int, int)
with Target.SIZE_ORIGINAL
as
the width and height.Target
that can be used to cancel the load via
RequestManager.clear(Target)
preload(int, int)
@Deprecated @CheckResult public <Y extends Target<File>> Y downloadOnly(Y target)
RequestManager.downloadOnly()
and into(Target)
.Y
- The type of Target.target
- The Target that will receive the cache File when the load completes@Deprecated @CheckResult public FutureTarget<File> downloadOnly(int width, int height)
RequestManager.downloadOnly()
and into(int, int)
.Future
that can be used to retrieve the cache File containing the
data.width
- The width in pixels to use to fetch the data.height
- The height in pixels to use to fetch the data.Future
that can be used to retrieve the cache File
containing the data.@CheckResult protected RequestBuilder<File> getDownloadOnlyRequest()