public class RequestManager extends java.lang.Object implements android.content.ComponentCallbacks2, LifecycleListener
Modifier and Type | Field and Description |
---|---|
protected android.content.Context |
context |
protected Glide |
glide |
Constructor and Description |
---|
RequestManager(Glide glide,
Lifecycle lifecycle,
RequestManagerTreeNode treeNode,
android.content.Context context) |
Modifier and Type | Method and Description |
---|---|
RequestManager |
addDefaultRequestListener(RequestListener<java.lang.Object> requestListener)
Adds a default
RequestListener that will be added to every request started with this
RequestManager . |
RequestManager |
applyDefaultRequestOptions(RequestOptions requestOptions)
Updates the default
RequestOptions for all loads started with this request manager with
the given RequestOptions . |
<ResourceType> |
as(java.lang.Class<ResourceType> resourceClass)
Attempts to load the resource using any registered
ResourceDecoder s that can decode the given resource class or any
subclass of the given resource class. |
RequestBuilder<android.graphics.Bitmap> |
asBitmap()
Attempts to always load the resource as a
Bitmap , even if it could
actually be animated. |
RequestBuilder<android.graphics.drawable.Drawable> |
asDrawable()
Attempts to always load the resource using any registered
ResourceDecoder s that can decode any subclass of Drawable . |
RequestBuilder<java.io.File> |
asFile()
Attempts to always load a
File containing the resource, either using a file path
obtained from the media store (for local images/videos), or using Glide's disk cache (for
remote images/videos). |
RequestBuilder<GifDrawable> |
asGif()
Attempts to always load the resource as a
GifDrawable . |
void |
clear(Target<?> target)
Cancel any pending loads Glide may have for the target and free any resources (such as
Bitmap s) that may have been loaded for the target so they may be reused. |
void |
clear(android.view.View view)
Cancel any pending loads Glide may have for the view and free any resources that may have been
loaded for the view.
|
RequestBuilder<java.io.File> |
download(java.lang.Object model)
A helper method equivalent to calling
downloadOnly() ()} and then RequestBuilder.load(Object) with the given model. |
RequestBuilder<java.io.File> |
downloadOnly()
Attempts always load the resource into the cache and return the
File containing the
cached source data. |
boolean |
isPaused()
Returns true if loads for this
RequestManager are currently paused. |
RequestBuilder<android.graphics.drawable.Drawable> |
load(android.graphics.Bitmap bitmap)
Equivalent to calling
asDrawable() and then RequestBuilder.load(Bitmap) . |
RequestBuilder<android.graphics.drawable.Drawable> |
load(byte[] model)
Equivalent to calling
asDrawable() and then RequestBuilder.load(byte[]) . |
RequestBuilder<android.graphics.drawable.Drawable> |
load(android.graphics.drawable.Drawable drawable)
Equivalent to calling
asDrawable() and then RequestBuilder.load(Drawable) . |
RequestBuilder<android.graphics.drawable.Drawable> |
load(java.io.File file)
Equivalent to calling
asDrawable() and then RequestBuilder.load(File) . |
RequestBuilder<android.graphics.drawable.Drawable> |
load(java.lang.Integer resourceId)
Equivalent to calling
asDrawable() and then RequestBuilder.load(Integer) . |
RequestBuilder<android.graphics.drawable.Drawable> |
load(java.lang.Object model)
A helper method equivalent to calling
asDrawable() and then RequestBuilder.load(Object) with the given model. |
RequestBuilder<android.graphics.drawable.Drawable> |
load(java.lang.String string)
Equivalent to calling
asDrawable() and then RequestBuilder.load(String) . |
RequestBuilder<android.graphics.drawable.Drawable> |
load(android.net.Uri uri)
Equivalent to calling
asDrawable() and then RequestBuilder.load(Uri) . |
RequestBuilder<android.graphics.drawable.Drawable> |
load(java.net.URL url)
Deprecated.
|
void |
onConfigurationChanged(android.content.res.Configuration newConfig) |
void |
onDestroy()
Lifecycle callback that cancels all in progress requests and clears and recycles resources for
all completed requests.
|
void |
onLowMemory() |
void |
onStart()
Lifecycle callback that registers for connectivity events (if the
android.permission.ACCESS_NETWORK_STATE permission is present) and restarts failed or paused
requests.
|
void |
onStop()
Lifecycle callback that unregisters for connectivity events (if the
android.permission.ACCESS_NETWORK_STATE permission is present) and pauses in progress loads.
|
void |
onTrimMemory(int level) |
void |
pauseAllRequests()
Cancels any in progress loads and clears resources of completed loads.
|
void |
pauseAllRequestsRecursive()
Performs
pauseAllRequests() recursively for all managers that are contextually
descendant to this manager based on the Activity/Fragment hierarchy. |
void |
pauseRequests()
Cancels any in progress loads, but does not clear resources of completed loads.
|
void |
pauseRequestsRecursive()
Performs
pauseRequests() recursively for all managers that are contextually descendant
to this manager based on the Activity/Fragment hierarchy:
When pausing on an Activity all attached fragments will also get paused. |
void |
resumeRequests()
Restarts any loads that have not yet completed.
|
void |
resumeRequestsRecursive()
Performs
resumeRequests() recursively for all managers that are contextually
descendant to this manager based on the Activity/Fragment hierarchy. |
RequestManager |
setDefaultRequestOptions(RequestOptions requestOptions)
Replaces the default
RequestOptions for all loads started with this request manager
with the given RequestOptions . |
void |
setPauseAllRequestsOnTrimMemoryModerate(boolean pauseAllOnTrim)
If
true then clear all in-progress and completed requests when the platform sends
onTrimMemory with level = TRIM_MEMORY_MODERATE . |
protected void |
setRequestOptions(RequestOptions toSet) |
java.lang.String |
toString() |
protected final Glide glide
protected final android.content.Context context
public RequestManager(@NonNull Glide glide, @NonNull Lifecycle lifecycle, @NonNull RequestManagerTreeNode treeNode, @NonNull android.content.Context context)
protected void setRequestOptions(@NonNull RequestOptions toSet)
@NonNull public RequestManager applyDefaultRequestOptions(@NonNull RequestOptions requestOptions)
RequestOptions
for all loads started with this request manager with
the given RequestOptions
.
The RequestOptions
provided here are applied on top of those provided via GlideBuilder.setDefaultRequestOptions(RequestOptions)
. If there are conflicts, the options
applied here will win. Note that this method does not mutate options provided to GlideBuilder.setDefaultRequestOptions(RequestOptions)
.
Multiple sets of options can be applied. If there are conflicts the last RequestOptions
applied will win.
The modified options will only be applied to loads started after this method is called.
RequestBuilder.apply(BaseRequestOptions)
@NonNull public RequestManager setDefaultRequestOptions(@NonNull RequestOptions requestOptions)
RequestOptions
for all loads started with this request manager
with the given RequestOptions
.
The RequestOptions
provided here replace those that have been previously provided
via this method, GlideBuilder.setDefaultRequestOptions(RequestOptions)
, and applyDefaultRequestOptions(RequestOptions)
.
Subsequent calls to applyDefaultRequestOptions(RequestOptions)
will not mutate the
RequestOptions
provided here. Instead the manager will create a clone of these options
and mutate the clone.
applyDefaultRequestOptions(RequestOptions)
public RequestManager addDefaultRequestListener(RequestListener<java.lang.Object> requestListener)
RequestListener
that will be added to every request started with this
RequestManager
.
Multiple RequestListener
s can be added here, in RequestManager
scopes or to
individual RequestBuilder
s. RequestListener
s are called in the order they're
added. Even if an earlier RequestListener
returns true
from RequestListener.onLoadFailed(GlideException, Object, Target, boolean)
or RequestListener.onResourceReady(Object, Object, Target, DataSource, boolean)
, it will not
prevent subsequent RequestListener
s from being called.
Because Glide requests can be started for any number of individual resource types, any
listener added here has to accept any generic resource type in RequestListener.onResourceReady(Object, Object, Target, DataSource, boolean)
. If you must base
the behavior of the listener on the resource type, you will need to use instanceof
to
do so. It's not safe to cast resource types without first checking with instanceof
.
public void setPauseAllRequestsOnTrimMemoryModerate(boolean pauseAllOnTrim)
true
then clear all in-progress and completed requests when the platform sends
onTrimMemory
with level = TRIM_MEMORY_MODERATE
.public boolean isPaused()
RequestManager
are currently paused.pauseRequests()
,
resumeRequests()
public void pauseRequests()
Note #resumeRequests()
must be called for any requests made before or while the
manager is paused to complete. RequestManagers attached to Fragments and Activities
automatically resume onStart().
isPaused()
,
resumeRequests()
public void pauseAllRequests()
Note #resumeRequests()
must be called for any requests made before or while the
manager is paused to complete. RequestManagers attached to Fragments and Activities
automatically resume onStart().
This will release the memory used by completed bitmaps but leaves them in any configured
caches. When an #Activity
receives #Activity.onTrimMemory(int)
at a level of #ComponentCallbacks2.TRIM_MEMORY_BACKGROUND
this is desirable in order to keep
your process alive longer.
isPaused()
,
resumeRequests()
public void pauseAllRequestsRecursive()
pauseAllRequests()
recursively for all managers that are contextually
descendant to this manager based on the Activity/Fragment hierarchy.
Similar to pauseRequestsRecursive()
with the exception that it also clears
resources of completed loads.
public void pauseRequestsRecursive()
pauseRequests()
recursively for all managers that are contextually descendant
to this manager based on the Activity/Fragment hierarchy:
Note, on pre-Jelly Bean MR1 calling pause on a Fragment will not cause child fragments to pause, in this case either call pause on the Activity or use a support Fragment.
public void resumeRequests()
isPaused()
,
pauseRequests()
public void resumeRequestsRecursive()
resumeRequests()
recursively for all managers that are contextually
descendant to this manager based on the Activity/Fragment hierarchy. The hierarchical semantics
are identical as for pauseRequestsRecursive()
.public void onStart()
onStart
in interface LifecycleListener
public void onStop()
onStop
in interface LifecycleListener
public void onDestroy()
onDestroy
in interface LifecycleListener
@NonNull @CheckResult public RequestBuilder<android.graphics.Bitmap> asBitmap()
Bitmap
, even if it could
actually be animated.Bitmap
@NonNull @CheckResult public RequestBuilder<GifDrawable> asGif()
GifDrawable
.
If the underlying data is not a GIF, this will fail. As a result, this should only be used
if the model represents an animated GIF and the caller wants to interact with the GifDrawable
directly. Normally using just asDrawable()
is sufficient because it will determine
whether or not the given data represents an animated GIF and return the appropriate Drawable
, animated or not, automatically.
GifDrawable
.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> asDrawable()
ResourceDecoder
s that can decode any subclass of Drawable
.
By default, may return either a BitmapDrawable
or GifDrawable
, but if additional decoders are registered for other Drawable
subclasses,
any of those subclasses may also be returned.
Drawable
.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> load(@Nullable android.graphics.Bitmap bitmap)
asDrawable()
and then RequestBuilder.load(Bitmap)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> load(@Nullable android.graphics.drawable.Drawable drawable)
asDrawable()
and then RequestBuilder.load(Drawable)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> load(@Nullable java.lang.String string)
asDrawable()
and then RequestBuilder.load(String)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> load(@Nullable android.net.Uri uri)
asDrawable()
and then RequestBuilder.load(Uri)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> load(@Nullable java.io.File file)
asDrawable()
and then RequestBuilder.load(File)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> load(@RawRes @DrawableRes @Nullable java.lang.Integer resourceId)
asDrawable()
and then RequestBuilder.load(Integer)
.Drawable
using the given model.@CheckResult @Deprecated public RequestBuilder<android.graphics.drawable.Drawable> load(@Nullable java.net.URL url)
asDrawable()
and then RequestBuilder.load(URL)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> load(@Nullable byte[] model)
asDrawable()
and then RequestBuilder.load(byte[])
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<android.graphics.drawable.Drawable> load(@Nullable java.lang.Object model)
asDrawable()
and then RequestBuilder.load(Object)
with the given model.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<java.io.File> downloadOnly()
File
containing the
cached source data.
This method is designed to work for remote data that is or will be cached using DiskCacheStrategy.DATA
. As a result, specifying a DiskCacheStrategy
on this request is generally not recommended.
@NonNull @CheckResult public RequestBuilder<java.io.File> download(@Nullable java.lang.Object model)
downloadOnly()
()} and then RequestBuilder.load(Object)
with the given model.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<java.io.File> asFile()
File
containing the resource, either using a file path
obtained from the media store (for local images/videos), or using Glide's disk cache (for
remote images/videos).
For remote content, prefer downloadOnly()
.
@NonNull @CheckResult public <ResourceType> RequestBuilder<ResourceType> as(@NonNull java.lang.Class<ResourceType> resourceClass)
ResourceDecoder
s that can decode the given resource class or any
subclass of the given resource class.resourceClass
- The resource to decode.public void clear(@NonNull android.view.View view)
Note that this will only work if View.setTag(Object)
is not called on this view
outside of Glide.
view
- The view to cancel loads and free resources for.java.lang.IllegalArgumentException
- if an object other than Glide's metadata is put as the view's
tag.clear(Target)
public void clear(@Nullable Target<?> target)
Bitmap
s) that may have been loaded for the target so they may be reused.target
- The Target to cancel loads for.public java.lang.String toString()
toString
in class java.lang.Object
public void onTrimMemory(int level)
onTrimMemory
in interface android.content.ComponentCallbacks2
public void onLowMemory()
onLowMemory
in interface android.content.ComponentCallbacks
public void onConfigurationChanged(android.content.res.Configuration newConfig)
onConfigurationChanged
in interface android.content.ComponentCallbacks