public class RequestManager extends Object implements LifecycleListener
Constructor and Description |
---|
RequestManager(Glide glide,
Lifecycle lifecycle,
RequestManagerTreeNode treeNode) |
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(Object model)
A helper method equivalent to calling
asDrawable() and then RequestBuilder.load(Object) with the given model. |
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 |
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 final Glide glide
public RequestManager(Glide glide, Lifecycle lifecycle, RequestManagerTreeNode treeNode)
protected void setRequestOptions(@NonNull RequestOptions toSet)
public RequestManager applyDefaultRequestOptions(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)
public RequestManager setDefaultRequestOptions(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 GlideBuilder.setDefaultRequestOptions(RequestOptions)
, 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 void onTrimMemory(int level)
ComponentCallbacks2.onTrimMemory(int)
public void onLowMemory()
ComponentCallbacks.onLowMemory()
public boolean isPaused()
RequestManager
are currently paused.pauseRequests()
,
resumeRequests()
public void pauseRequests()
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
public RequestBuilder<Bitmap> asBitmap()
Bitmap
, even if it could
actually be animated.Bitmap
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
.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
.public RequestBuilder<Drawable> load(@Nullable Object model)
asDrawable()
and then RequestBuilder.load(Object)
with the given model.Drawable
using the given model.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.
public RequestBuilder<File> download(@Nullable Object model)
downloadOnly()
()} and then RequestBuilder.load(Object)
with the given model.Drawable
using the given model.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()
.
public <ResourceType> RequestBuilder<ResourceType> as(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(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.