-
- All Implemented Interfaces:
-
android.content.ComponentCallbacks,android.content.ComponentCallbacks2,com.mobwith.imgmodule.ModelTypes,com.mobwith.imgmodule.manager.LifecycleListener
public class RequestManager implements ComponentCallbacks2, LifecycleListener, ModelTypes<RequestBuilder<Drawable>>
A class for managing and starting requests for ImageModule. 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 ImageModule.load methods with your Fragment or Activity.
-
-
Field Summary
Fields Modifier and Type Field Description private booleanpauseAllRequestsOnTrimMemoryModerate
-
Constructor Summary
Constructors Constructor Description RequestManager(ImageModule imageModule, Lifecycle lifecycle, RequestManagerTreeNode treeNode, Context context)
-
Method Summary
Modifier and Type Method Description voidsetPauseAllRequestsOnTrimMemoryModerate(boolean pauseAllOnTrim)If {@code true}then clear all in-progress and completed requests when the platform sends{@code onTrimMemory}with level ={@code TRIM_MEMORY_MODERATE}.synchronized RequestManagerapplyDefaultRequestOptions(@NonNull() RequestOptions requestOptions)Updates the default RequestOptions for all loads started with this request manager withthe given RequestOptions. synchronized RequestManagersetDefaultRequestOptions(@NonNull() RequestOptions requestOptions)Replaces the default RequestOptions for all loads started with this request managerwith the given RequestOptions. RequestManageraddDefaultRequestListener(RequestListener<Object> requestListener)Adds a default RequestListener that will be added to every request started with this RequestManager. synchronized booleanisPaused()Returns true if loads for this RequestManager are currently paused. synchronized voidpauseRequests()Cancels any in progress loads, but does not clear resources of completed loads. synchronized voidpauseAllRequests()Cancels any in progress loads and clears resources of completed loads. synchronized voidpauseAllRequestsRecursive()Performs pauseAllRequests recursively for all managers that are contextuallydescendant to this manager based on the Activity/Fragment hierarchy. synchronized voidpauseRequestsRecursive()Performs pauseRequests recursively for all managers that are contextually descendantto this manager based on the Activity/Fragment hierarchy: - When pausing on an Activity all attached fragments will also get paused.
- When pausing on an attached Fragment all descendant fragments will also get paused.
- When pausing on a detached Fragment or the application context only the currentRequestManager is paused.
synchronized voidresumeRequests()Restarts any loads that have not yet completed. synchronized voidresumeRequestsRecursive()Performs resumeRequests recursively for all managers that are contextuallydescendant to this manager based on the Activity/Fragment hierarchy. synchronized voidonStart()Lifecycle callback that registers for connectivity events (if theandroid.permission.ACCESS_NETWORK_STATE permission is present) and restarts failed or pausedrequests. synchronized voidonStop()Lifecycle callback that unregisters for connectivity events (if theandroid.permission.ACCESS_NETWORK_STATE permission is present) and pauses in progress loads. synchronized voidonDestroy()Lifecycle callback that cancels all in progress requests and clears and recycles resources forall completed requests. RequestBuilder<Bitmap>asBitmap()Attempts to always load the resource as a Bitmap, even if it couldactually be animated. RequestBuilder<GifDrawable>asGif()Attempts to always load the resource as a . RequestBuilder<Drawable>asDrawable()Attempts to always load the resource using any registered s that can decode any subclass of Drawable. RequestBuilder<Drawable>load(@Nullable() Bitmap bitmap)Equivalent to calling asDrawable and then load. RequestBuilder<Drawable>load(@Nullable() Drawable drawable)Equivalent to calling asDrawable and then load. RequestBuilder<Drawable>load(@Nullable() String string)Equivalent to calling asDrawable and then load. RequestBuilder<Drawable>load(@Nullable() Uri uri)Equivalent to calling asDrawable and then load. RequestBuilder<Drawable>load(@Nullable() File file)Equivalent to calling asDrawable and then load. RequestBuilder<Drawable>load(@RawRes() @DrawableRes() @Nullable() Integer resourceId)Equivalent to calling asDrawable and then load. RequestBuilder<Drawable>load(@Nullable() URL url)Equivalent to calling asDrawable and then load. RequestBuilder<Drawable>load(@Nullable() Array<byte> model)Equivalent to calling asDrawable and then load. RequestBuilder<Drawable>load(@Nullable() Object model)A helper method equivalent to calling asDrawable and then with the given model. RequestBuilder<File>downloadOnly()Attempts always load the resource into the cache and return the File containing thecached source data. RequestBuilder<File>download(@Nullable() Object model)A helper method equivalent to calling downloadOnly ()} and then with the given model. RequestBuilder<File>asFile()Attempts to always load a File containing the resource, either using a file pathobtained from the media store (for local images/videos), or using ImageModule disk cache (forremote images/videos). <ResourceType> RequestBuilder<ResourceType>as(@NonNull() Class<ResourceType> resourceClass)Attempts to load the resource using any registered s that can decode the given resource class or anysubclass of the given resource class. voidclear(@NonNull() View view)Cancel any pending loads ImageModule may have for the view and free any resources that may have beenloaded for the view. voidclear(@Nullable() Target<out Object> target)Cancel any pending loads ImageModule may have for the target and free any resources (such as s) that may have been loaded for the target so they may be reused. synchronized StringtoString()voidonTrimMemory(int level)voidonLowMemory()voidonConfigurationChanged(Configuration newConfig)-
Methods inherited from class android.content.ComponentCallbacks2
onTrimMemory -
Methods inherited from class android.content.ComponentCallbacks
onConfigurationChanged, onLowMemory -
Methods inherited from class com.mobwith.imgmodule.ModelTypes
load, load, load, load, load, load, load, load, load -
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
-
Constructor Detail
-
RequestManager
RequestManager(ImageModule imageModule, Lifecycle lifecycle, RequestManagerTreeNode treeNode, Context context)
-
-
Method Detail
-
setPauseAllRequestsOnTrimMemoryModerate
void setPauseAllRequestsOnTrimMemoryModerate(boolean pauseAllOnTrim)
If
{@code true}then clear all in-progress and completed requests when the platform sends{@code onTrimMemory}with level ={@code TRIM_MEMORY_MODERATE}.
-
applyDefaultRequestOptions
@NonNull() synchronized RequestManager applyDefaultRequestOptions(@NonNull() RequestOptions requestOptions)
Updates the default RequestOptions for all loads started with this request manager withthe given RequestOptions.
The RequestOptions provided here are applied on top of those provided via . If there are conflicts, the optionsapplied here will win. Note that this method does not mutate options provided to .
Multiple sets of options can be applied. If there are conflicts the last applied will win.
The modified options will only be applied to loads started after this method is called.
-
setDefaultRequestOptions
@NonNull() synchronized RequestManager setDefaultRequestOptions(@NonNull() RequestOptions requestOptions)
Replaces the default RequestOptions for all loads started with this request managerwith the given RequestOptions.
The RequestOptions provided here replace those that have been previously providedvia this method, setDefaultRequestOptions, and .
Subsequent calls to applyDefaultRequestOptions will not mutate the RequestOptions provided here. Instead the manager will create a clone of these optionsand mutate the clone.
-
addDefaultRequestListener
RequestManager addDefaultRequestListener(RequestListener<Object> requestListener)
Adds a default RequestListener that will be added to every request started with this RequestManager.
Multiple RequestListeners can be added here, in RequestManager scopes or toindividual RequestBuilders. RequestListeners are called in the order they'readded. Even if an earlier RequestListener returns
{@code true}from or , it will notprevent subsequent RequestListeners from being called.Because ImageModule requests can be started for any number of individual resource types, anylistener added here has to accept any generic resource type in . If you must basethe behavior of the listener on the resource type, you will need to use
{@code instanceof}todo so. It's not safe to cast resource types without first checking with{@code instanceof}.
-
isPaused
synchronized boolean isPaused()
Returns true if loads for this RequestManager are currently paused.
-
pauseRequests
synchronized void pauseRequests()
Cancels any in progress loads, but does not clear resources of completed loads.
Note #resumeRequests must be called for any requests made before or while themanager is paused to complete. RequestManagers attached to Fragments and Activitiesautomatically resume onStart().
-
pauseAllRequests
synchronized void pauseAllRequests()
Cancels any in progress loads and clears resources of completed loads.
Note #resumeRequests must be called for any requests made before or while themanager is paused to complete. RequestManagers attached to Fragments and Activitiesautomatically resume onStart().
This will release the memory used by completed bitmaps but leaves them in any configuredcaches. When an #android.app.Activity receives # at a level of # this is desirable in order to keepyour process alive longer.
-
pauseAllRequestsRecursive
synchronized void pauseAllRequestsRecursive()
Performs pauseAllRequests recursively for all managers that are contextuallydescendant to this manager based on the Activity/Fragment hierarchy.
Similar to pauseRequestsRecursive with the exception that it also clearsresources of completed loads.
-
pauseRequestsRecursive
synchronized void pauseRequestsRecursive()
Performs pauseRequests recursively for all managers that are contextually descendantto this manager based on the Activity/Fragment hierarchy:
- When pausing on an Activity all attached fragments will also get paused.
- When pausing on an attached Fragment all descendant fragments will also get paused.
- When pausing on a detached Fragment or the application context only the currentRequestManager is paused.
Note, on pre-Jelly Bean MR1 calling pause on a Fragment will not cause child fragments topause, in this case either call pause on the Activity or use a support Fragment.
-
resumeRequests
synchronized void resumeRequests()
Restarts any loads that have not yet completed.
-
resumeRequestsRecursive
synchronized void resumeRequestsRecursive()
Performs resumeRequests recursively for all managers that are contextuallydescendant to this manager based on the Activity/Fragment hierarchy. The hierarchical semanticsare identical as for pauseRequestsRecursive.
-
onStart
synchronized void onStart()
Lifecycle callback that registers for connectivity events (if theandroid.permission.ACCESS_NETWORK_STATE permission is present) and restarts failed or pausedrequests.
-
onStop
synchronized void onStop()
Lifecycle callback that unregisters for connectivity events (if theandroid.permission.ACCESS_NETWORK_STATE permission is present) and pauses in progress loads.
-
onDestroy
synchronized void onDestroy()
Lifecycle callback that cancels all in progress requests and clears and recycles resources forall completed requests.
-
asBitmap
@NonNull()@CheckResult() RequestBuilder<Bitmap> asBitmap()
Attempts to always load the resource as a Bitmap, even if it couldactually be animated.
-
asGif
@NonNull()@CheckResult() RequestBuilder<GifDrawable> asGif()
Attempts to always load the resource as a .
If the underlying data is not a GIF, this will fail. As a result, this should only be usedif the model represents an animated GIF and the caller wants to interact with the GifDrawabledirectly. Normally using just asDrawable is sufficient because it will determinewhether or not the given data represents an animated GIF and return the appropriate , animated or not, automatically.
-
asDrawable
@NonNull()@CheckResult() RequestBuilder<Drawable> asDrawable()
Attempts to always load the resource using any registered s that can decode any subclass of Drawable.
By default, may return either a android.graphics.drawable.BitmapDrawable or , but if additional decoders are registered for other Drawable subclasses,any of those subclasses may also be returned.
-
load
@NonNull()@CheckResult() RequestBuilder<Drawable> load(@Nullable() Bitmap bitmap)
Equivalent to calling asDrawable and then load.
-
load
@NonNull()@CheckResult() RequestBuilder<Drawable> load(@Nullable() Drawable drawable)
Equivalent to calling asDrawable and then load.
-
load
@NonNull()@CheckResult() RequestBuilder<Drawable> load(@Nullable() String string)
Equivalent to calling asDrawable and then load.
-
load
@NonNull()@CheckResult() RequestBuilder<Drawable> load(@Nullable() Uri uri)
Equivalent to calling asDrawable and then load.
-
load
@NonNull()@CheckResult() RequestBuilder<Drawable> load(@Nullable() File file)
Equivalent to calling asDrawable and then load.
-
load
@NonNull()@CheckResult() RequestBuilder<Drawable> load(@RawRes() @DrawableRes() @Nullable() Integer resourceId)
Equivalent to calling asDrawable and then load.
-
load
@CheckResult()@Deprecated() RequestBuilder<Drawable> load(@Nullable() URL url)
Equivalent to calling asDrawable and then load.
-
load
@NonNull()@CheckResult() RequestBuilder<Drawable> load(@Nullable() Array<byte> model)
Equivalent to calling asDrawable and then load.
-
load
@NonNull()@CheckResult() RequestBuilder<Drawable> load(@Nullable() Object model)
A helper method equivalent to calling asDrawable and then with the given model.
-
downloadOnly
@NonNull()@CheckResult() RequestBuilder<File> downloadOnly()
Attempts always load the resource into the cache and return the File containing thecached source data.
This method is designed to work for remote data that is or will be cached using . As a result, specifying a on this request is generally not recommended.
-
download
@NonNull()@CheckResult() RequestBuilder<File> download(@Nullable() Object model)
A helper method equivalent to calling downloadOnly ()} and then with the given model.
-
asFile
@NonNull()@CheckResult() RequestBuilder<File> asFile()
Attempts to always load a File containing the resource, either using a file pathobtained from the media store (for local images/videos), or using ImageModule disk cache (forremote images/videos).
For remote content, prefer downloadOnly.
-
as
@NonNull()@CheckResult() <ResourceType> RequestBuilder<ResourceType> as(@NonNull() Class<ResourceType> resourceClass)
Attempts to load the resource using any registered s that can decode the given resource class or anysubclass of the given resource class.
- Parameters:
resourceClass- The resource to decode.
-
clear
void clear(@NonNull() View view)
Cancel any pending loads ImageModule may have for the view and free any resources that may have beenloaded for the view.
Note that this will only work if setTag is not called on this viewoutside of ImageModule.
- Parameters:
view- The view to cancel loads and free resources for.
-
clear
void clear(@Nullable() Target<out Object> target)
Cancel any pending loads ImageModule may have for the target and free any resources (such as s) that may have been loaded for the target so they may be reused.
- Parameters:
target- The Target to cancel loads for.
-
onTrimMemory
void onTrimMemory(int level)
-
onLowMemory
void onLowMemory()
-
onConfigurationChanged
void onConfigurationChanged(Configuration newConfig)
-
-
-