T
- The particular child implementationpublic abstract class BaseRequestOptions<T extends BaseRequestOptions<T>>
extends java.lang.Object
implements java.lang.Cloneable
RequestOptions
and RequestBuilder
.
This class is not meant for general use and may change at any time.
Constructor and Description |
---|
BaseRequestOptions() |
Modifier and Type | Method and Description |
---|---|
T |
apply(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. |
T |
autoClone()
|
T |
centerCrop()
Applies
CenterCrop to all default types and throws an exception if asked to transform
an unknown type. |
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. |
T |
circleCrop()
Applies
CircleCrop to all default types and throws an exception if asked to transform
an unknown type. |
T |
clone()
Returns a copy of this request builder with all of the options put so far on this builder.
|
T |
decode(java.lang.Class<?> resourceClass) |
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 Canvas s backed by Bitmap s etc. |
T |
diskCacheStrategy(DiskCacheStrategy strategy)
Sets the
DiskCacheStrategy to use for this load. |
T |
dontAnimate()
Disables resource decoders that return animated resources so any resource returned will be
static.
|
T |
dontTransform()
Removes all applied
Transformations for all resource classes and allows
unknown resource types to be transformed without throwing an exception. |
T |
downsample(DownsampleStrategy strategy)
|
T |
encodeFormat(android.graphics.Bitmap.CompressFormat format)
Sets the value for key
BitmapEncoder.COMPRESSION_FORMAT . |
T |
encodeQuality(int quality)
Sets the value for key
BitmapEncoder.COMPRESSION_QUALITY . |
boolean |
equals(java.lang.Object o) |
T |
error(android.graphics.drawable.Drawable drawable)
Sets a
Drawable to display if a load fails. |
T |
error(int resourceId)
Sets a resource to display if a load fails.
|
T |
fallback(android.graphics.drawable.Drawable drawable)
|
T |
fallback(int resourceId)
Sets a resource to display if the model provided to
RequestBuilder.load(Object) is null . |
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. |
T |
format(DecodeFormat format)
Sets the
DecodeFormat to use when decoding Bitmap objects using Downsampler and Glide's default GIF decoders. |
T |
frame(long frameTimeMicros)
Sets the time position of the frame to extract from a video.
|
DiskCacheStrategy |
getDiskCacheStrategy() |
int |
getErrorId() |
android.graphics.drawable.Drawable |
getErrorPlaceholder() |
android.graphics.drawable.Drawable |
getFallbackDrawable() |
int |
getFallbackId() |
boolean |
getOnlyRetrieveFromCache() |
Options |
getOptions() |
int |
getOverrideHeight() |
int |
getOverrideWidth() |
android.graphics.drawable.Drawable |
getPlaceholderDrawable() |
int |
getPlaceholderId() |
Priority |
getPriority() |
java.lang.Class<?> |
getResourceClass() |
Key |
getSignature() |
float |
getSizeMultiplier() |
android.content.res.Resources.Theme |
getTheme() |
java.util.Map<java.lang.Class<?>,Transformation<?>> |
getTransformations() |
boolean |
getUseAnimationPool() |
boolean |
getUseUnlimitedSourceGeneratorsPool() |
int |
hashCode() |
protected boolean |
isAutoCloneEnabled() |
boolean |
isDiskCacheStrategySet() |
boolean |
isLocked() |
boolean |
isMemoryCacheable() |
boolean |
isPrioritySet() |
boolean |
isSkipMemoryCacheSet() |
boolean |
isTransformationAllowed() |
boolean |
isTransformationRequired() |
boolean |
isTransformationSet() |
boolean |
isValidOverride() |
T |
lock()
Throws if any further mutations are attempted.
|
T |
onlyRetrieveFromCache(boolean flag)
If set to true, will only load an item if found in the cache, and will not fetch from source.
|
T |
optionalCenterCrop()
Applies
CenterCrop to all default types, and
ignores unknown types. |
T |
optionalCenterInside()
Applies
CenterInside to all default types,
DownsampleStrategy.CENTER_INSIDE to image types, and ignores unknown types. |
T |
optionalCircleCrop()
Applies
CircleCrop to all default types, and ignores unknown types. |
T |
optionalFitCenter()
Applies
FitCenter and to all default types, DownsampleStrategy.FIT_CENTER to
image types, and ignores unknown types. |
<Y> T |
optionalTransform(java.lang.Class<Y> resourceClass,
Transformation<Y> transformation)
Applies the given
Transformation for any decoded resource of the given type and allows
unknown resource types to be ignored. |
T |
optionalTransform(Transformation<android.graphics.Bitmap> transformation)
Applies the given
Transformation for Bitmaps to the default types
(Bitmap , BitmapDrawable , and GifDrawable ) and ignores unknown types. |
T |
override(int size)
Overrides the
Target 's width and height with the
given size. |
T |
override(int width,
int height)
Overrides the
Target 's width and height with the
given values. |
T |
placeholder(android.graphics.drawable.Drawable drawable)
Sets an
Drawable to display while a resource is loading. |
T |
placeholder(int resourceId)
Sets an Android resource id for a
Drawable resource to display while a resource is
loading. |
T |
priority(Priority priority)
Sets the priority for this load.
|
protected T |
selfOrThrowIfLocked() |
<Y> T |
set(Option<Y> option,
Y value) |
T |
signature(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.
|
T |
sizeMultiplier(float sizeMultiplier)
Applies a multiplier to the
Target 's size before
loading the resource. |
T |
skipMemoryCache(boolean skip)
Allows the loaded resource to skip the memory cache.
|
T |
theme(android.content.res.Resources.Theme theme)
Sets the
Resources.Theme to apply when loading Drawable s
for resource ids provided via error(int) , placeholder(int) , and fallback(Drawable) . |
T |
timeout(int timeoutMs)
Sets the read and write timeout for the http requests used to load the image.
|
<Y> T |
transform(java.lang.Class<Y> resourceClass,
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. |
T |
transform(Transformation<android.graphics.Bitmap>... transformations)
Applies the given
Transformation s 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. |
T |
transform(Transformation<android.graphics.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. |
T |
transforms(Transformation<android.graphics.Bitmap>... transformations)
Deprecated.
Deprecated due to api update, use
transform(Transformation[]) instead |
T |
useAnimationPool(boolean flag)
If set to
true , uses a special Executor that is used
exclusively for decoding frames of animated resources, like GIFs. |
T |
useUnlimitedSourceGeneratorsPool(boolean flag)
If set to
true , uses a cached unlimited Executor to run
the request. |
@NonNull @CheckResult public T sizeMultiplier(float sizeMultiplier)
Target
's size before
loading the resource. Useful for loading thumbnails or trying to avoid loading huge resources
(particularly Bitmap
s on devices with overly dense screens.sizeMultiplier
- The multiplier to apply to the Target
's dimensions when loading the resource.@NonNull @CheckResult public T useUnlimitedSourceGeneratorsPool(boolean flag)
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.
@NonNull @CheckResult public T useAnimationPool(boolean flag)
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.
@NonNull @CheckResult public T onlyRetrieveFromCache(boolean flag)
@NonNull @CheckResult public T diskCacheStrategy(@NonNull DiskCacheStrategy strategy)
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
.
strategy
- The strategy to use.@NonNull @CheckResult public T priority(@NonNull Priority priority)
priority
- A priority.@NonNull @CheckResult public T placeholder(@Nullable android.graphics.drawable.Drawable drawable)
Drawable
to display while a resource is loading.
Replaces any previous calls to this method or placeholder(int)
.
drawable
- The drawable to display as a placeholder.@NonNull @CheckResult public T placeholder(@DrawableRes int resourceId)
Drawable
resource to display while a resource is
loading.
Replaces any previous calls to this method or placeholder(Drawable)
resourceId
- The id of the resource to use as a placeholder@NonNull @CheckResult public T fallback(@Nullable android.graphics.drawable.Drawable drawable)
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)
.
drawable
- The drawable to display as a placeholder.placeholder(Drawable)
,
placeholder(int)
@NonNull @CheckResult public T fallback(@DrawableRes int resourceId)
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)
.
resourceId
- The id of the resource to use as a fallback.placeholder(Drawable)
,
placeholder(int)
@NonNull @CheckResult public T error(@Nullable android.graphics.drawable.Drawable drawable)
Drawable
to display if a load fails.
Replaces any previous calls to this method or error(int)
drawable
- The drawable to display.@NonNull @CheckResult public T error(@DrawableRes int resourceId)
Replaces any previous calls to this method or error(Drawable)
resourceId
- The id of the resource to use as a placeholder.@NonNull @CheckResult public T theme(@Nullable android.content.res.Resources.Theme theme)
Resources.Theme
to apply when loading Drawable
s
for resource ids provided via error(int)
, placeholder(int)
, and fallback(Drawable)
.
The theme is NOT applied in the decoder that will attempt to decode a given resource id model on Glide's background threads. The theme is used exclusively on the main thread to obtain placeholder/error/fallback drawables to avoid leaking Activities.
If the Context
of the Fragment
or Activity
used to start this load has a different Resources.Theme
, the Resources.Theme
provided
here will override the Resources.Theme
of the Context
.
theme
- The theme to use when loading Drawables.@NonNull @CheckResult public T skipMemoryCache(boolean skip)
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.
skip
- True to allow the resource to skip the memory cache.@NonNull @CheckResult public T override(int width, int height)
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.width
- The width in pixels to use to load the resource.height
- The height in pixels to use to load the resource.@NonNull @CheckResult public T override(int size)
Target
's width and height with the
given size.size
- The width and height to use.override(int, int)
@NonNull @CheckResult public T signature(@NonNull Key signature)
Note - The signature does not replace the cache key, it is purely additive.
@CheckResult public T clone()
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.
clone
in class java.lang.Object
@NonNull @CheckResult public T decode(@NonNull java.lang.Class<?> resourceClass)
public final boolean isTransformationAllowed()
public final boolean isTransformationSet()
public final boolean isLocked()
@NonNull @CheckResult public T encodeFormat(@NonNull android.graphics.Bitmap.CompressFormat format)
BitmapEncoder.COMPRESSION_FORMAT
.@NonNull @CheckResult public T encodeQuality(int quality)
BitmapEncoder.COMPRESSION_QUALITY
.@NonNull @CheckResult public T frame(long frameTimeMicros)
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.
frameTimeMicros
- The time position in microseconds of the desired frame. If negative, the
Android framework implementation return a representative frame.VideoDecoder.TARGET_FRAME
@NonNull @CheckResult public T format(@NonNull DecodeFormat format)
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 Bitmap
s, 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
.
@NonNull @CheckResult public T disallowHardwareConfig()
Bitmap.Config.HARDWARE
in Downsampler
to
avoid errors caused by inspecting Bitmap pixels, drawing with hardware support disabled,
drawing to Canvas
s backed by Bitmap
s 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
. Transformation
s like circleCrop()
that can't be
replicated by Downsampler
cannot use Bitmap.Config#HARDWARE
because Bitmap.Config.HARDWARE
cannot be drawn to Canvas
s,
which is required by most Transformation
s.
@NonNull @CheckResult public T downsample(@NonNull DownsampleStrategy strategy)
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.
@NonNull @CheckResult public T timeout(int timeoutMs)
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.
timeoutMs
- The read and write timeout in milliseconds.HttpGlideUrlLoader.TIMEOUT
@NonNull @CheckResult public T optionalCenterCrop()
CenterCrop
to all default types, and
ignores unknown types.
This will override previous calls to dontTransform()
.
@NonNull @CheckResult public T centerCrop()
CenterCrop
to all default types and throws an exception if asked to transform
an unknown type.
this will override previous calls to dontTransform()
()}.
@NonNull @CheckResult public T optionalFitCenter()
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)
.
@NonNull @CheckResult public T fitCenter()
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)
.
@NonNull @CheckResult public T optionalCenterInside()
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)
.
@NonNull @CheckResult public T centerInside()
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)
.
@NonNull @CheckResult public T optionalCircleCrop()
CircleCrop
to all default types, and ignores unknown types.
This will override previous calls to dontTransform()
.
optionalTransform(Transformation)
,
circleCrop()
@NonNull @CheckResult public T circleCrop()
CircleCrop
to all default types and throws an exception if asked to transform
an unknown type.
This will override previous calls to dontTransform()
.
@NonNull @CheckResult public T transform(@NonNull Transformation<android.graphics.Bitmap> transformation)
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()
.
transformation
- Any Transformation
for Bitmap
s.optionalTransform(Transformation)
,
optionalTransform(Class, Transformation)
@NonNull @CheckResult public T transform(@NonNull Transformation<android.graphics.Bitmap>... transformations)
Transformation
s 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()
.
transformations
- One or more Transformation
s for Bitmap
s.optionalTransform(Transformation)
,
optionalTransform(Class, Transformation)
@NonNull @CheckResult @Deprecated public T transforms(@NonNull Transformation<android.graphics.Bitmap>... transformations)
transform(Transformation[])
insteadTransformation
s 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()
.
transformations
- One or more Transformation
s for Bitmap
s.optionalTransform(Transformation)
,
optionalTransform(Class, Transformation)
@NonNull @CheckResult public T optionalTransform(@NonNull Transformation<android.graphics.Bitmap> transformation)
Transformation
for Bitmaps
to the default types
(Bitmap
, BitmapDrawable
, and GifDrawable
) and ignores unknown types.
This will override previous calls to dontTransform()
.
transformation
- Any Transformation
for Bitmap
s.transform(Transformation)
,
transform(Class, Transformation)
@NonNull @CheckResult public <Y> T optionalTransform(@NonNull java.lang.Class<Y> resourceClass, @NonNull Transformation<Y> transformation)
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()
.
resourceClass
- The type of resource to transform.transformation
- The Transformation
to apply.@NonNull @CheckResult public <Y> T transform(@NonNull java.lang.Class<Y> resourceClass, @NonNull Transformation<Y> transformation)
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()
.
resourceClass
- The type of resource to transform.transformation
- The Transformation
to apply.optionalTransform(Class, Transformation)
@NonNull @CheckResult public T dontTransform()
Transformations
for all resource classes and allows
unknown resource types to be transformed without throwing an exception.@NonNull @CheckResult public T dontAnimate()
To disable transitions (fades etc) use TransitionOptions.dontTransition()
@NonNull @CheckResult public T apply(@NonNull BaseRequestOptions<?> o)
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.
public boolean equals(java.lang.Object o)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
@NonNull public T lock()
Once locked, the only way to unlock is to use clone()
@NonNull public T autoClone()
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.
@NonNull protected final T selfOrThrowIfLocked()
protected final boolean isAutoCloneEnabled()
public final boolean isDiskCacheStrategySet()
public final boolean isSkipMemoryCacheSet()
@NonNull public final java.util.Map<java.lang.Class<?>,Transformation<?>> getTransformations()
public final boolean isTransformationRequired()
@NonNull public final Options getOptions()
@NonNull public final java.lang.Class<?> getResourceClass()
@NonNull public final DiskCacheStrategy getDiskCacheStrategy()
@Nullable public final android.graphics.drawable.Drawable getErrorPlaceholder()
public final int getErrorId()
public final int getPlaceholderId()
@Nullable public final android.graphics.drawable.Drawable getPlaceholderDrawable()
public final int getFallbackId()
@Nullable public final android.graphics.drawable.Drawable getFallbackDrawable()
@Nullable public final android.content.res.Resources.Theme getTheme()
public final boolean isMemoryCacheable()
@NonNull public final Key getSignature()
public final boolean isPrioritySet()
@NonNull public final Priority getPriority()
public final int getOverrideWidth()
public final boolean isValidOverride()
public final int getOverrideHeight()
public final float getSizeMultiplier()
public final boolean getUseUnlimitedSourceGeneratorsPool()
public final boolean getUseAnimationPool()
public final boolean getOnlyRetrieveFromCache()