public class Registry extends 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 String |
BUCKET_BITMAP |
static String |
BUCKET_BITMAP_DRAWABLE |
static String |
BUCKET_GIF |
Constructor and Description |
---|
Registry() |
Modifier and Type | Method and Description |
---|---|
<Data,TResource> |
append(Class<Data> dataClass,
Class<TResource> resourceClass,
ResourceDecoder<Data,TResource> decoder)
Appends the given
ResourceDecoder onto the list of all available
ResourceDecoder s allowing it to be used if all earlier and default
ResourceDecoder s for the given types fail (or there are none). |
<Data> Registry |
append(Class<Data> dataClass,
Encoder<Data> encoder)
|
<Model,Data> |
append(Class<Model> modelClass,
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
ModelLoader s for the given model and data classes. |
<TResource> |
append(Class<TResource> resourceClass,
ResourceEncoder<TResource> encoder)
Appends the given
ResourceEncoder into the list of available ResourceEncoder s
so that it is attempted after all earlier and default ResourceEncoder s for the given
data type. |
<Data,TResource> |
append(String bucket,
Class<Data> dataClass,
Class<TResource> resourceClass,
ResourceDecoder<Data,TResource> decoder)
Appends the given
ResourceDecoder onto the list of available ResourceDecoder s
in this bucket, allowing it to be used if all earlier and default ResourceDecoder s for
the given types in this bucket fail (or there are none). |
List<ImageHeaderParser> |
getImageHeaderParsers() |
<Data,TResource,Transcode> |
getLoadPath(Class<Data> dataClass,
Class<TResource> resourceClass,
Class<Transcode> transcodeClass) |
<Model> List<ModelLoader<Model,?>> |
getModelLoaders(Model model) |
<Model,TResource,Transcode> |
getRegisteredResourceClasses(Class<Model> modelClass,
Class<TResource> resourceClass,
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(Class<Data> dataClass,
Class<TResource> resourceClass,
ResourceDecoder<Data,TResource> decoder)
Prepends the given
ResourceDecoder into the list of all available
ResourceDecoder s so that it is attempted before all later and default
ResourceDecoder s for the given types. |
<Data> Registry |
prepend(Class<Data> dataClass,
Encoder<Data> encoder)
|
<Model,Data> |
prepend(Class<Model> modelClass,
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
ModelLoader s for the given model and data classes. |
<TResource> |
prepend(Class<TResource> resourceClass,
ResourceEncoder<TResource> encoder)
Prepends the given
ResourceEncoder into the list of available ResourceEncoder s
so that it is attempted before all later and default ResourceEncoder s for the given
data type. |
<Data,TResource> |
prepend(String bucket,
Class<Data> dataClass,
Class<TResource> resourceClass,
ResourceDecoder<Data,TResource> decoder)
Prepends the given
ResourceDecoder into the list of available ResourceDecoder s
in the same bucket so that it is attempted before all later and default
ResourceDecoder s for the given types in that bucket. |
<Data> Registry |
register(Class<Data> dataClass,
Encoder<Data> encoder)
Deprecated.
Use the equivalent
append(Class, Class, ModelLoaderFactory) method
instead. |
<TResource,Transcode> |
register(Class<TResource> resourceClass,
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(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(Class<Model> modelClass,
Class<Data> dataClass,
ModelLoaderFactory<? extends Model,? extends Data> factory)
Removes all default and previously registered
ModelLoaderFactory s for the given data
and model class and replaces all of them with the single ModelLoader provided. |
Registry |
setResourceDecoderBucketPriorityList(List<String> buckets)
Overrides the default ordering of resource decoder buckets.
|
public static final String BUCKET_GIF
public static final String BUCKET_BITMAP
public static final String BUCKET_BITMAP_DRAWABLE
@Deprecated public <Data> Registry register(Class<Data> dataClass, 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 Encoder
s are registered for the same type or super type, the
Encoder
that is registered first will be used.
public <Data> Registry append(Class<Data> dataClass, Encoder<Data> encoder)
Encoder
onto the list of available Encoder
s so that it is
attempted after all earlier and default Encoder
s 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 Encoder
s are registered for the same type or super type, the
Encoder
that is registered first will be used.
prepend(Class, Encoder)
public <Data> Registry prepend(Class<Data> dataClass, Encoder<Data> encoder)
Encoder
into the list of available Encoder
s
so that it is attempted before all later and default Encoder
s 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 Encoder
s are registered for
the same type or super type, the Encoder
that is registered first will be used.
append(Class, Encoder)
public <Data,TResource> Registry append(Class<Data> dataClass, Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)
ResourceDecoder
onto the list of all available
ResourceDecoder
s allowing it to be used if all earlier and default
ResourceDecoder
s 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)
public <Data,TResource> Registry append(String bucket, Class<Data> dataClass, Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)
ResourceDecoder
onto the list of available ResourceDecoder
s
in this bucket, allowing it to be used if all earlier and default ResourceDecoder
s 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)
public <Data,TResource> Registry prepend(Class<Data> dataClass, Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)
ResourceDecoder
into the list of all available
ResourceDecoder
s so that it is attempted before all later and default
ResourceDecoder
s 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
ResourceDecoder
s 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)
public <Data,TResource> Registry prepend(String bucket, Class<Data> dataClass, Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)
ResourceDecoder
into the list of available ResourceDecoder
s
in the same bucket so that it is attempted before all later and default
ResourceDecoder
s 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
ResourceDecoder
s 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)
public final Registry setResourceDecoderBucketPriorityList(List<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)
@Deprecated public <TResource> Registry register(Class<TResource> resourceClass, ResourceEncoder<TResource> encoder)
append(Class, ResourceEncoder)
method instead.ResourceEncoder
into the list of available ResourceEncoder
s
so that it is attempted after all earlier and default ResourceEncoder
s 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 ResourceEncoder
s are registered for the same type or super type, the
ResourceEncoder
that is registered first will be used.
public <TResource> Registry append(Class<TResource> resourceClass, ResourceEncoder<TResource> encoder)
ResourceEncoder
into the list of available ResourceEncoder
s
so that it is attempted after all earlier and default ResourceEncoder
s 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 ResourceEncoder
s are registered for the same type or super type, the
ResourceEncoder
that is registered first will be used.
prepend(Class, ResourceEncoder)
public <TResource> Registry prepend(Class<TResource> resourceClass, ResourceEncoder<TResource> encoder)
ResourceEncoder
into the list of available ResourceEncoder
s
so that it is attempted before all later and default ResourceEncoder
s 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 ResourceEncoder
s are
registered for the same type or super type, the ResourceEncoder
that is registered
first will be used.
append(Class, ResourceEncoder)
public Registry register(DataRewinder.Factory<?> factory)
DataRewinder.Factory
to handle a
non-default data type that can be rewind to allow for efficient reads of file headers.public <TResource,Transcode> Registry register(Class<TResource> resourceClass, Class<Transcode> transcodeClass, 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.public Registry register(ImageHeaderParser parser)
ImageHeaderParser
that can obtain some basic metadata from an image
header (orientation, type etc).public <Model,Data> Registry append(Class<Model> modelClass, Class<Data> dataClass, 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
ModelLoader
s 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 ModelLoaderFactory
s are registered for the same model and/or data
classes, the ModelLoader
s they produce will be attempted in the order the
ModelLoaderFactory
s were registered. Only if all ModelLoader
s 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)
public <Model,Data> Registry prepend(Class<Model> modelClass, Class<Data> dataClass, 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
ModelLoader
s 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 ModelLoader
s 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 ModelLoader
s if the prepended ModelLoader
s fail.
If multiple ModelLoaderFactory
s are registered for the same model and/or data
classes, the ModelLoader
s they produce will be attempted in the order the
ModelLoaderFactory
s were registered. Only if all ModelLoader
s 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)
public <Model,Data> Registry replace(Class<Model> modelClass, Class<Data> dataClass, ModelLoaderFactory<? extends Model,? extends Data> factory)
ModelLoaderFactory
s 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 ModelLoader
s run, use
append(Class, Class, ModelLoaderFactory)
. This method should be used only when you
want to ensure that Glide's default ModelLoader
s 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)
public <Data,TResource,Transcode> LoadPath<Data,TResource,Transcode> getLoadPath(Class<Data> dataClass, Class<TResource> resourceClass, Class<Transcode> transcodeClass)
public <Model,TResource,Transcode> List<Class<?>> getRegisteredResourceClasses(Class<Model> modelClass, Class<TResource> resourceClass, Class<Transcode> transcodeClass)
public boolean isResourceEncoderAvailable(Resource<?> resource)
public <X> ResourceEncoder<X> getResultEncoder(Resource<X> resource) throws Registry.NoResultEncoderAvailableException
public <X> Encoder<X> getSourceEncoder(X data) throws Registry.NoSourceEncoderAvailableException
public <X> DataRewinder<X> getRewinder(X data)
public <Model> List<ModelLoader<Model,?>> getModelLoaders(Model model)
public List<ImageHeaderParser> getImageHeaderParsers()