public class RequestManager extends Object implements LifecycleListener
Modifier and Type | Class and Description |
---|---|
static interface |
RequestManager.DefaultOptions
An interface that allows a default set of options to be applied to all requests started from an
RequestManager . |
class |
RequestManager.GenericModelRequest<A,T>
A helper class for building requests with custom
ModelLoader s that requires the user to provide a
specific model. |
class |
RequestManager.ImageModelRequest<T>
A helper class for building requests with custom
ModelLoader s that translate models to
InputStream resources for loading images. |
class |
RequestManager.VideoModelRequest<T>
A helper class for building requests with custom
ModelLoader s that translate models to
ParcelFileDescriptor resources for loading video thumbnails. |
Constructor and Description |
---|
RequestManager(Context context,
Lifecycle lifecycle,
RequestManagerTreeNode treeNode) |
Modifier and Type | Method and Description |
---|---|
<T> DrawableTypeRequest<T> |
from(Class<T> modelClass)
Returns a request builder that can be used for multiple loads that uses the
ModelLoaderFactory s registered for the given model class for
InputStream s and ParcelFileDescriptor s to load a thumbnail from objects of
the given modelClass. |
DrawableTypeRequest<byte[]> |
fromBytes()
Returns a request builder that uses
StreamByteArrayLoader to load
images from byte arrays. |
DrawableTypeRequest<File> |
fromFile()
Returns a request builder that uses the
ModelLoaderFactory currently
registered for File to load the image represented by the given File . |
DrawableTypeRequest<Uri> |
fromMediaStore()
Returns a request builder that uses
MediaStore.Images.Thumbnails and
MediaStore.Video.Thumbnails to retrieve pre-generated thumbnails for
Uri s. |
DrawableTypeRequest<Integer> |
fromResource()
Returns a request builder that uses the
ModelLoaderFactory currently
registered for Integer to load the image represented by the given Integer resource id. |
DrawableTypeRequest<String> |
fromString()
Returns a request builder that loads data from
String s using an empty signature. |
DrawableTypeRequest<Uri> |
fromUri()
Returns a request builder to load data from
Uri s using no signature. |
DrawableTypeRequest<URL> |
fromUrl()
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) . |
boolean |
isPaused()
Returns true if loads for this
RequestManager are currently paused. |
DrawableTypeRequest<byte[]> |
load(byte[] model)
Returns a request to load the given byte array.
|
DrawableTypeRequest<byte[]> |
load(byte[] model,
String id)
Deprecated.
Use
load(byte[]) along with
GenericRequestBuilder.signature(com.bumptech.glide.load.Key) instead. Scheduled to be
removed in Glide 4.0. |
DrawableTypeRequest<File> |
load(File file)
Returns a request builder to load the given
File . |
DrawableTypeRequest<Integer> |
load(Integer resourceId)
Returns a request builder to load the given resource id.
|
DrawableTypeRequest<String> |
load(String string)
Returns a request builder to load the given
String . |
<T> DrawableTypeRequest<T> |
load(T model)
Returns a request builder that uses the
ModelLoaderFactory s currently
registered for the given model class for InputStream s and ParcelFileDescriptor s to load a
thumbnail from either the image or the video represented by the given model. |
DrawableTypeRequest<Uri> |
load(Uri uri)
Returns a request builder to load the given
Uri . |
DrawableTypeRequest<URL> |
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) . |
DrawableTypeRequest<Uri> |
loadFromMediaStore(Uri uri)
Returns a request builder to load the given media store
Uri . |
DrawableTypeRequest<Uri> |
loadFromMediaStore(Uri uri,
String mimeType,
long dateModified,
int orientation)
Deprecated.
Use
loadFromMediaStore(android.net.Uri) ,
MediaStoreSignature , and
DrawableRequestBuilder.signature(com.bumptech.glide.load.Key) instead. Scheduled to be
removed in Glide 4.0. |
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. |
void |
setDefaultOptions(RequestManager.DefaultOptions options)
Sets an interface that can apply some default options to all Requests started using this
RequestManager . |
<T> RequestManager.VideoModelRequest<T> |
using(FileDescriptorModelLoader<T> modelLoader)
Returns a new request builder that uses the given
ModelLoader to fetch a
ParcelFileDescriptor for loading video thumbnails. |
<A,T> RequestManager.GenericModelRequest<A,T> |
using(ModelLoader<A,T> modelLoader,
Class<T> dataClass)
Returns a request builder that uses the given
ModelLoader to fetch a
generic data type. |
RequestManager.ImageModelRequest<byte[]> |
using(StreamByteArrayLoader modelLoader)
Returns a request builder that uses the given
StreamByteArrayLoader to fetch an InputStream for
loading Bitmaps. |
<T> RequestManager.ImageModelRequest<T> |
using(StreamModelLoader<T> modelLoader)
Returns a request builder that uses the given
StreamModelLoader to
fetch an InputStream for loading images. |
public RequestManager(Context context, Lifecycle lifecycle, RequestManagerTreeNode treeNode)
public void onTrimMemory(int level)
public void onLowMemory()
ComponentCallbacks.onLowMemory()
public void setDefaultOptions(RequestManager.DefaultOptions options)
RequestManager
.
Note - These options will be retained for the life the of this RequestManager
so be wary of using
GenericRequestBuilder.listener(com.bumptech.glide.request.RequestListener)
} when
starting requests using an Context
or Application
to avoid
leaking memory. Any option that does not use an anonymous inner class is generally safe.
options
- The default options to apply to all requests.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 <A,T> RequestManager.GenericModelRequest<A,T> using(ModelLoader<A,T> modelLoader, Class<T> dataClass)
ModelLoader
to fetch a
generic data type.
Warning - This is an experimental api that may change without a change in major version.
A
- The type of the model to be loaded.T
- The type of the data to be loaded from the mode.modelLoader
- The ModelLoader
class to use to load the model.dataClass
- The type of data the ModelLoader
will load.public <T> RequestManager.ImageModelRequest<T> using(StreamModelLoader<T> modelLoader)
StreamModelLoader
to
fetch an InputStream
for loading images.T
- The type of the model.modelLoader
- The model loader to use.public RequestManager.ImageModelRequest<byte[]> using(StreamByteArrayLoader modelLoader)
StreamByteArrayLoader
to fetch an InputStream
for
loading Bitmaps.modelLoader
- The byte array loader.public <T> RequestManager.VideoModelRequest<T> using(FileDescriptorModelLoader<T> modelLoader)
ModelLoader
to fetch a
ParcelFileDescriptor
for loading video thumbnails.T
- The type of the model.modelLoader
- The model loader to use.public DrawableTypeRequest<String> load(String string)
String
.
signature.string
- A file path, or a uri or url handled by UriLoader
.fromString()
,
load(Object)
public DrawableTypeRequest<String> fromString()
String
s using an empty signature.
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
GenericRequestBuilder.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
DrawableRequestBuilder.skipMemoryCache(boolean)
may be appropriate.
from(Class)
,
load(String)
public DrawableTypeRequest<Uri> load(Uri uri)
Uri
.uri
- The Uri representing the image. Must be of a type handled by
UriLoader
.fromUri()
,
load(Object)
public DrawableTypeRequest<Uri> fromUri()
Uri
s using no signature.
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
GenericRequestBuilder.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
DrawableRequestBuilder.skipMemoryCache(boolean)
may be appropriate.
@Deprecated public DrawableTypeRequest<Uri> loadFromMediaStore(Uri uri, String mimeType, long dateModified, int orientation)
loadFromMediaStore(android.net.Uri)
,
MediaStoreSignature
, and
DrawableRequestBuilder.signature(com.bumptech.glide.load.Key)
instead. Scheduled to be
removed in Glide 4.0.MediaStore.Images.Thumbnails
and
MediaStore.Video.Thumbnails
to retrieve pre-generated thumbnails for the given uri if
available and uses the given additional data to build a unique signature for cache invalidation.uri
- The uri representing the media.mimeType
- The mime type of the media store media. Ok to default to empty string "". See
MediaStore.MediaColumns.MIME_TYPE
or
MediaStore.MediaColumns.MIME_TYPE
.dateModified
- The date modified time of the media store media. Ok to default to 0. See
MediaStore.MediaColumns.DATE_MODIFIED
or
MediaStore.MediaColumns.DATE_MODIFIED
.orientation
- The orientation of the media store media. Ok to default to 0. See
MediaStore.Images.ImageColumns.ORIENTATION
.loadFromMediaStore(android.net.Uri)
,
load(android.net.Uri)
,
GenericRequestBuilder.signature(com.bumptech.glide.load.Key)
,
MediaStoreSignature
public DrawableTypeRequest<Uri> loadFromMediaStore(Uri uri)
Uri
.uri
- The uri representing the media.fromMediaStore()
,
load(Object)
public DrawableTypeRequest<Uri> fromMediaStore()
MediaStore.Images.Thumbnails
and
MediaStore.Video.Thumbnails
to retrieve pre-generated thumbnails for
Uri
s.
Falls back to the registered ModelLoaderFactory
registered for
Uri
s if the given uri is not a media store uri or if no pre-generated thumbnail exists for the given
uri.
Note - This method by default caches data using the given Uri as the key. Since content in the media store
can change at any time, you should use
GenericRequestBuilder.signature(com.bumptech.glide.load.Key)
to mix in some
additional data identifying the current state of the Uri, preferably using
MediaStoreSignature
. Alternatively consider avoiding the memory and
disk caches entirely using
GenericRequestBuilder.diskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy)
and DiskCacheStrategy.NONE
and/or
GenericRequestBuilder.skipMemoryCache(boolean)
.
public DrawableTypeRequest<File> load(File file)
File
.file
- The File containing the imagefromFile()
,
load(Object)
public DrawableTypeRequest<File> fromFile()
ModelLoaderFactory
currently
registered for File
to load the image represented by the given File
. Defaults to
StreamFileLoader.Factory
and
StreamFileLoader
to load images from File
s.
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
GenericRequestBuilder.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
DrawableRequestBuilder.skipMemoryCache(boolean)
may be appropriate.
load(java.io.File)
,
from(Class)
public DrawableTypeRequest<Integer> load(Integer resourceId)
resourceId
- the id of the resource containing the imagefromResource()
,
load(Object)
public DrawableTypeRequest<Integer> fromResource()
ModelLoaderFactory
currently
registered for Integer
to load the image represented by the given Integer
resource id. Defaults
to StreamResourceLoader.Factory
and
StreamResourceLoader
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 GenericRequestBuilder.diskCacheStrategy(com.bumptech.glide.load.engine.DiskCacheStrategy)
during development, and re-enabling the default
DiskCacheStrategy.RESULT
for release builds.
@Deprecated public DrawableTypeRequest<URL> load(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.fromUrl()
,
load(Object)
@Deprecated public DrawableTypeRequest<URL> fromUrl()
URL
class has
a number of performance problems and should generally be avoided when
possible. Prefer load(android.net.Uri)
or load(String)
.ModelLoaderFactory
currently
registered for URL
to load the image represented by the given URL
. Defaults to
HttpUrlGlideUrlLoader
and
HttpUrlFetcher
to load URL
models.from(Class)
,
load(java.net.URL)
@Deprecated public DrawableTypeRequest<byte[]> load(byte[] model, String id)
load(byte[])
along with
GenericRequestBuilder.signature(com.bumptech.glide.load.Key)
instead. Scheduled to be
removed in Glide 4.0.StreamByteArrayLoader
to load an image from the given byte array.
Note - by default loads for bytes are not cached in either the memory or the disk cache.
model
- The data to load.id
- A unique id that identifies the image represented by the model suitable for use as a cache key
(url, filepath etc). If there is no suitable id, use load(byte[])
instead.load(byte[])
public DrawableTypeRequest<byte[]> load(byte[] model)
model
- the data to load.fromBytes()
,
load(Object)
public DrawableTypeRequest<byte[]> fromBytes()
StreamByteArrayLoader
to load
images from byte arrays.
Note - by default loads for bytes are not cached in either the memory or the disk cache.
from(Class)
,
load(byte[])
public <T> DrawableTypeRequest<T> load(T model)
ModelLoaderFactory
s currently
registered for the given model class for InputStream
s and ParcelFileDescriptor
s to load a
thumbnail from either the image or the video represented by the given model.
Note - for maximum efficiency, consider using from(Class)
} to avoid repeatedly allocating builder
objects.
T
- The type of the model to load.model
- The model the load.from(Class)
public <T> DrawableTypeRequest<T> from(Class<T> modelClass)
ModelLoaderFactory
s registered for the given model class for
InputStream
s and ParcelFileDescriptor
s to load a thumbnail from objects of
the given modelClass.
Note - you must use DrawableRequestBuilder.load(Object)
} to set a concrete model
to be loaded before calling
GenericRequestBuilder.into(com.bumptech.glide.request.target.Target)
. You may
also use this object for repeated loads by calling request.load(model).into(target)
. You may
also adjust the options after calling DrawableRequestBuilder.load(Object)
} and/or
GenericRequestBuilder.into(com.bumptech.glide.request.target.Target)
}. However,
keep in mind that any changes in options will apply to all future loads.
T
- The type of the model.modelClass
- The class of model requests built by this class will load data from.