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. |
| 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 available ResourceDecoders
allowing it to be used if all earlier and default ResourceDecoders for the given types
fail (or if none are present). |
<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
ModelLoaders for the given model and data classes. |
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 available ResourceDecoders
so that it is attempted before all later and default ResourceDecoders for the given
types. |
<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
ModelLoaders for the given model and data classes. |
<Data> Registry |
register(Class<Data> dataClass,
Encoder<Data> encoder)
Registers the given
Encoder for the given data class (InputStream, FileDescriptor etc). |
<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)
|
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<Model,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. |
public <Data> Registry register(Class<Data> dataClass, Encoder<Data> encoder)
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. As a result, it's not currently possible
to replace Glide's default Encoders.
public <Data,TResource> Registry append(Class<Data> dataClass, Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)
ResourceDecoder onto the list of available ResourceDecoders
allowing it to be used if all earlier and default ResourceDecoders for the given types
fail (or if none are present).
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.prepend(Class, Class, ResourceDecoder)public <Data,TResource> Registry prepend(Class<Data> dataClass, Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)
ResourceDecoder into the list of 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.append(Class, Class, ResourceDecoder)public <TResource> Registry register(Class<TResource> resourceClass, ResourceEncoder<TResource> encoder)
ResourceEncoder for the given resource class
(Bitmap, GifDrawable
etc).
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. As a result, it's not currently
possible to replace Glide's default ResourceEncoders.
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
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)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
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)public <Model,Data> Registry replace(Class<Model> modelClass, Class<Data> dataClass, ModelLoaderFactory<Model,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)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()