com.bumptech.glide
Class RequestManager

java.lang.Object
  extended by com.bumptech.glide.RequestManager
All Implemented Interfaces:
LifecycleListener

public class RequestManager
extends Object
implements LifecycleListener

A class for managing and starting requests for Glide. Can use activity, fragment and connectivity lifecycle events to intelligently stop, start, and restart requests. Retrieve either by instantiating a new object, or to take advantage built in Activity and Fragment lifecycle handling, use the static Glide.load methods with your Fragment or Activity.

See Also:
Glide.with(android.app.Activity), Glide.with(android.support.v4.app.FragmentActivity), Glide.with(android.app.Fragment), Glide.with(android.support.v4.app.Fragment), Glide.with(Context)

Nested Class Summary
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 ModelLoaders that requires the user to provide a specific model.
 class RequestManager.ImageModelRequest<T>
          A helper class for building requests with custom ModelLoaders that translate models to InputStream resources for loading images.
 class RequestManager.VideoModelRequest<T>
          A helper class for building requests with custom ModelLoaders that translate models to ParcelFileDescriptor resources for loading video thumbnails.
 
Constructor Summary
RequestManager(Context context, Lifecycle lifecycle)
           
 
Method Summary
 boolean isPaused()
          Returns true if loads for this RequestManager are currently paused.
 DrawableTypeRequest<byte[]> load(byte[] model)
          Use a new StreamByteArrayLoader to load an image from the given model.
 DrawableTypeRequest<byte[]> load(byte[] model, String id)
          Use a new StreamByteArrayLoader to load an image from the given model.
 DrawableTypeRequest<File> load(File file)
          Use the ModelLoaderFactory currently registered for File to load the image represented by the given File.
 DrawableTypeRequest<Integer> load(Integer resourceId)
          Use the ModelLoaderFactory currently registered for Integer to load the image represented by the given Integer resource id.
 DrawableTypeRequest<String> load(String string)
          Use the ModelLoaderFactory currently registered for String to load the image represented by the given String.
<T> DrawableTypeRequest<T>
load(T model)
          Use the ModelLoaderFactorys currently registered for the given model type for InputStreams and ParcelFileDescriptors to load a thumbnail from either the image or the video represented by the given model.
 DrawableTypeRequest<Uri> load(Uri uri)
          Use the ModelLoaderFactory currently registered for Uri to load the image at the given uri.
 DrawableTypeRequest<URL> load(URL url)
          Use the ModelLoaderFactory currently registered for URL to load the image represented by the given URL.
 DrawableTypeRequest<Uri> loadFromMediaStore(Uri uri, String mimeType, long dateModified, int orientation)
          Use MediaStore.Images.Thumbnails and MediaStore.Video.Thumbnails to retrieve pre-generated thumbnails for the given uri.
 void onDestroy()
          Lifecycle callback that cancels all in progress requests and clears and recycles resources for all completed requests.
 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 pauseRequests()
          Cancels any in progress loads, but does not clear resources of completed loads.
 void resumeRequests()
          Restarts any loads that have not yet completed.
 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)
          Set the ModelLoader to use for a new load where the model loader translates from a model to an ParcelFileDescriptor resource for loading video thumbnails.
<A,T> RequestManager.GenericModelRequest<A,T>
using(ModelLoader<A,T> modelLoader, Class<T> dataClass)
          Use the given generic model loader to load the given generic data class.
 RequestManager.ImageModelRequest<byte[]> using(StreamByteArrayLoader modelLoader)
          A convenience method to use a StreamByteArrayLoader to decode an image from a byte array.
<T> RequestManager.ImageModelRequest<T>
using(StreamModelLoader<T> modelLoader)
          Set the ModelLoader to use for for a new load where the model loader translates from a model to an InputStream resource for loading images.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RequestManager

public RequestManager(Context context,
                      Lifecycle lifecycle)
Method Detail

setDefaultOptions

public void setDefaultOptions(RequestManager.DefaultOptions options)
Sets an interface that can apply some default options to all Requests started using this 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.

Parameters:
options - The default options to apply to all requests.

isPaused

public boolean isPaused()
Returns true if loads for this RequestManager are currently paused.

See Also:
pauseRequests(), resumeRequests()

pauseRequests

public void pauseRequests()
Cancels any in progress loads, but does not clear resources of completed loads.

See Also:
isPaused(), resumeRequests()

resumeRequests

public void resumeRequests()
Restarts any loads that have not yet completed.

See Also:
isPaused(), pauseRequests()

onStart

public 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.

Specified by:
onStart in interface LifecycleListener

onStop

public void onStop()
Lifecycle callback that unregisters for connectivity events (if the android.permission.ACCESS_NETWORK_STATE permission is present) and pauses in progress loads.

Specified by:
onStop in interface LifecycleListener

onDestroy

public void onDestroy()
Lifecycle callback that cancels all in progress requests and clears and recycles resources for all completed requests.

Specified by:
onDestroy in interface LifecycleListener

using

public <A,T> RequestManager.GenericModelRequest<A,T> using(ModelLoader<A,T> modelLoader,
                                                           Class<T> dataClass)
Use the given generic model loader to load the given generic data class.

Warning - This is an experimental api that may change without a change in major version.

Type Parameters:
A - The type of the model to be loaded.
T - The type of the data to be loaded from the mode.
Parameters:
modelLoader - The ModelLoader class to use to load the model.
dataClass - The type of data the ModelLoader will load.
Returns:
A RequestManager.GenericModelRequest to set options for the load and ultimately the target to load the model into.

using

public <T> RequestManager.ImageModelRequest<T> using(StreamModelLoader<T> modelLoader)
Set the ModelLoader to use for for a new load where the model loader translates from a model to an InputStream resource for loading images.

Type Parameters:
T - The type of the model.
Parameters:
modelLoader - The model loader to use.
Returns:
A new RequestManager.ImageModelRequest.

using

public RequestManager.ImageModelRequest<byte[]> using(StreamByteArrayLoader modelLoader)
A convenience method to use a StreamByteArrayLoader to decode an image from a byte array.

Parameters:
modelLoader - The byte array loader.
Returns:
A new RequestManager.ImageModelRequest.

using

public <T> RequestManager.VideoModelRequest<T> using(FileDescriptorModelLoader<T> modelLoader)
Set the ModelLoader to use for a new load where the model loader translates from a model to an ParcelFileDescriptor resource for loading video thumbnails.

Type Parameters:
T - The type of the model.
Parameters:
modelLoader - The model loader to use.
Returns:
A new RequestManager.VideoModelRequest.

load

public DrawableTypeRequest<String> load(String string)
Use the ModelLoaderFactory currently registered for String to load the image represented by the given String. Defaults to StreamStringLoader.Factory and StreamStringLoader to load the given model.

Parameters:
string - The string representing the image. Must be either a path, or a uri handled by StreamUriLoader
Returns:
A DrawableTypeRequest to set options for the load and ultimately the target to load the model into.
See Also:
using(StreamModelLoader)

load

public DrawableTypeRequest<Uri> load(Uri uri)
Use the ModelLoaderFactory currently registered for Uri to load the image at the given uri. Defaults to StreamUriLoader.Factory and StreamUriLoader.

Parameters:
uri - The uri representing the image. Must be a uri handled by StreamUriLoader
Returns:
A DrawableTypeRequest to set options for the load and ultimately the target to load the model into.
See Also:
using(StreamModelLoader)

loadFromMediaStore

public DrawableTypeRequest<Uri> loadFromMediaStore(Uri uri,
                                                   String mimeType,
                                                   long dateModified,
                                                   int orientation)
Use MediaStore.Images.Thumbnails and MediaStore.Video.Thumbnails to retrieve pre-generated thumbnails for the given uri.

Falls back to the registered ModelLoaderFactory registered for Uris if the given uri is not a media store uri or if no pre-generated thumbnail exists for the given uri. In addition, mixes the given mimeType, dateModified, and orientation into the cache key to detect and invalidate thumbnails if content is changed locally.

Parameters:
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.
Returns:
A new DrawableRequestBuilder to set options for the load and ultimately the target to load the uri into.

load

public DrawableTypeRequest<File> load(File file)
Use the ModelLoaderFactory currently registered for File to load the image represented by the given File. Defaults to StreamFileLoader.Factory and StreamFileLoader to load the given model.

Parameters:
file - The File containing the image
Returns:
A DrawableTypeRequest to set options for the load and ultimately the target to load the model into.
See Also:
using(StreamModelLoader)

load

public DrawableTypeRequest<Integer> load(Integer resourceId)
Use the ModelLoaderFactory currently registered for Integer to load the image represented by the given Integer resource id. Defaults to StreamResourceLoader.Factory and StreamResourceLoader to load the given model.

Parameters:
resourceId - the id of the resource containing the image
Returns:
A DrawableTypeRequest to set options for the load and ultimately the target to load the model into.
See Also:
using(StreamModelLoader)

load

public DrawableTypeRequest<URL> load(URL url)
Use the ModelLoaderFactory currently registered for URL to load the image represented by the given URL. Defaults to HttpUrlGlideUrlLoader and HttpUrlFetcher to load the given model.

Parameters:
url - The URL representing the image.
Returns:
A DrawableTypeRequest to set options for the load and ultimately the target to load the model into.
See Also:
using(StreamModelLoader)

load

public DrawableTypeRequest<byte[]> load(byte[] model,
                                        String id)
Use a new StreamByteArrayLoader to load an image from the given model.

Parameters:
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[]) instaed.
Returns:
A DrawableTypeRequest to set options for the load and ultimately the target to load the image into.
See Also:
load(byte[])

load

public DrawableTypeRequest<byte[]> load(byte[] model)
Use a new StreamByteArrayLoader to load an image from the given model. Suitable when there is no simple id that represents the given data.

Parameters:
model - the data to load.
Returns:
A DrawableTypeRequest to set options for the load and ultimately the target to load the image into.

load

public <T> DrawableTypeRequest<T> load(T model)
Use the ModelLoaderFactorys currently registered for the given model type for InputStreams and ParcelFileDescriptors to load a thumbnail from either the image or the video represented by the given model.

Type Parameters:
T - The type of the model to load.
Parameters:
model - The model the load.
Returns:
A DrawableTypeRequest to set options for the load and ultimately the target to load the image into.