public class RequestManager extends Object implements LifecycleListener
Modifier and Type | Field and Description |
---|---|
protected Context |
context |
protected Glide |
glide |
Constructor and Description |
---|
RequestManager(Glide glide,
Lifecycle lifecycle,
RequestManagerTreeNode treeNode,
Context context) |
Modifier and Type | Method and Description |
---|---|
RequestManager |
applyDefaultRequestOptions(RequestOptions requestOptions)
Updates the default
RequestOptions for all loads started with this request manager
with the given RequestOptions . |
<ResourceType> |
as(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<Bitmap> |
asBitmap()
Attempts to always load the resource as a
Bitmap , even if it could
actually be animated. |
RequestBuilder<Drawable> |
asDrawable()
Attempts to always load the resource using any registered
ResourceDecoder s that can decode any subclass of Drawable . |
RequestBuilder<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(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<File> |
download(Object model)
A helper method equivalent to calling
downloadOnly() ()} and then RequestBuilder.load(Object) with the given model. |
RequestBuilder<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<Drawable> |
load(Bitmap bitmap)
Equivalent to calling
asDrawable() and then RequestBuilder.load(Bitmap) . |
RequestBuilder<Drawable> |
load(byte[] model)
Equivalent to calling
asDrawable() and then RequestBuilder.load(byte[]) . |
RequestBuilder<Drawable> |
load(Drawable drawable)
Equivalent to calling
asDrawable() and then RequestBuilder.load(Drawable) . |
RequestBuilder<Drawable> |
load(File file)
Equivalent to calling
asDrawable() and then RequestBuilder.load(File) . |
RequestBuilder<Drawable> |
load(Integer resourceId)
Equivalent to calling
asDrawable() and then RequestBuilder.load(Integer) . |
RequestBuilder<Drawable> |
load(Object model)
A helper method equivalent to calling
asDrawable() and then RequestBuilder.load(Object) with the given model. |
RequestBuilder<Drawable> |
load(String string)
Equivalent to calling
asDrawable() and then RequestBuilder.load(String) . |
RequestBuilder<Drawable> |
load(Uri uri)
Equivalent to calling
asDrawable() and then RequestBuilder.load(Uri) . |
RequestBuilder<Drawable> |
load(URL url)
Deprecated.
|
void |
onDestroy()
Lifecycle callback that cancels all in progress requests and clears and recycles resources for
all completed requests.
|
void |
onLowMemory()
Deprecated.
This method is called automatically by Glide's internals and shouldn't be called
externally.
|
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)
Deprecated.
This method is called automatically by Glide's internals and shouldn't be called
externally.
|
void |
pauseAllRequests()
Cancels any in progress loads and clears resources of completed loads.
|
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 . |
protected void |
setRequestOptions(RequestOptions toSet) |
String |
toString() |
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(RequestOptions)
@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)
@Deprecated public void onTrimMemory(int level)
ComponentCallbacks2.onTrimMemory(int)
@Deprecated public void onLowMemory()
ComponentCallbacks.onLowMemory()
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 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<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<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<Drawable> load(@Nullable Bitmap bitmap)
asDrawable()
and then RequestBuilder.load(Bitmap)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<Drawable> load(@Nullable Drawable drawable)
asDrawable()
and then RequestBuilder.load(Drawable)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<Drawable> load(@Nullable String string)
asDrawable()
and then RequestBuilder.load(String)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<Drawable> load(@Nullable Uri uri)
asDrawable()
and then RequestBuilder.load(Uri)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<Drawable> load(@Nullable File file)
asDrawable()
and then RequestBuilder.load(File)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<Drawable> load(@Nullable Integer resourceId)
asDrawable()
and then RequestBuilder.load(Integer)
.Drawable
using the given model.@CheckResult @Deprecated public RequestBuilder<Drawable> load(@Nullable URL url)
asDrawable()
and then RequestBuilder.load(URL)
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<Drawable> load(@Nullable byte[] model)
asDrawable()
and then RequestBuilder.load(byte[])
.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<Drawable> load(@Nullable Object model)
asDrawable()
and then RequestBuilder.load(Object)
with the given model.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<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<File> download(@Nullable Object model)
downloadOnly()
()} and then RequestBuilder.load(Object)
with the given model.Drawable
using the given model.@NonNull @CheckResult public RequestBuilder<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 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 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.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.