Class Registry
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classThrown when some necessary component is missing for a load.static final classThrown when noImageHeaderParseris registered.static classThrown when noModelLoaderis registered for a given model class.static classThrown when noResourceEncoderis registered for a given resource class.static classThrown when noEncoderis registered for a given data class. -
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<Data> Registry<Data,TResource>
Registryappend(Class<Data> dataClass, 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(Class<Model> modelClass, 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(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(String bucket, Class<Data> dataClass, 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).<Data,TResource, Transcode>
LoadPath<Data,TResource, Transcode> getLoadPath(Class<Data> dataClass, Class<TResource> resourceClass, Class<Transcode> transcodeClass) <Model> List<ModelLoader<Model,?>> getModelLoaders(Model model) 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) booleanisResourceEncoderAvailable(Resource<?> resource) <Data> Registry<Data,TResource>
Registryprepend(Class<Data> dataClass, 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(Class<Model> modelClass, 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(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(String bucket, Class<Data> dataClass, 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.register(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(ImageHeaderParser parser) Registers a newImageHeaderParserthat can obtain some basic metadata from an image header (orientation, type etc).<Data> RegistryDeprecated.Use the equivalentappend(Class, Class, ModelLoaderFactory)method instead.<TResource>
Registryregister(Class<TResource> resourceClass, ResourceEncoder<TResource> encoder) Deprecated.Use the equivalentappend(Class, ResourceEncoder)method instead.<TResource,Transcode>
Registryregister(Class<TResource> resourceClass, Class<Transcode> transcodeClass, ResourceTranscoder<TResource, Transcode> transcoder) Registers the givenResourceTranscoderto convert from the given resourceClassto the given transcodeClass.<Model,Data>
Registryreplace(Class<Model> modelClass, 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.final RegistrysetResourceDecoderBucketPriorityList(List<String> buckets) Overrides the default ordering of resource decoder buckets.
-
Field Details
-
BUCKET_ANIMATION
- See Also:
-
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:
-
BUCKET_BITMAP
- See Also:
-
BUCKET_BITMAP_DRAWABLE
- See Also:
-
-
Constructor Details
-
Registry
public Registry()
-
-
Method Details
-
register
@NonNull @Deprecated public <Data> Registry register(@NonNull 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 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
@NonNull public <Data> Registry prepend(@NonNull 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
@NonNull public <Data,TResource> Registry append(@NonNull Class<Data> dataClass, @NonNull 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
@NonNull public <Data,TResource> Registry append(@NonNull String bucket, @NonNull Class<Data> dataClass, @NonNull 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
@NonNull public <Data,TResource> Registry prepend(@NonNull Class<Data> dataClass, @NonNull 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
@NonNull public <Data,TResource> Registry prepend(@NonNull String bucket, @NonNull Class<Data> dataClass, @NonNull 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:
-
setResourceDecoderBucketPriorityList
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:
-
register
@NonNull @Deprecated public <TResource> Registry register(@NonNull 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 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
@NonNull public <TResource> Registry prepend(@NonNull 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:
-
register
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 Class<TResource> resourceClass, @NonNull 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
Registers a newImageHeaderParserthat can obtain some basic metadata from an image header (orientation, type etc). -
append
@NonNull public <Model,Data> Registry append(@NonNull Class<Model> modelClass, @NonNull 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
@NonNull public <Model,Data> Registry prepend(@NonNull Class<Model> modelClass, @NonNull 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:
-
replace
@NonNull public <Model,Data> Registry replace(@NonNull Class<Model> modelClass, @NonNull 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:
-
getLoadPath
-
getRegisteredResourceClasses
-
isResourceEncoderAvailable
-
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
-
getModelLoaders
-
getImageHeaderParsers
-
BUCKET_ANIMATION, just with a more confusing name.