public class Registry
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static class |
Registry.MissingComponentException
Thrown when some necessary component is missing for a load.
|
static class |
Registry.NoImageHeaderParserException
Thrown when no
ImageHeaderParser is registered. |
static class |
Registry.NoModelLoaderAvailableException
Thrown when no
ModelLoader is registered for a given
model class. |
static class |
Registry.NoResultEncoderAvailableException
Thrown when no
ResourceEncoder is registered for a given resource class. |
static class |
Registry.NoSourceEncoderAvailableException
Thrown when no
Encoder is registered for a given data class. |
| Modifier and Type | Field and Description |
|---|---|
static java.lang.String |
BUCKET_BITMAP |
static java.lang.String |
BUCKET_BITMAP_DRAWABLE |
static java.lang.String |
BUCKET_GIF |
| Constructor and Description |
|---|
Registry() |
| Modifier and Type | Method and Description |
|---|---|
<Data,TResource> |
append(java.lang.Class<Data> dataClass,
java.lang.Class<TResource> resourceClass,
ResourceDecoder<Data,TResource> decoder)
Appends the given
ResourceDecoder onto the list of all available ResourceDecoders allowing it to be used if all earlier and default ResourceDecoders
for the given types fail (or there are none). |
<Data> Registry |
append(java.lang.Class<Data> dataClass,
Encoder<Data> encoder)
|
<Model,Data> |
append(java.lang.Class<Model> modelClass,
java.lang.Class<Data> dataClass,
ModelLoaderFactory<Model,Data> factory)
Appends a new
ModelLoaderFactory onto the end of the existing set so that the
constructed ModelLoader will be tried after all default and previously registered
ModelLoaders for the given model and data classes. |
<TResource> |
append(java.lang.Class<TResource> resourceClass,
ResourceEncoder<TResource> encoder)
Appends the given
ResourceEncoder into the list of available ResourceEncoders
so that it is attempted after all earlier and default ResourceEncoders for the given
data type. |
<Data,TResource> |
append(java.lang.String bucket,
java.lang.Class<Data> dataClass,
java.lang.Class<TResource> resourceClass,
ResourceDecoder<Data,TResource> decoder)
Appends the given
ResourceDecoder onto the list of available ResourceDecoders
in this bucket, allowing it to be used if all earlier and default ResourceDecoders for
the given types in this bucket fail (or there are none). |
java.util.List<ImageHeaderParser> |
getImageHeaderParsers() |
<Data,TResource,Transcode> |
getLoadPath(java.lang.Class<Data> dataClass,
java.lang.Class<TResource> resourceClass,
java.lang.Class<Transcode> transcodeClass) |
<Model> java.util.List<ModelLoader<Model,?>> |
getModelLoaders(Model model) |
<Model,TResource,Transcode> |
getRegisteredResourceClasses(java.lang.Class<Model> modelClass,
java.lang.Class<TResource> resourceClass,
java.lang.Class<Transcode> transcodeClass) |
<X> ResourceEncoder<X> |
getResultEncoder(Resource<X> resource) |
<X> DataRewinder<X> |
getRewinder(X data) |
<X> Encoder<X> |
getSourceEncoder(X data) |
boolean |
isResourceEncoderAvailable(Resource<?> resource) |
<Data,TResource> |
prepend(java.lang.Class<Data> dataClass,
java.lang.Class<TResource> resourceClass,
ResourceDecoder<Data,TResource> decoder)
Prepends the given
ResourceDecoder into the list of all available ResourceDecoders so that it is attempted before all later and default ResourceDecoders
for the given types. |
<Data> Registry |
prepend(java.lang.Class<Data> dataClass,
Encoder<Data> encoder)
|
<Model,Data> |
prepend(java.lang.Class<Model> modelClass,
java.lang.Class<Data> dataClass,
ModelLoaderFactory<Model,Data> factory)
Prepends a new
ModelLoaderFactory onto the beginning of the existing set so that the
constructed ModelLoader will be tried before all default and previously registered
ModelLoaders for the given model and data classes. |
<TResource> |
prepend(java.lang.Class<TResource> resourceClass,
ResourceEncoder<TResource> encoder)
Prepends the given
ResourceEncoder into the list of available ResourceEncoders
so that it is attempted before all later and default ResourceEncoders for the given
data type. |
<Data,TResource> |
prepend(java.lang.String bucket,
java.lang.Class<Data> dataClass,
java.lang.Class<TResource> resourceClass,
ResourceDecoder<Data,TResource> decoder)
Prepends the given
ResourceDecoder into the list of available ResourceDecoders
in the same bucket so that it is attempted before all later and default ResourceDecoders for the given types in that bucket. |
<Data> Registry |
register(java.lang.Class<Data> dataClass,
Encoder<Data> encoder)
Deprecated.
Use the equivalent
append(Class, Class, ModelLoaderFactory) method
instead. |
<TResource,Transcode> |
register(java.lang.Class<TResource> resourceClass,
java.lang.Class<Transcode> transcodeClass,
ResourceTranscoder<TResource,Transcode> transcoder)
Registers the given
ResourceTranscoder to convert from the given resource Class
to the given transcode Class. |
<TResource> |
register(java.lang.Class<TResource> resourceClass,
ResourceEncoder<TResource> encoder)
Deprecated.
Use the equivalent
append(Class, ResourceEncoder) method instead. |
Registry |
register(DataRewinder.Factory<?> factory)
Registers a new
DataRewinder.Factory to handle a
non-default data type that can be rewind to allow for efficient reads of file headers. |
Registry |
register(ImageHeaderParser parser)
Registers a new
ImageHeaderParser that can obtain some basic metadata from an image
header (orientation, type etc). |
<Model,Data> |
replace(java.lang.Class<Model> modelClass,
java.lang.Class<Data> dataClass,
ModelLoaderFactory<? extends Model,? extends Data> factory)
Removes all default and previously registered
ModelLoaderFactorys for the given data
and model class and replaces all of them with the single ModelLoader provided. |
Registry |
setResourceDecoderBucketPriorityList(java.util.List<java.lang.String> buckets)
Overrides the default ordering of resource decoder buckets.
|
public static final java.lang.String BUCKET_GIF
public static final java.lang.String BUCKET_BITMAP
public static final java.lang.String BUCKET_BITMAP_DRAWABLE
@NonNull @Deprecated public <Data> Registry register(@NonNull java.lang.Class<Data> dataClass, @NonNull Encoder<Data> encoder)
append(Class, Class, ModelLoaderFactory) method
instead.Encoder for the given data class (InputStream, FileDescriptor etc).
The Encoder will be used both for the exact data class and any subtypes. For
example, registering an Encoder for InputStream will result in the
Encoder being used for AssetFileDescriptor.AutoCloseInputStream, FileInputStream
and any other subclass.
If multiple Encoders are registered for the same type or super type, the Encoder that is registered first will be used.
@NonNull public <Data> Registry append(@NonNull java.lang.Class<Data> dataClass, @NonNull Encoder<Data> encoder)
Encoder onto the list of available Encoders so that it is
attempted after all earlier and default Encoders for the given data class.
The Encoder will be used both for the exact data class and any subtypes. For
example, registering an Encoder for InputStream will result in the
Encoder being used for AssetFileDescriptor.AutoCloseInputStream, FileInputStream
and any other subclass.
If multiple Encoders are registered for the same type or super type, the Encoder that is registered first will be used.
prepend(Class, Encoder)@NonNull public <Data> Registry prepend(@NonNull java.lang.Class<Data> dataClass, @NonNull Encoder<Data> encoder)
Encoder into the list of available Encoders so that it is
attempted before all later and default Encoders for the given data class.
This method allows you to replace the default Encoder because it ensures the
registered Encoder will run first. If multiple Encoders are registered for the
same type or super type, the Encoder that is registered first will be used.
append(Class, Encoder)@NonNull public <Data,TResource> Registry append(@NonNull java.lang.Class<Data> dataClass, @NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceDecoder<Data,TResource> decoder)
ResourceDecoder onto the list of all available ResourceDecoders allowing it to be used if all earlier and default ResourceDecoders
for the given types fail (or there are none).
If you're attempting to replace an existing ResourceDecoder or would like to ensure
that your ResourceDecoder gets the chance to run before an existing ResourceDecoder, use prepend(Class, Class, ResourceDecoder). This method is best for
new types of resources and data or as a way to add an additional fallback decoder for an
existing type of data.
dataClass - The data that will be decoded from (InputStream, FileDescriptor etc).resourceClass - The resource that will be decoded to (Bitmap,
GifDrawable etc).decoder - The ResourceDecoder to register.append(String, Class, Class, ResourceDecoder),
prepend(Class, Class, ResourceDecoder)@NonNull public <Data,TResource> Registry append(@NonNull java.lang.String bucket, @NonNull java.lang.Class<Data> dataClass, @NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceDecoder<Data,TResource> decoder)
ResourceDecoder onto the list of available ResourceDecoders
in this bucket, allowing it to be used if all earlier and default ResourceDecoders for
the given types in this bucket fail (or there are none).
If you're attempting to replace an existing ResourceDecoder or would like to ensure
that your ResourceDecoder gets the chance to run before an existing ResourceDecoder, use prepend(Class, Class, ResourceDecoder). This method is best for
new types of resources and data or as a way to add an additional fallback decoder for an
existing type of data.
bucket - The bucket identifier to add this decoder to.dataClass - The data that will be decoded from (InputStream, FileDescriptor etc).resourceClass - The resource that will be decoded to (Bitmap,
GifDrawable etc).decoder - The ResourceDecoder to register.prepend(String, Class, Class, ResourceDecoder),
setResourceDecoderBucketPriorityList(List)@NonNull public <Data,TResource> Registry prepend(@NonNull java.lang.Class<Data> dataClass, @NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceDecoder<Data,TResource> decoder)
ResourceDecoder into the list of all available ResourceDecoders so that it is attempted before all later and default ResourceDecoders
for the given types.
This method allows you to replace the default ResourceDecoder because it ensures the
registered ResourceDecoder will run first. You can use the ResourceDecoder.handles(Object, Options) to fall back to the default ResourceDecoders
if you only want to change the default functionality for certain types of data.
dataClass - The data that will be decoded from (InputStream, FileDescriptor etc).resourceClass - The resource that will be decoded to (Bitmap,
GifDrawable etc).decoder - The ResourceDecoder to register.prepend(String, Class, Class, ResourceDecoder),
append(Class, Class, ResourceDecoder)@NonNull public <Data,TResource> Registry prepend(@NonNull java.lang.String bucket, @NonNull java.lang.Class<Data> dataClass, @NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceDecoder<Data,TResource> decoder)
ResourceDecoder into the list of available ResourceDecoders
in the same bucket so that it is attempted before all later and default ResourceDecoders for the given types in that bucket.
This method allows you to replace the default ResourceDecoder for this bucket
because it ensures the registered ResourceDecoder will run first. You can use the
ResourceDecoder.handles(Object, Options) to fall back to the default ResourceDecoders if you only want to change the default functionality for certain types of
data.
bucket - The bucket identifier to add this decoder to.dataClass - The data that will be decoded from (InputStream, FileDescriptor etc).resourceClass - The resource that will be decoded to (Bitmap,
GifDrawable etc).decoder - The ResourceDecoder to register.append(String, Class, Class, ResourceDecoder),
setResourceDecoderBucketPriorityList(List)@NonNull public final Registry setResourceDecoderBucketPriorityList(@NonNull java.util.List<java.lang.String> buckets)
The default order is [BUCKET_GIF, BUCKET_BITMAP, BUCKET_BITMAP_DRAWABLE].
When registering decoders, you can use these buckets to specify the ordering relative only to other decoders in that bucket.
buckets - The list of bucket identifiers in order from highest priority to least priority.append(String, Class, Class, ResourceDecoder),
prepend(String, Class, Class, ResourceDecoder)@NonNull @Deprecated public <TResource> Registry register(@NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceEncoder<TResource> encoder)
append(Class, ResourceEncoder) method instead.ResourceEncoder into the list of available ResourceEncoders
so that it is attempted after all earlier and default ResourceEncoders for the given
data type.
The ResourceEncoder will be used both for the exact resource class and any subtypes.
For example, registering an ResourceEncoder for Drawable (not recommended) will result in the ResourceEncoder being used for BitmapDrawable and GifDrawable and any other subclass.
If multiple ResourceEncoders are registered for the same type or super type, the
ResourceEncoder that is registered first will be used.
@NonNull public <TResource> Registry append(@NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceEncoder<TResource> encoder)
ResourceEncoder into the list of available ResourceEncoders
so that it is attempted after all earlier and default ResourceEncoders for the given
data type.
The ResourceEncoder will be used both for the exact resource class and any subtypes.
For example, registering an ResourceEncoder for Drawable (not recommended) will result in the ResourceEncoder being used for BitmapDrawable and GifDrawable and any other subclass.
If multiple ResourceEncoders are registered for the same type or super type, the
ResourceEncoder that is registered first will be used.
prepend(Class, ResourceEncoder)@NonNull public <TResource> Registry prepend(@NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceEncoder<TResource> encoder)
ResourceEncoder into the list of available ResourceEncoders
so that it is attempted before all later and default ResourceEncoders for the given
data type.
This method allows you to replace the default ResourceEncoder because it ensures the
registered ResourceEncoder will run first. If multiple ResourceEncoders are
registered for the same type or super type, the ResourceEncoder that is registered
first will be used.
append(Class, ResourceEncoder)@NonNull public Registry register(@NonNull DataRewinder.Factory<?> factory)
DataRewinder.Factory to handle a
non-default data type that can be rewind to allow for efficient reads of file headers.@NonNull public <TResource,Transcode> Registry register(@NonNull java.lang.Class<TResource> resourceClass, @NonNull java.lang.Class<Transcode> transcodeClass, @NonNull ResourceTranscoder<TResource,Transcode> transcoder)
ResourceTranscoder to convert from the given resource Class
to the given transcode Class.resourceClass - The class that will be transcoded from (e.g. Bitmap).transcodeClass - The class that will be transcoded to (e.g. BitmapDrawable).transcoder - The ResourceTranscoder to register.@NonNull public Registry register(@NonNull ImageHeaderParser parser)
ImageHeaderParser that can obtain some basic metadata from an image
header (orientation, type etc).@NonNull public <Model,Data> Registry append(@NonNull java.lang.Class<Model> modelClass, @NonNull java.lang.Class<Data> dataClass, @NonNull ModelLoaderFactory<Model,Data> factory)
ModelLoaderFactory onto the end of the existing set so that the
constructed ModelLoader will be tried after all default and previously registered
ModelLoaders for the given model and data classes.
If you're attempting to replace an existing ModelLoader, use prepend(Class,
Class, ModelLoaderFactory). This method is best for new types of models and/or data or as a
way to add an additional fallback loader for an existing type of model/data.
If multiple ModelLoaderFactorys are registered for the same model and/or data
classes, the ModelLoaders they produce will be attempted in the order the ModelLoaderFactorys were registered. Only if all ModelLoaders fail will the entire
request fail.
modelClass - The model class (e.g. URL, file path).dataClass - the data class (e.g. InputStream, FileDescriptor).prepend(Class, Class, ModelLoaderFactory),
replace(Class, Class, ModelLoaderFactory)@NonNull public <Model,Data> Registry prepend(@NonNull java.lang.Class<Model> modelClass, @NonNull java.lang.Class<Data> dataClass, @NonNull ModelLoaderFactory<Model,Data> factory)
ModelLoaderFactory onto the beginning of the existing set so that the
constructed ModelLoader will be tried before all default and previously registered
ModelLoaders for the given model and data classes.
If you're attempting to add additional functionality or add a backup that should run only
after the default ModelLoaders run, use append(Class, Class,
ModelLoaderFactory). This method is best for adding an additional case to Glide's existing
functionality that should run first. This method will still run Glide's default ModelLoaders if the prepended ModelLoaders fail.
If multiple ModelLoaderFactorys are registered for the same model and/or data
classes, the ModelLoaders they produce will be attempted in the order the ModelLoaderFactorys were registered. Only if all ModelLoaders fail will the entire
request fail.
modelClass - The model class (e.g. URL, file path).dataClass - the data class (e.g. InputStream, FileDescriptor).append(Class, Class, ModelLoaderFactory),
replace(Class, Class, ModelLoaderFactory)@NonNull public <Model,Data> Registry replace(@NonNull java.lang.Class<Model> modelClass, @NonNull java.lang.Class<Data> dataClass, @NonNull ModelLoaderFactory<? extends Model,? extends Data> factory)
ModelLoaderFactorys for the given data
and model class and replaces all of them with the single ModelLoader provided.
If you're attempting to add additional functionality or add a backup that should run only
after the default ModelLoaders run, use append(Class, Class,
ModelLoaderFactory). This method should be used only when you want to ensure that Glide's
default ModelLoaders do not run.
One good use case for this method is when you want to replace Glide's default networking
library with your OkHttp, Volley, or your own implementation. Using prepend(Class,
Class, ModelLoaderFactory) or append(Class, Class, ModelLoaderFactory) may still
allow Glide's default networking library to run in some cases. Using this method will ensure
that only your networking library will run and that the request will fail otherwise.
modelClass - The model class (e.g. URL, file path).dataClass - the data class (e.g. InputStream, FileDescriptor).prepend(Class, Class, ModelLoaderFactory),
append(Class, Class, ModelLoaderFactory)@Nullable public <Data,TResource,Transcode> LoadPath<Data,TResource,Transcode> getLoadPath(@NonNull java.lang.Class<Data> dataClass, @NonNull java.lang.Class<TResource> resourceClass, @NonNull java.lang.Class<Transcode> transcodeClass)
@NonNull
public <Model,TResource,Transcode> java.util.List<java.lang.Class<?>> getRegisteredResourceClasses(@NonNull
java.lang.Class<Model> modelClass,
@NonNull
java.lang.Class<TResource> resourceClass,
@NonNull
java.lang.Class<Transcode> transcodeClass)
public boolean isResourceEncoderAvailable(@NonNull
Resource<?> resource)
@NonNull public <X> ResourceEncoder<X> getResultEncoder(@NonNull Resource<X> resource) throws Registry.NoResultEncoderAvailableException
@NonNull public <X> Encoder<X> getSourceEncoder(@NonNull X data) throws Registry.NoSourceEncoderAvailableException
@NonNull public <X> DataRewinder<X> getRewinder(@NonNull X data)
@NonNull public <Model> java.util.List<ModelLoader<Model,?>> getModelLoaders(@NonNull Model model)
@NonNull public java.util.List<ImageHeaderParser> getImageHeaderParsers()