Class Registry
- java.lang.Object
-
- com.bumptech.glide.Registry
-
public class Registry extends java.lang.ObjectManages component registration to extend or replace Glide's default loading, decoding, and encoding logic.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classRegistry.MissingComponentExceptionThrown when some necessary component is missing for a load.static classRegistry.NoImageHeaderParserExceptionThrown when noImageHeaderParseris registered.static classRegistry.NoModelLoaderAvailableExceptionThrown when noModelLoaderis registered for a given model class.static classRegistry.NoResultEncoderAvailableExceptionThrown when noResourceEncoderis registered for a given resource class.static classRegistry.NoSourceEncoderAvailableExceptionThrown when noEncoderis registered for a given data class.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringBUCKET_ANIMATIONstatic java.lang.StringBUCKET_BITMAPstatic java.lang.StringBUCKET_BITMAP_DRAWABLEstatic java.lang.StringBUCKET_GIFDeprecated.Identical toBUCKET_ANIMATION, just with a more confusing name.
-
Constructor Summary
Constructors Constructor Description Registry()
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description <Data> Registryappend(java.lang.Class<Data> dataClass, Encoder<Data> encoder)<Data,TResource>
Registryappend(java.lang.Class<Data> dataClass, java.lang.Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)Appends the givenResourceDecoderonto the list of all availableResourceDecoders allowing it to be used if all earlier and defaultResourceDecoders for the given types fail (or there are none).<Model,Data>
Registryappend(java.lang.Class<Model> modelClass, java.lang.Class<Data> dataClass, ModelLoaderFactory<Model,Data> factory)Appends a newModelLoaderFactoryonto the end of the existing set so that the constructedModelLoaderwill be tried after all default and previously registeredModelLoaders for the given model and data classes.<TResource>
Registryappend(java.lang.Class<TResource> resourceClass, ResourceEncoder<TResource> encoder)Appends the givenResourceEncoderinto the list of availableResourceEncoders so that it is attempted after all earlier and defaultResourceEncoders for the given data type.<Data,TResource>
Registryappend(java.lang.String bucket, java.lang.Class<Data> dataClass, java.lang.Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)Appends the givenResourceDecoderonto the list of availableResourceDecoders in this bucket, allowing it to be used if all earlier and defaultResourceDecoders for the given types in this bucket fail (or there are none).java.util.List<ImageHeaderParser>getImageHeaderParsers()<Data,TResource,Transcode>
LoadPath<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>
java.util.List<java.lang.Class<?>>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)booleanisResourceEncoderAvailable(Resource<?> resource)<Data> Registryprepend(java.lang.Class<Data> dataClass, Encoder<Data> encoder)<Data,TResource>
Registryprepend(java.lang.Class<Data> dataClass, java.lang.Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)Prepends the givenResourceDecoderinto the list of all availableResourceDecoders so that it is attempted before all later and defaultResourceDecoders for the given types.<Model,Data>
Registryprepend(java.lang.Class<Model> modelClass, java.lang.Class<Data> dataClass, ModelLoaderFactory<Model,Data> factory)Prepends a newModelLoaderFactoryonto the beginning of the existing set so that the constructedModelLoaderwill be tried before all default and previously registeredModelLoaders for the given model and data classes.<TResource>
Registryprepend(java.lang.Class<TResource> resourceClass, ResourceEncoder<TResource> encoder)Prepends the givenResourceEncoderinto the list of availableResourceEncoders so that it is attempted before all later and defaultResourceEncoders for the given data type.<Data,TResource>
Registryprepend(java.lang.String bucket, java.lang.Class<Data> dataClass, java.lang.Class<TResource> resourceClass, ResourceDecoder<Data,TResource> decoder)Prepends the givenResourceDecoderinto the list of availableResourceDecoders in the same bucket so that it is attempted before all later and defaultResourceDecoders for the given types in that bucket.Registryregister(DataRewinder.Factory<?> factory)Registers a newDataRewinder.Factoryto handle a non-default data type that can be rewind to allow for efficient reads of file headers.Registryregister(ImageHeaderParser parser)Registers a newImageHeaderParserthat can obtain some basic metadata from an image header (orientation, type etc).<Data> Registryregister(java.lang.Class<Data> dataClass, Encoder<Data> encoder)Deprecated.Use the equivalentappend(Class, Class, ModelLoaderFactory)method instead.<TResource>
Registryregister(java.lang.Class<TResource> resourceClass, ResourceEncoder<TResource> encoder)Deprecated.Use the equivalentappend(Class, ResourceEncoder)method instead.<TResource,Transcode>
Registryregister(java.lang.Class<TResource> resourceClass, java.lang.Class<Transcode> transcodeClass, ResourceTranscoder<TResource,Transcode> transcoder)Registers the givenResourceTranscoderto convert from the given resourceClassto the given transcodeClass.<Model,Data>
Registryreplace(java.lang.Class<Model> modelClass, java.lang.Class<Data> dataClass, ModelLoaderFactory<? extends Model,? extends Data> factory)Removes all default and previously registeredModelLoaderFactorys for the given data and model class and replaces all of them with the singleModelLoaderprovided.RegistrysetResourceDecoderBucketPriorityList(java.util.List<java.lang.String> buckets)Overrides the default ordering of resource decoder buckets.
-
-
-
Field Detail
-
BUCKET_ANIMATION
public static final java.lang.String BUCKET_ANIMATION
- See Also:
- Constant Field Values
-
BUCKET_GIF
@Deprecated public static final java.lang.String BUCKET_GIF
Deprecated.Identical toBUCKET_ANIMATION, just with a more confusing name. This bucket can be used for all animation types (including webp).- See Also:
- Constant Field Values
-
BUCKET_BITMAP
public static final java.lang.String BUCKET_BITMAP
- See Also:
- Constant Field Values
-
BUCKET_BITMAP_DRAWABLE
public static final java.lang.String BUCKET_BITMAP_DRAWABLE
- See Also:
- Constant Field Values
-
-
Method Detail
-
register
@NonNull @Deprecated public <Data> Registry register(@NonNull java.lang.Class<Data> dataClass, @NonNull Encoder<Data> encoder)
Deprecated.Use the equivalentappend(Class, Class, ModelLoaderFactory)method instead.Registers the givenEncoderfor the given data class (InputStream, FileDescriptor etc).The
Encoderwill be used both for the exact data class and any subtypes. For example, registering anEncoderforInputStreamwill result in theEncoderbeing used forAssetFileDescriptor.AutoCloseInputStream,FileInputStreamand any other subclass.If multiple
Encoders are registered for the same type or super type, theEncoderthat is registered first will be used.
-
append
@NonNull public <Data> Registry append(@NonNull java.lang.Class<Data> dataClass, @NonNull Encoder<Data> encoder)
Appends the givenEncoderonto the list of availableEncoders so that it is attempted after all earlier and defaultEncoders for the given data class.The
Encoderwill be used both for the exact data class and any subtypes. For example, registering anEncoderforInputStreamwill result in theEncoderbeing used forAssetFileDescriptor.AutoCloseInputStream,FileInputStreamand any other subclass.If multiple
Encoders are registered for the same type or super type, theEncoderthat is registered first will be used.- See Also:
prepend(Class, Encoder)
-
prepend
@NonNull public <Data> Registry prepend(@NonNull java.lang.Class<Data> dataClass, @NonNull Encoder<Data> encoder)
Prepends the givenEncoderinto the list of availableEncoders so that it is attempted before all later and defaultEncoders for the given data class.This method allows you to replace the default
Encoderbecause it ensures the registeredEncoderwill run first. If multipleEncoders are registered for the same type or super type, theEncoderthat is registered first will be used.- See Also:
append(Class, Encoder)
-
append
@NonNull public <Data,TResource> Registry append(@NonNull java.lang.Class<Data> dataClass, @NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceDecoder<Data,TResource> decoder)
Appends the givenResourceDecoderonto the list of all availableResourceDecoders allowing it to be used if all earlier and defaultResourceDecoders for the given types fail (or there are none).If you're attempting to replace an existing
ResourceDecoderor would like to ensure that yourResourceDecodergets the chance to run before an existingResourceDecoder, useprepend(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.- Parameters:
dataClass- The data that will be decoded from (InputStream,FileDescriptoretc).resourceClass- The resource that will be decoded to (Bitmap,GifDrawableetc).decoder- TheResourceDecoderto register.- See Also:
append(String, Class, Class, ResourceDecoder),prepend(Class, Class, ResourceDecoder)
-
append
@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)
Appends the givenResourceDecoderonto the list of availableResourceDecoders in this bucket, allowing it to be used if all earlier and defaultResourceDecoders for the given types in this bucket fail (or there are none).If you're attempting to replace an existing
ResourceDecoderor would like to ensure that yourResourceDecodergets the chance to run before an existingResourceDecoder, useprepend(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.- Parameters:
bucket- The bucket identifier to add this decoder to.dataClass- The data that will be decoded from (InputStream,FileDescriptoretc).resourceClass- The resource that will be decoded to (Bitmap,GifDrawableetc).decoder- TheResourceDecoderto register.- See Also:
prepend(String, Class, Class, ResourceDecoder),setResourceDecoderBucketPriorityList(List)
-
prepend
@NonNull public <Data,TResource> Registry prepend(@NonNull java.lang.Class<Data> dataClass, @NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceDecoder<Data,TResource> decoder)
Prepends the givenResourceDecoderinto the list of all availableResourceDecoders so that it is attempted before all later and defaultResourceDecoders for the given types.This method allows you to replace the default
ResourceDecoderbecause it ensures the registeredResourceDecoderwill run first. You can use theResourceDecoder.handles(Object, Options)to fall back to the defaultResourceDecoders if you only want to change the default functionality for certain types of data.- Parameters:
dataClass- The data that will be decoded from (InputStream,FileDescriptoretc).resourceClass- The resource that will be decoded to (Bitmap,GifDrawableetc).decoder- TheResourceDecoderto register.- See Also:
prepend(String, Class, Class, ResourceDecoder),append(Class, Class, ResourceDecoder)
-
prepend
@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)
Prepends the givenResourceDecoderinto the list of availableResourceDecoders in the same bucket so that it is attempted before all later and defaultResourceDecoders for the given types in that bucket.This method allows you to replace the default
ResourceDecoderfor this bucket because it ensures the registeredResourceDecoderwill run first. You can use theResourceDecoder.handles(Object, Options)to fall back to the defaultResourceDecoders if you only want to change the default functionality for certain types of data.- Parameters:
bucket- The bucket identifier to add this decoder to.dataClass- The data that will be decoded from (InputStream,FileDescriptoretc).resourceClass- The resource that will be decoded to (Bitmap,GifDrawableetc).decoder- TheResourceDecoderto register.- See Also:
append(String, Class, Class, ResourceDecoder),setResourceDecoderBucketPriorityList(List)
-
setResourceDecoderBucketPriorityList
@NonNull public final Registry setResourceDecoderBucketPriorityList(@NonNull java.util.List<java.lang.String> buckets)
Overrides the default ordering of resource decoder buckets. You may also add custom buckets which are identified as a unique string. Glide will attempt to decode using decoders in the highest priority bucket before moving on to the next one.The default order is [
BUCKET_ANIMATION,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.
- Parameters:
buckets- The list of bucket identifiers in order from highest priority to least priority.- See Also:
append(String, Class, Class, ResourceDecoder),prepend(String, Class, Class, ResourceDecoder)
-
register
@NonNull @Deprecated public <TResource> Registry register(@NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceEncoder<TResource> encoder)
Deprecated.Use the equivalentappend(Class, ResourceEncoder)method instead.Appends the givenResourceEncoderinto the list of availableResourceEncoders so that it is attempted after all earlier and defaultResourceEncoders for the given data type.The
ResourceEncoderwill be used both for the exact resource class and any subtypes. For example, registering anResourceEncoderforDrawable(not recommended) will result in theResourceEncoderbeing used forBitmapDrawableandGifDrawableand any other subclass.If multiple
ResourceEncoders are registered for the same type or super type, theResourceEncoderthat is registered first will be used.
-
append
@NonNull public <TResource> Registry append(@NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceEncoder<TResource> encoder)
Appends the givenResourceEncoderinto the list of availableResourceEncoders so that it is attempted after all earlier and defaultResourceEncoders for the given data type.The
ResourceEncoderwill be used both for the exact resource class and any subtypes. For example, registering anResourceEncoderforDrawable(not recommended) will result in theResourceEncoderbeing used forBitmapDrawableandGifDrawableand any other subclass.If multiple
ResourceEncoders are registered for the same type or super type, theResourceEncoderthat is registered first will be used.- See Also:
prepend(Class, ResourceEncoder)
-
prepend
@NonNull public <TResource> Registry prepend(@NonNull java.lang.Class<TResource> resourceClass, @NonNull ResourceEncoder<TResource> encoder)
Prepends the givenResourceEncoderinto the list of availableResourceEncoders so that it is attempted before all later and defaultResourceEncoders for the given data type.This method allows you to replace the default
ResourceEncoderbecause it ensures the registeredResourceEncoderwill run first. If multipleResourceEncoders are registered for the same type or super type, theResourceEncoderthat is registered first will be used.- See Also:
append(Class, ResourceEncoder)
-
register
@NonNull public Registry register(@NonNull DataRewinder.Factory<?> factory)
Registers a newDataRewinder.Factoryto handle a non-default data type that can be rewind to allow for efficient reads of file headers.
-
register
@NonNull public <TResource,Transcode> Registry register(@NonNull java.lang.Class<TResource> resourceClass, @NonNull java.lang.Class<Transcode> transcodeClass, @NonNull ResourceTranscoder<TResource,Transcode> transcoder)
Registers the givenResourceTranscoderto convert from the given resourceClassto the given transcodeClass.- Parameters:
resourceClass- The class that will be transcoded from (e.g.Bitmap).transcodeClass- The class that will be transcoded to (e.g.BitmapDrawable).transcoder- TheResourceTranscoderto register.
-
register
@NonNull public Registry register(@NonNull ImageHeaderParser parser)
Registers a newImageHeaderParserthat can obtain some basic metadata from an image header (orientation, type etc).
-
append
@NonNull public <Model,Data> Registry append(@NonNull java.lang.Class<Model> modelClass, @NonNull java.lang.Class<Data> dataClass, @NonNull ModelLoaderFactory<Model,Data> factory)
Appends a newModelLoaderFactoryonto the end of the existing set so that the constructedModelLoaderwill be tried after all default and previously registeredModelLoaders for the given model and data classes.If you're attempting to replace an existing
ModelLoader, useprepend(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, theModelLoaders they produce will be attempted in the order theModelLoaderFactorys were registered. Only if allModelLoaders fail will the entire request fail.- Parameters:
modelClass- The model class (e.g. URL, file path).dataClass- the data class (e.g.InputStream,FileDescriptor).- See Also:
prepend(Class, Class, ModelLoaderFactory),replace(Class, Class, ModelLoaderFactory)
-
prepend
@NonNull public <Model,Data> Registry prepend(@NonNull java.lang.Class<Model> modelClass, @NonNull java.lang.Class<Data> dataClass, @NonNull ModelLoaderFactory<Model,Data> factory)
Prepends a newModelLoaderFactoryonto the beginning of the existing set so that the constructedModelLoaderwill be tried before all default and previously registeredModelLoaders 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, useappend(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 defaultModelLoaders if the prependedModelLoaders fail.If multiple
ModelLoaderFactorys are registered for the same model and/or data classes, theModelLoaders they produce will be attempted in the order theModelLoaderFactorys were registered. Only if allModelLoaders fail will the entire request fail.- Parameters:
modelClass- The model class (e.g. URL, file path).dataClass- the data class (e.g.InputStream,FileDescriptor).- See Also:
append(Class, Class, ModelLoaderFactory),replace(Class, Class, ModelLoaderFactory)
-
replace
@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)
Removes all default and previously registeredModelLoaderFactorys for the given data and model class and replaces all of them with the singleModelLoaderprovided.If you're attempting to add additional functionality or add a backup that should run only after the default
ModelLoaders run, useappend(Class, Class, ModelLoaderFactory). This method should be used only when you want to ensure that Glide's defaultModelLoaders 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)orappend(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.- Parameters:
modelClass- The model class (e.g. URL, file path).dataClass- the data class (e.g.InputStream,FileDescriptor).- See Also:
prepend(Class, Class, ModelLoaderFactory),append(Class, Class, ModelLoaderFactory)
-
getLoadPath
@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)
-
getRegisteredResourceClasses
@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)
-
isResourceEncoderAvailable
public boolean isResourceEncoderAvailable(@NonNull Resource<?> resource)
-
getResultEncoder
@NonNull public <X> ResourceEncoder<X> getResultEncoder(@NonNull Resource<X> resource) throws Registry.NoResultEncoderAvailableException
-
getSourceEncoder
@NonNull public <X> Encoder<X> getSourceEncoder(@NonNull X data) throws Registry.NoSourceEncoderAvailableException
-
getRewinder
@NonNull public <X> DataRewinder<X> getRewinder(@NonNull X data)
-
getModelLoaders
@NonNull public <Model> java.util.List<ModelLoader<Model,?>> getModelLoaders(@NonNull Model model)
-
getImageHeaderParsers
@NonNull public java.util.List<ImageHeaderParser> getImageHeaderParsers()
-
-