Class BaseRequestOptions<T extends BaseRequestOptions<T>>
- Type Parameters:
T- The particular child implementation
- All Implemented Interfaces:
Cloneable
- Direct Known Subclasses:
RequestBuilder,RequestOptions
RequestOptions and RequestBuilder.
This class is not meant for general use and may change at any time.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionapply(BaseRequestOptions<?> o) Updates this options set with any options that are explicitly set in the givenTobject and returns this object ifautoClone()is disabled or a newTobject ifautoClone()is enabled.AppliesCenterCropto all default types and throws an exception if asked to transform an unknown type.AppliesCenterInsideto all default types,DownsampleStrategy.CENTER_INSIDEto image types and throws an exception if asked to transform an unknown type.AppliesCircleCropto all default types and throws an exception if asked to transform an unknown type.clone()Returns a copy of this request builder with all of the options put so far on this builder.Disables the use ofBitmap.Config.HARDWAREinDownsamplerto avoid errors caused by inspecting Bitmap pixels, drawing with hardware support disabled, drawing toCanvass backed byBitmaps etc.diskCacheStrategy(DiskCacheStrategy strategy) Sets theDiskCacheStrategyto use for this load.Disables resource decoders that return animated resources so any resource returned will be static.Removes all appliedTransformationsfor all resource classes and allows unknown resource types to be transformed without throwing an exception.downsample(DownsampleStrategy strategy) encodeFormat(Bitmap.CompressFormat format) Sets the value for keyBitmapEncoder.COMPRESSION_FORMAT.encodeQuality(int quality) Sets the value for keyBitmapEncoder.COMPRESSION_QUALITY.booleanerror(int resourceId) Sets a resource to display if a load fails.Sets aDrawableto display if a load fails.fallback(int resourceId) Sets a resource to display if the model provided toRequestBuilder.load(Object)isnull.AppliesFitCenterand to all default types,DownsampleStrategy.FIT_CENTERto image types, and throws an exception if asked to transform an unknown type.format(DecodeFormat format) Sets theDecodeFormatto use when decodingBitmapobjects usingDownsamplerand Glide's default GIF decoders.frame(long frameTimeMicros) Sets the time position of the frame to extract from a video.final DiskCacheStrategyfinal intfinal Drawablefinal Drawablefinal intfinal booleanfinal Optionsfinal intfinal intfinal Drawablefinal intfinal Priorityfinal Class<?>final Keyfinal floatfinal Resources.ThemegetTheme()final Map<Class<?>,Transformation<?>> final booleanfinal booleaninthashCode()protected final booleanfinal booleanfinal booleanisEquivalentTo(BaseRequestOptions<?> other) Returnstrueif thisBaseRequestOptionsis equivalent to the givenBaseRequestOptions(has all of the same options and sizes).final booleanisLocked()final booleanfinal booleanfinal booleanfinal booleanfinal booleanfinal booleanfinal booleanlock()Throws if any further mutations are attempted.onlyRetrieveFromCache(boolean flag) If set to true, will only load an item if found in the cache, and will not fetch from source.AppliesCenterCropto all default types, and ignores unknown types.AppliesCenterInsideto all default types,DownsampleStrategy.CENTER_INSIDEto image types, and ignores unknown types.AppliesCircleCropto all default types, and ignores unknown types.AppliesFitCenterand to all default types,DownsampleStrategy.FIT_CENTERto image types, and ignores unknown types.optionalTransform(Transformation<Bitmap> transformation) Applies the givenTransformationforBitmapsto the default types (Bitmap,BitmapDrawable, andGifDrawable) and ignores unknown types.<Y> ToptionalTransform(Class<Y> resourceClass, Transformation<Y> transformation) Applies the givenTransformationfor any decoded resource of the given type and allows unknown resource types to be ignored.override(int size) Overrides theTarget's width and height with the given size.override(int width, int height) Overrides theTarget's width and height with the given values.placeholder(int resourceId) Sets an Android resource id for aDrawableresource to display while a resource is loading.placeholder(Drawable drawable) Sets anDrawableto display while a resource is loading.Sets the priority for this load.protected final T<Y> TSets 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.sizeMultiplier(float sizeMultiplier) Applies a multiplier to theTarget's size before loading the resource.skipMemoryCache(boolean skip) Allows the loaded resource to skip the memory cache.theme(Resources.Theme theme) Sets theResources.Themeto apply when loadingDrawables for resource ids, including those provided viaerror(int),placeholder(int), andfallback(Drawable).timeout(int timeoutMs) Sets the read and write timeout for the http requests used to load the image.transform(Transformation<Bitmap> transformation) Applies the givenTransformationforBitmapsto the default types (Bitmap,BitmapDrawable, andGifDrawable) and throws an exception if asked to transform an unknown type.transform(Transformation<Bitmap>... transformations) Applies the givenTransformations in the given order forBitmapsto the default types (Bitmap,BitmapDrawable, andGifDrawable) and throws an exception if asked to transform an unknown type.<Y> Ttransform(Class<Y> resourceClass, Transformation<Y> transformation) Applies the givenTransformationfor any decoded resource of the given type and throws if asked to transform an unknown resource type.transforms(Transformation<Bitmap>... transformations) Deprecated.useAnimationPool(boolean flag) If set totrue, uses a specialExecutorthat is used exclusively for decoding frames of animated resources, like GIFs.useUnlimitedSourceGeneratorsPool(boolean flag) If set totrue, uses a cached unlimitedExecutorto run the request.
-
Constructor Details
-
BaseRequestOptions
public BaseRequestOptions()
-
-
Method Details
-
sizeMultiplier
Applies a multiplier to theTarget's size before loading the resource. Useful for loading thumbnails or trying to avoid loading huge resources (particularlyBitmaps on devices with overly dense screens.- Parameters:
sizeMultiplier- The multiplier to apply to theTarget's dimensions when loading the resource.- Returns:
- This request builder.
-
useUnlimitedSourceGeneratorsPool
If set totrue, uses a cached unlimitedExecutorto 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 anduseAnimationPool(boolean)will be ignored. -
useAnimationPool
If set totrue, uses a specialExecutorthat 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
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.DATAandDiskCacheStrategy.RESOURCE). If this flag is set totrueand 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
trueand also calldiskCacheStrategy(DiskCacheStrategy)withDiskCacheStrategy.NONE -
diskCacheStrategy
Sets theDiskCacheStrategyto use for this load.Defaults to
DiskCacheStrategy.AUTOMATIC.For most applications
DiskCacheStrategy.RESOURCEis 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 usingDiskCacheStrategy.DATAorDiskCacheStrategy.ALL.- Parameters:
strategy- The strategy to use.- Returns:
- This request builder.
-
priority
Sets the priority for this load.- Parameters:
priority- A priority.- Returns:
- This request builder.
-
placeholder
Sets anDrawableto 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
Sets an Android resource id for aDrawableresource 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
Sets anDrawableto display if the model provided toRequestBuilder.load(Object)isnull.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
Sets a resource to display if the model provided toRequestBuilder.load(Object)isnull.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
Sets aDrawableto 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
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
Sets theResources.Themeto apply when loadingDrawables for resource ids, including those provided viaerror(int),placeholder(int), andfallback(Drawable).The
Resources.Themeprovided here will override theResources.Themeof the applicationContext.- Parameters:
theme- The theme to use when loading Drawables.- Returns:
- this request builder.
-
skipMemoryCache
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
Overrides theTarget'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
Overrides theTarget's width and height with the given size.- Parameters:
size- The width and height to use.- Returns:
- This request builder.
- See Also:
-
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.
-
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.
-
set
-
decode
-
isTransformationAllowed
public final boolean isTransformationAllowed() -
isTransformationSet
public final boolean isTransformationSet() -
isLocked
public final boolean isLocked() -
encodeFormat
Sets the value for keyBitmapEncoder.COMPRESSION_FORMAT. -
encodeQuality
Sets the value for keyBitmapEncoder.COMPRESSION_QUALITY. -
frame
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
Sets theDecodeFormatto use when decodingBitmapobjects usingDownsamplerand Glide's default GIF decoders.DecodeFormatis a request, not a requirement. It's possible the resource will be decoded using a decoder that cannot control the format (MediaMetadataRetrieverfor 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
Downsamplerand 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, useset(Option, Object)} andDownsampler.DECODE_FORMAT. To set only the format used when decoding GIF frames, useset(Option, Object)andGifOptions.DECODE_FORMAT. -
disallowHardwareConfig
Disables the use ofBitmap.Config.HARDWAREinDownsamplerto avoid errors caused by inspecting Bitmap pixels, drawing with hardware support disabled, drawing toCanvass backed byBitmaps etc.It's almost never safe to set
Downsampler.ALLOW_HARDWARE_CONFIGtotrueso we only provide a way to disable hardware configs entirely. If no option is set forDownsampler.ALLOW_HARDWARE_CONFIG, Glide will set the value per request based on whether or not aTransformationis applied and if one is, the type ofTransformationapplied. Built in transformations likeFitCenterandDownsampleStrategy.CenterOutsidecan safely useBitmap.Config.HARDWAREbecause they can be entirely replaced by scaling withinDownsampler.Transformations likecircleCrop()that can't be replicated byDownsamplercannot useBitmap.Config.HARDWAREbecauseBitmap.Config.HARDWAREcannot be drawn toCanvass, which is required by mostTransformations. -
downsample
Sets theDownsampleStrategyto use when decodingBitmapsusingDownsampler.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
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
AppliesCenterCropto all default types, and ignores unknown types.This will override previous calls to
dontTransform(). -
centerCrop
AppliesCenterCropto all default types and throws an exception if asked to transform an unknown type.this will override previous calls to
dontTransform()()}. -
optionalFitCenter
AppliesFitCenterand to all default types,DownsampleStrategy.FIT_CENTERto image types, and ignores unknown types.This will override previous calls to
dontTransform()and previous calls todownsample(DownsampleStrategy). -
fitCenter
AppliesFitCenterand to all default types,DownsampleStrategy.FIT_CENTERto image types, and throws an exception if asked to transform an unknown type.This will override previous calls to
dontTransform()and previous calls todownsample(DownsampleStrategy). -
optionalCenterInside
AppliesCenterInsideto all default types,DownsampleStrategy.CENTER_INSIDEto image types, and ignores unknown types.This will override previous calls to
dontTransform()and previous calls todownsample(DownsampleStrategy). -
centerInside
AppliesCenterInsideto all default types,DownsampleStrategy.CENTER_INSIDEto image types and throws an exception if asked to transform an unknown type.This will override previous calls to
dontTransform()and previous calls todownsample(DownsampleStrategy). -
optionalCircleCrop
AppliesCircleCropto all default types, and ignores unknown types.This will override previous calls to
dontTransform(). -
circleCrop
AppliesCircleCropto all default types and throws an exception if asked to transform an unknown type.This will override previous calls to
dontTransform(). -
transform
Applies the givenTransformationforBitmapsto the default types (Bitmap,BitmapDrawable, andGifDrawable) and throws an exception if asked to transform an unknown type.This will override previous calls to
dontTransform().- Parameters:
transformation- AnyTransformationforBitmaps.- See Also:
-
transform
Applies the givenTransformations in the given order forBitmapsto the default types (Bitmap,BitmapDrawable, andGifDrawable) and throws an exception if asked to transform an unknown type.This will override previous calls to
dontTransform().- Parameters:
transformations- One or moreTransformations forBitmaps.- See Also:
-
transforms
@NonNull @CheckResult @Deprecated public T transforms(@NonNull Transformation<Bitmap>... transformations) Deprecated.Deprecated due to api update, usetransform(Transformation[])insteadApplies the givenTransformations in the given order forBitmapsto the default types (Bitmap,BitmapDrawable, andGifDrawable) and throws an exception if asked to transform an unknown type.This will override previous calls to
dontTransform().- Parameters:
transformations- One or moreTransformations forBitmaps.- See Also:
-
optionalTransform
Applies the givenTransformationforBitmapsto the default types (Bitmap,BitmapDrawable, andGifDrawable) and ignores unknown types.This will override previous calls to
dontTransform().- Parameters:
transformation- AnyTransformationforBitmaps.- See Also:
-
optionalTransform
@NonNull @CheckResult public <Y> T optionalTransform(@NonNull Class<Y> resourceClass, @NonNull Transformation<Y> transformation) Applies the givenTransformationfor 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
Transformationfor a resource type that already has aTransformationwill 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- TheTransformationto apply.
-
transform
@NonNull @CheckResult public <Y> T transform(@NonNull Class<Y> resourceClass, @NonNull Transformation<Y> transformation) Applies the givenTransformationfor 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- TheTransformationto apply.- See Also:
-
dontTransform
Removes all appliedTransformationsfor all resource classes and allows unknown resource types to be transformed without throwing an exception. -
dontAnimate
Disables resource decoders that return animated resources so any resource returned will be static.To disable transitions (fades etc) use
TransitionOptions.dontTransition() -
apply
Updates this options set with any options that are explicitly set in the givenTobject and returns this object ifautoClone()is disabled or a newTobject ifautoClone()is enabled.#applyonly replaces those values that are explicitly set in the givenT. If you need to completely reset all previously set options, create a newTobject instead of using this method.The options that will be set to values in the returned
Tobject is the intersection of the set of options in thisTobject and the givenTobject that were explicitly set. If the values of any of the options conflict, the values in the returnedTobject will be set to those in the givenTobject. -
isEquivalentTo
Returnstrueif thisBaseRequestOptionsis equivalent to the givenBaseRequestOptions(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 ofequals(Object), because child classes may have additional fields, such as listeners and models, that should not be considered when checking for equality. -
equals
-
hashCode
public int hashCode() -
lock
Throws if any further mutations are attempted.Once locked, the only way to unlock is to use
clone() -
autoClone
Similar tolock()except that mutations cause aclone()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
-
isAutoCloneEnabled
protected final boolean isAutoCloneEnabled() -
isDiskCacheStrategySet
public final boolean isDiskCacheStrategySet() -
isSkipMemoryCacheSet
public final boolean isSkipMemoryCacheSet() -
getTransformations
-
isTransformationRequired
public final boolean isTransformationRequired() -
getOptions
-
getResourceClass
-
getDiskCacheStrategy
-
getErrorPlaceholder
-
getErrorId
public final int getErrorId() -
getPlaceholderId
public final int getPlaceholderId() -
getPlaceholderDrawable
-
getFallbackId
public final int getFallbackId() -
getFallbackDrawable
-
getTheme
-
isMemoryCacheable
public final boolean isMemoryCacheable() -
getSignature
-
isPrioritySet
public final boolean isPrioritySet() -
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()
-
transform(Transformation[])instead