Class RequestManager

    • Field Detail

      • glide

        protected final Glide glide
      • context

        protected final android.content.Context context
    • Constructor Detail

      • RequestManager

        public RequestManager​(@NonNull
                              Glide glide,
                              @NonNull
                              Lifecycle lifecycle,
                              @NonNull
                              RequestManagerTreeNode treeNode,
                              @NonNull
                              android.content.Context context)
    • Method Detail

      • setRequestOptions

        protected void setRequestOptions​(@NonNull
                                         RequestOptions toSet)
      • setPauseAllRequestsOnTrimMemoryModerate

        public void setPauseAllRequestsOnTrimMemoryModerate​(boolean pauseAllOnTrim)
        If true then clear all in-progress and completed requests when the platform sends onTrimMemory with level = TRIM_MEMORY_MODERATE.
      • pauseRequests

        public 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 the manager is paused to complete. RequestManagers attached to Fragments and Activities automatically resume onStart().

        See Also:
        isPaused(), resumeRequests()
      • pauseAllRequests

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

        See Also:
        isPaused(), resumeRequests()
      • pauseAllRequestsRecursive

        public void pauseAllRequestsRecursive()
        Performs pauseAllRequests() recursively for all managers that are contextually descendant to this manager based on the Activity/Fragment hierarchy.

        Similar to pauseRequestsRecursive() with the exception that it also clears resources of completed loads.

      • pauseRequestsRecursive

        public 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.
        • 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 current RequestManager is paused.

        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.

      • resumeRequests

        public void resumeRequests()
        Restarts any loads that have not yet completed.
        See Also:
        isPaused(), pauseRequests()
      • resumeRequestsRecursive

        public void resumeRequestsRecursive()
        Performs 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().
      • 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
      • asBitmap

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.Bitmap> asBitmap()
        Attempts to always load the resource as a Bitmap, even if it could actually be animated.
        Returns:
        A new request builder for loading a Bitmap
      • asGif

        @NonNull
        @CheckResult
        public RequestBuilder<GifDrawable> asGif()
        Attempts to always load the resource as a 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.

        Returns:
        A new request builder for loading a GifDrawable.
      • asDrawable

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> asDrawable()
        Attempts to always load the resource using any registered ResourceDecoders 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.

        Returns:
        A new request builder for loading a Drawable.
      • load

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@Nullable
                                                                       android.graphics.Bitmap bitmap)
        Equivalent to calling asDrawable() and then RequestBuilder.load(Bitmap).
        Returns:
        A new request builder for loading a Drawable using the given model.
      • load

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@Nullable
                                                                       android.graphics.drawable.Drawable drawable)
        Equivalent to calling asDrawable() and then RequestBuilder.load(Drawable).
        Returns:
        A new request builder for loading a Drawable using the given model.
      • load

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@Nullable
                                                                       java.lang.String string)
        Equivalent to calling asDrawable() and then RequestBuilder.load(String).
        Returns:
        A new request builder for loading a Drawable using the given model.
      • load

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@Nullable
                                                                       android.net.Uri uri)
        Equivalent to calling asDrawable() and then RequestBuilder.load(Uri).
        Returns:
        A new request builder for loading a Drawable using the given model.
      • load

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@Nullable
                                                                       java.io.File file)
        Equivalent to calling asDrawable() and then RequestBuilder.load(File).
        Returns:
        A new request builder for loading a Drawable using the given model.
      • load

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@RawRes @DrawableRes @Nullable
                                                                       java.lang.Integer resourceId)
        Equivalent to calling asDrawable() and then RequestBuilder.load(Integer).
        Returns:
        A new request builder for loading a Drawable using the given model.
      • load

        @CheckResult
        @Deprecated
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@Nullable
                                                                       java.net.URL url)
        Deprecated.
        Equivalent to calling asDrawable() and then RequestBuilder.load(URL).
        Returns:
        A new request builder for loading a Drawable using the given model.
      • load

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@Nullable
                                                                       byte[] model)
        Equivalent to calling asDrawable() and then RequestBuilder.load(byte[]).
        Returns:
        A new request builder for loading a Drawable using the given model.
      • load

        @NonNull
        @CheckResult
        public RequestBuilder<android.graphics.drawable.Drawable> load​(@Nullable
                                                                       java.lang.Object model)
        A helper method equivalent to calling asDrawable() and then RequestBuilder.load(Object) with the given model.
        Returns:
        A new request builder for loading a Drawable using the given model.
      • downloadOnly

        @NonNull
        @CheckResult
        public RequestBuilder<java.io.File> downloadOnly()
        Attempts always load the resource into the cache and return the 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.

        Returns:
        A new request builder for downloading content to cache and returning the cache File.
      • download

        @NonNull
        @CheckResult
        public RequestBuilder<java.io.File> download​(@Nullable
                                                     java.lang.Object model)
        A helper method equivalent to calling downloadOnly() ()} and then RequestBuilder.load(Object) with the given model.
        Returns:
        A new request builder for loading a Drawable using the given model.
      • asFile

        @NonNull
        @CheckResult
        public RequestBuilder<java.io.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).

        For remote content, prefer downloadOnly().

        Returns:
        A new request builder for obtaining File paths to content.
      • as

        @NonNull
        @CheckResult
        public <ResourceType> RequestBuilder<ResourceType> as​(@NonNull
                                                              java.lang.Class<ResourceType> resourceClass)
        Attempts to load the resource using any registered ResourceDecoders that can decode the given resource class or any subclass of the given resource class.
        Parameters:
        resourceClass - The resource to decode.
        Returns:
        A new request builder for loading the given resource class.
      • clear

        public void clear​(@NonNull
                          android.view.View view)
        Cancel any pending loads Glide may have for the view and free any resources that may have been loaded for the view.

        Note that this will only work if View.setTag(Object) is not called on this view outside of Glide.

        Parameters:
        view - The view to cancel loads and free resources for.
        Throws:
        java.lang.IllegalArgumentException - if an object other than Glide's metadata is put as the view's tag.
        See Also:
        clear(Target)
      • clear

        public void clear​(@Nullable
                          Target<?> target)
        Cancel any pending loads Glide may have for the target and free any resources (such as Bitmaps) that may have been loaded for the target so they may be reused.
        Parameters:
        target - The Target to cancel loads for.
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • onTrimMemory

        public void onTrimMemory​(int level)
        Specified by:
        onTrimMemory in interface android.content.ComponentCallbacks2
      • onLowMemory

        public void onLowMemory()
        Specified by:
        onLowMemory in interface android.content.ComponentCallbacks
      • onConfigurationChanged

        public void onConfigurationChanged​(android.content.res.Configuration newConfig)
        Specified by:
        onConfigurationChanged in interface android.content.ComponentCallbacks