Class BaseRequestOptions<T extends BaseRequestOptions<T>>

java.lang.Object
com.bumptech.glide.request.BaseRequestOptions<T>
Type Parameters:
T - The particular child implementation
All Implemented Interfaces:
Cloneable
Direct Known Subclasses:
RequestBuilder, RequestOptions

public abstract class BaseRequestOptions<T extends BaseRequestOptions<T>> extends Object implements Cloneable
A base object to allow method sharing between RequestOptions and RequestBuilder.

This class is not meant for general use and may change at any time.

  • Constructor Details

    • BaseRequestOptions

      public BaseRequestOptions()
  • Method Details

    • sizeMultiplier

      @NonNull @CheckResult public T sizeMultiplier(@FloatRange(from=0.0,to=1.0) float sizeMultiplier)
      Applies a multiplier to the Target's size before loading the resource. Useful for loading thumbnails or trying to avoid loading huge resources (particularly Bitmaps on devices with overly dense screens.
      Parameters:
      sizeMultiplier - The multiplier to apply to the Target's dimensions when loading the resource.
      Returns:
      This request builder.
    • useUnlimitedSourceGeneratorsPool

      @NonNull @CheckResult public T useUnlimitedSourceGeneratorsPool(boolean flag)
      If set to true, uses a cached unlimited Executor to run the request.

      This method should ONLY be used when a Glide load is started recursively on one of Glide's threads as part of another request. Using this method in other scenarios can lead to excessive memory usage and OOMs and/or a significant decrease in performance across an application.

      If both this method and useAnimationPool(boolean) are set, this method will be preferred and useAnimationPool(boolean) will be ignored.

    • useAnimationPool

      @NonNull @CheckResult public T useAnimationPool(boolean flag)
      If set to true, uses a special Executor that is used exclusively for decoding frames of animated resources, like GIFs.

      The animation executor disallows network operations and must not be used for loads that may load remote data. The animation executor has fewer threads available to it than Glide's normal executors and is only useful as a way of avoiding blocking on longer and more expensive reads for critical requests like those in an animating GIF.

      If both useUnlimitedSourceGeneratorsPool(boolean) and this method are set, useUnlimitedSourceGeneratorsPool(boolean) will be preferred and this method will be ignored.

    • onlyRetrieveFromCache

      @NonNull @CheckResult public T onlyRetrieveFromCache(boolean flag)
      If set to true, will only load an item if found in the cache, and will not fetch from source.

      By 'cache' we mean both the in memory cache and both types of disk cache (DiskCacheStrategy.DATA and DiskCacheStrategy.RESOURCE). If this flag is set to true and the item is not in the memory cache, but it is in one of the disk caches, the load will complete asynchronously.

      If you'd like to only load an item from the memory cache. You can call this method with true and also call diskCacheStrategy(DiskCacheStrategy) with DiskCacheStrategy.NONE

    • diskCacheStrategy

      @NonNull @CheckResult public T diskCacheStrategy(@NonNull DiskCacheStrategy strategy)
      Sets the DiskCacheStrategy to use for this load.

      Defaults to DiskCacheStrategy.AUTOMATIC.

      For most applications DiskCacheStrategy.RESOURCE is ideal. Applications that use the same resource multiple times in multiple sizes and are willing to trade off some speed and disk space in return for lower bandwidth usage may want to consider using DiskCacheStrategy.DATA or DiskCacheStrategy.ALL.

      Parameters:
      strategy - The strategy to use.
      Returns:
      This request builder.
    • priority

      @NonNull @CheckResult public T priority(@NonNull Priority priority)
      Sets the priority for this load.
      Parameters:
      priority - A priority.
      Returns:
      This request builder.
    • placeholder

      @NonNull @CheckResult public T placeholder(@Nullable Drawable drawable)
      Sets an Drawable to display while a resource is loading.

      Replaces any previous calls to this method or placeholder(int).

      Parameters:
      drawable - The drawable to display as a placeholder.
      Returns:
      This request builder.
    • placeholder

      @NonNull @CheckResult public T placeholder(@DrawableRes int resourceId)
      Sets an Android resource id for a Drawable resource to display while a resource is loading.

      Replaces any previous calls to this method or placeholder(Drawable)

      Parameters:
      resourceId - The id of the resource to use as a placeholder
      Returns:
      This request builder.
    • fallback

      @NonNull @CheckResult public T fallback(@Nullable Drawable drawable)
      Sets an Drawable to display if the model provided to RequestBuilder.load(Object) is null.

      If a fallback is not set, null models will cause the error drawable to be displayed. If the error drawable is not set, the placeholder will be displayed.

      Replaces any previous calls to this method or fallback(int).

      Parameters:
      drawable - The drawable to display as a placeholder.
      Returns:
      This request builder.
      See Also:
    • fallback

      @NonNull @CheckResult public T fallback(@DrawableRes int resourceId)
      Sets a resource to display if the model provided to RequestBuilder.load(Object) is null.

      If a fallback is not set, null models will cause the error drawable to be displayed. If the error drawable is not set, the placeholder will be displayed.

      Replaces any previous calls to this method or fallback(Drawable).

      Parameters:
      resourceId - The id of the resource to use as a fallback.
      Returns:
      This request builder.
      See Also:
    • error

      @NonNull @CheckResult public T error(@Nullable Drawable drawable)
      Sets a Drawable to display if a load fails.

      Replaces any previous calls to this method or error(int)

      Parameters:
      drawable - The drawable to display.
      Returns:
      This request builder.
    • error

      @NonNull @CheckResult public T error(@DrawableRes int resourceId)
      Sets a resource to display if a load fails.

      Replaces any previous calls to this method or error(Drawable)

      Parameters:
      resourceId - The id of the resource to use as a placeholder.
      Returns:
      This request builder.
    • theme

      @NonNull @CheckResult public T theme(@Nullable Resources.Theme theme)
      Sets the Resources.Theme to apply when loading Drawables for resource ids, including those provided via error(int), placeholder(int), and fallback(Drawable).

      The Resources.Theme provided here will override the Resources.Theme of the application Context.

      Parameters:
      theme - The theme to use when loading Drawables.
      Returns:
      this request builder.
    • skipMemoryCache

      @NonNull @CheckResult public T skipMemoryCache(boolean skip)
      Allows the loaded resource to skip the memory cache.

      Note - this is not a guarantee. If a request is already pending for this resource and that request is not also skipping the memory cache, the resource will be cached in memory.

      Parameters:
      skip - True to allow the resource to skip the memory cache.
      Returns:
      This request builder.
    • override

      @NonNull @CheckResult public T override(int width, int height)
      Overrides the Target's width and height with the given values. This is useful for thumbnails, and should only be used for other cases when you need a very specific image size.
      Parameters:
      width - The width in pixels to use to load the resource.
      height - The height in pixels to use to load the resource.
      Returns:
      This request builder.
    • override

      @NonNull @CheckResult public T override(int size)
      Overrides the Target's width and height with the given size.
      Parameters:
      size - The width and height to use.
      Returns:
      This request builder.
      See Also:
    • signature

      @NonNull @CheckResult public T signature(@NonNull Key signature)
      Sets some additional data to be mixed in to the memory and disk cache keys allowing the caller more control over when cached data is invalidated.

      Note - The signature does not replace the cache key, it is purely additive.

      Parameters:
      signature - A unique non-null Key representing the current state of the model that will be mixed in to the cache key.
      Returns:
      This request builder.
      See Also:
    • clone

      @CheckResult public T clone()
      Returns a copy of this request builder with all of the options put so far on this builder.

      This method returns a "deep" copy in that all non-immutable arguments are copied such that changes to one builder will not affect the other builder. However, in addition to immutable arguments, the current model is not copied copied so changes to the model will affect both builders.

      Even if this object was locked, the cloned object returned from this method will not be locked.

      Overrides:
      clone in class Object
    • set

      @NonNull @CheckResult public <Y> T set(@NonNull Option<Y> option, @NonNull Y value)
    • decode

      @NonNull @CheckResult public T decode(@NonNull Class<?> resourceClass)
    • isTransformationAllowed

      public final boolean isTransformationAllowed()
    • isTransformationSet

      public final boolean isTransformationSet()
    • isLocked

      public final boolean isLocked()
    • encodeFormat

      @NonNull @CheckResult public T encodeFormat(@NonNull Bitmap.CompressFormat format)
      Sets the value for key BitmapEncoder.COMPRESSION_FORMAT.
    • encodeQuality

      @NonNull @CheckResult public T encodeQuality(@IntRange(from=0L,to=100L) int quality)
      Sets the value for key BitmapEncoder.COMPRESSION_QUALITY.
    • frame

      @NonNull @CheckResult public T frame(@IntRange(from=0L) long frameTimeMicros)
      Sets the time position of the frame to extract from a video.

      This is a component option specific to VideoDecoder. If the default video decoder is replaced or skipped because of your configuration, this option may be ignored.

      Parameters:
      frameTimeMicros - The time position in microseconds of the desired frame. If negative, the Android framework implementation return a representative frame.
      See Also:
    • format

      @NonNull @CheckResult public T format(@NonNull DecodeFormat format)
      Sets the DecodeFormat to use when decoding Bitmap objects using Downsampler and Glide's default GIF decoders.

      DecodeFormat is a request, not a requirement. It's possible the resource will be decoded using a decoder that cannot control the format (MediaMetadataRetriever for example), or that the decoder may choose to ignore the requested format if it can't display the image (i.e. RGB_565 is requested, but the image has alpha).

      This is a component option specific to Downsampler and Glide's GIF decoders. If the default Bitmap decoders are replaced or skipped because of your configuration, this option may be ignored.

      To set only the format used when decoding Bitmaps, use set(Option, Object)} and Downsampler.DECODE_FORMAT. To set only the format used when decoding GIF frames, use set(Option, Object) and GifOptions.DECODE_FORMAT.

      See Also:
    • disallowHardwareConfig

      @NonNull @CheckResult public T disallowHardwareConfig()
      Disables the use of Bitmap.Config.HARDWARE in Downsampler to avoid errors caused by inspecting Bitmap pixels, drawing with hardware support disabled, drawing to Canvass backed by Bitmaps etc.

      It's almost never safe to set Downsampler.ALLOW_HARDWARE_CONFIG to true so we only provide a way to disable hardware configs entirely. If no option is set for Downsampler.ALLOW_HARDWARE_CONFIG, Glide will set the value per request based on whether or not a Transformation is applied and if one is, the type of Transformation applied. Built in transformations like FitCenter and DownsampleStrategy.CenterOutside can safely use Bitmap.Config.HARDWARE because they can be entirely replaced by scaling within Downsampler. Transformations like circleCrop() that can't be replicated by Downsampler cannot use Bitmap.Config.HARDWARE because Bitmap.Config.HARDWARE cannot be drawn to Canvass, which is required by most Transformations.

    • downsample

      @NonNull @CheckResult public T downsample(@NonNull DownsampleStrategy strategy)
      Sets the DownsampleStrategy to use when decoding Bitmaps using Downsampler.

      This is a component option specific to Downsampler. If the defautlt Bitmap decoder is replaced or skipped because of your configuration, this option may be ignored.

    • timeout

      @NonNull @CheckResult public T timeout(@IntRange(from=0L) int timeoutMs)
      Sets the read and write timeout for the http requests used to load the image.

      This is a component option specific to Glide's default networking library and HttpGlideUrlLoader. If you use any other networking library including Glide's Volley or OkHttp integration libraries, this option will be ignored.

      Parameters:
      timeoutMs - The read and write timeout in milliseconds.
      See Also:
    • optionalCenterCrop

      @NonNull @CheckResult public T optionalCenterCrop()
      Applies CenterCrop to all default types, and ignores unknown types.

      This will override previous calls to dontTransform().

      See Also:
    • centerCrop

      @NonNull @CheckResult public T centerCrop()
      Applies CenterCrop to all default types and throws an exception if asked to transform an unknown type.

      this will override previous calls to dontTransform() ()}.

      See Also:
    • optionalFitCenter

      @NonNull @CheckResult public T optionalFitCenter()
      Applies FitCenter and to all default types, DownsampleStrategy.FIT_CENTER to image types, and ignores unknown types.

      This will override previous calls to dontTransform() and previous calls to downsample(DownsampleStrategy).

      See Also:
    • fitCenter

      @NonNull @CheckResult public T fitCenter()
      Applies FitCenter and to all default types, DownsampleStrategy.FIT_CENTER to image types, and throws an exception if asked to transform an unknown type.

      This will override previous calls to dontTransform() and previous calls to downsample(DownsampleStrategy).

      See Also:
    • optionalCenterInside

      @NonNull @CheckResult public T optionalCenterInside()
      Applies CenterInside to all default types, DownsampleStrategy.CENTER_INSIDE to image types, and ignores unknown types.

      This will override previous calls to dontTransform() and previous calls to downsample(DownsampleStrategy).

      See Also:
    • centerInside

      @NonNull @CheckResult public T centerInside()
      Applies CenterInside to all default types, DownsampleStrategy.CENTER_INSIDE to image types and throws an exception if asked to transform an unknown type.

      This will override previous calls to dontTransform() and previous calls to downsample(DownsampleStrategy).

      See Also:
    • optionalCircleCrop

      @NonNull @CheckResult public T optionalCircleCrop()
      Applies CircleCrop to all default types, and ignores unknown types.

      This will override previous calls to dontTransform().

      See Also:
    • circleCrop

      @NonNull @CheckResult public T circleCrop()
      Applies CircleCrop to all default types and throws an exception if asked to transform an unknown type.

      This will override previous calls to dontTransform().

      See Also:
    • transform

      @NonNull @CheckResult public T transform(@NonNull Transformation<Bitmap> transformation)
      Applies the given Transformation for Bitmaps to the default types (Bitmap, BitmapDrawable, and GifDrawable) and throws an exception if asked to transform an unknown type.

      This will override previous calls to dontTransform().

      Parameters:
      transformation - Any Transformation for Bitmaps.
      See Also:
    • transform

      @NonNull @CheckResult public T transform(@NonNull Transformation<Bitmap>... transformations)
      Applies the given Transformations in the given order for Bitmaps to the default types (Bitmap, BitmapDrawable, and GifDrawable) and throws an exception if asked to transform an unknown type.

      This will override previous calls to dontTransform().

      Parameters:
      transformations - One or more Transformations for Bitmaps.
      See Also:
    • transforms

      @NonNull @CheckResult @Deprecated public T transforms(@NonNull Transformation<Bitmap>... transformations)
      Deprecated.
      Deprecated due to api update, use transform(Transformation[]) instead
      Applies the given Transformations in the given order for Bitmaps to the default types (Bitmap, BitmapDrawable, and GifDrawable) and throws an exception if asked to transform an unknown type.

      This will override previous calls to dontTransform().

      Parameters:
      transformations - One or more Transformations for Bitmaps.
      See Also:
    • optionalTransform

      @NonNull @CheckResult public T optionalTransform(@NonNull Transformation<Bitmap> transformation)
      Applies the given Transformation for Bitmaps to the default types (Bitmap, BitmapDrawable, and GifDrawable) and ignores unknown types.

      This will override previous calls to dontTransform().

      Parameters:
      transformation - Any Transformation for Bitmaps.
      See Also:
    • optionalTransform

      @NonNull @CheckResult public <Y> T optionalTransform(@NonNull Class<Y> resourceClass, @NonNull Transformation<Y> transformation)
      Applies the given Transformation for any decoded resource of the given type and allows unknown resource types to be ignored.

      Users can apply different transformations for each resource class. Applying a Transformation for a resource type that already has a Transformation will override the previous call.

      If any calls are made to the non-optional transform methods, then attempting to transform an unknown resource class will throw an exception. To allow unknown types, users must always call the optional version of each method.

      This will override previous calls to dontTransform().

      Parameters:
      resourceClass - The type of resource to transform.
      transformation - The Transformation to apply.
    • transform

      @NonNull @CheckResult public <Y> T transform(@NonNull Class<Y> resourceClass, @NonNull Transformation<Y> transformation)
      Applies the given Transformation for any decoded resource of the given type and throws if asked to transform an unknown resource type.

      This will override previous calls to dontTransform().

      Parameters:
      resourceClass - The type of resource to transform.
      transformation - The Transformation to apply.
      See Also:
    • dontTransform

      @NonNull @CheckResult public T dontTransform()
      Removes all applied Transformations for all resource classes and allows unknown resource types to be transformed without throwing an exception.
    • dontAnimate

      @NonNull @CheckResult public T dontAnimate()
      Disables resource decoders that return animated resources so any resource returned will be static.

      To disable transitions (fades etc) use TransitionOptions.dontTransition()

    • apply

      @NonNull @CheckResult public T apply(@NonNull BaseRequestOptions<?> o)
      Updates this options set with any options that are explicitly set in the given T object and returns this object if autoClone() is disabled or a new T object if autoClone() is enabled.

      #apply only replaces those values that are explicitly set in the given T. If you need to completely reset all previously set options, create a new T object instead of using this method.

      The options that will be set to values in the returned T object is the intersection of the set of options in this T object and the given T object that were explicitly set. If the values of any of the options conflict, the values in the returned T object will be set to those in the given T object.

    • isEquivalentTo

      public final boolean isEquivalentTo(BaseRequestOptions<?> other)
      Returns true if this BaseRequestOptions is equivalent to the given BaseRequestOptions (has all of the same options and sizes).

      This method is identical to equals(Object), but this can not be overridden. We need to use this method instead of equals(Object), because child classes may have additional fields, such as listeners and models, that should not be considered when checking for equality.

    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • lock

      @NonNull public T lock()
      Throws if any further mutations are attempted.

      Once locked, the only way to unlock is to use clone()

    • autoClone

      @NonNull public T autoClone()
      Similar to lock() except that mutations cause a clone() operation to happen before the mutation resulting in all methods returning a new Object and leaving the original locked object unmodified.

      Auto clone is not retained by cloned objects returned from mutations. The cloned objects are mutable and are not locked.

    • selfOrThrowIfLocked

      @NonNull protected final T selfOrThrowIfLocked()
    • isAutoCloneEnabled

      protected final boolean isAutoCloneEnabled()
    • isDiskCacheStrategySet

      public final boolean isDiskCacheStrategySet()
    • isSkipMemoryCacheSet

      public final boolean isSkipMemoryCacheSet()
    • getTransformations

      @NonNull public final Map<Class<?>,Transformation<?>> getTransformations()
    • isTransformationRequired

      public final boolean isTransformationRequired()
    • getOptions

      @NonNull public final Options getOptions()
    • getResourceClass

      @NonNull public final Class<?> getResourceClass()
    • getDiskCacheStrategy

      @NonNull public final DiskCacheStrategy getDiskCacheStrategy()
    • getErrorPlaceholder

      @Nullable public final Drawable getErrorPlaceholder()
    • getErrorId

      public final int getErrorId()
    • getPlaceholderId

      public final int getPlaceholderId()
    • getPlaceholderDrawable

      @Nullable public final Drawable getPlaceholderDrawable()
    • getFallbackId

      public final int getFallbackId()
    • getFallbackDrawable

      @Nullable public final Drawable getFallbackDrawable()
    • getTheme

      @Nullable public final Resources.Theme getTheme()
    • isMemoryCacheable

      public final boolean isMemoryCacheable()
    • getSignature

      @NonNull public final Key getSignature()
    • isPrioritySet

      public final boolean isPrioritySet()
    • getPriority

      @NonNull public final Priority getPriority()
    • getOverrideWidth

      public final int getOverrideWidth()
    • isValidOverride

      public final boolean isValidOverride()
    • getOverrideHeight

      public final int getOverrideHeight()
    • getSizeMultiplier

      public final float getSizeMultiplier()
    • getUseUnlimitedSourceGeneratorsPool

      public final boolean getUseUnlimitedSourceGeneratorsPool()
    • getUseAnimationPool

      public final boolean getUseAnimationPool()
    • getOnlyRetrieveFromCache

      public final boolean getOnlyRetrieveFromCache()