-
public class RegistryManages component registration to extend or replace ImageModule default loading, decoding, and encoding logic.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public classRegistry.NoModelLoaderAvailableExceptionThrown when no com.mobwith.imgmodule.load.model.ModelLoader is registered for a givenmodel class.
public classRegistry.NoResultEncoderAvailableExceptionThrown when no ResourceEncoder is registered for a given resource class.
public classRegistry.NoSourceEncoderAvailableExceptionThrown when no Encoder is registered for a given data class.
public classRegistry.MissingComponentExceptionThrown when some necessary component is missing for a load.
public final classRegistry.NoImageHeaderParserExceptionThrown when no ImageHeaderParser is registered.
-
Field Summary
Fields Modifier and Type Field Description public final static StringBUCKET_GIFpublic final static StringBUCKET_BITMAPpublic final static StringBUCKET_BITMAP_DRAWABLE
-
Constructor Summary
Constructors Constructor Description Registry()
-
Method Summary
Modifier and Type Method Description <Data> Registryregister(@NonNull() Class<Data> dataClass, @NonNull() Encoder<Data> encoder)Registers the given Encoder for the given data class (InputStream, FileDescriptor etc). <Data> Registryappend(@NonNull() Class<Data> dataClass, @NonNull() Encoder<Data> encoder)Appends the given Encoder onto the list of available Encoders so that it isattempted after all earlier and default Encoders for the given data class. <Data> Registryprepend(@NonNull() Class<Data> dataClass, @NonNull() Encoder<Data> encoder)Prepends the given Encoder into the list of available Encoders so that it isattempted before all later and default Encoders for the given data class. <Data, TResource> Registryappend(@NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() ResourceDecoder<Data, TResource> decoder)Appends the given ResourceDecoder onto the list of all available s allowing it to be used if all earlier and default ResourceDecodersfor the given types fail (or there are none). <Data, TResource> Registryappend(@NonNull() String bucket, @NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() ResourceDecoder<Data, TResource> decoder)Appends the given ResourceDecoder onto the list of available ResourceDecodersin this bucket, allowing it to be used if all earlier and default ResourceDecoders forthe given types in this bucket fail (or there are none). <Data, TResource> Registryprepend(@NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() ResourceDecoder<Data, TResource> decoder)Prepends the given ResourceDecoder into the list of all available s so that it is attempted before all later and default ResourceDecodersfor the given types. <Data, TResource> Registryprepend(@NonNull() String bucket, @NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() ResourceDecoder<Data, TResource> decoder)Prepends the given ResourceDecoder into the list of available ResourceDecodersin the same bucket so that it is attempted before all later and default s for the given types in that bucket. final RegistrysetResourceDecoderBucketPriorityList(@NonNull() List<String> buckets)Overrides the default ordering of resource decoder buckets. <TResource> Registryregister(@NonNull() Class<TResource> resourceClass, @NonNull() ResourceEncoder<TResource> encoder)Appends the given ResourceEncoder into the list of available ResourceEncodersso that it is attempted after all earlier and default ResourceEncoders for the givendata type. <TResource> Registryappend(@NonNull() Class<TResource> resourceClass, @NonNull() ResourceEncoder<TResource> encoder)Appends the given ResourceEncoder into the list of available ResourceEncodersso that it is attempted after all earlier and default ResourceEncoders for the givendata type. <TResource> Registryprepend(@NonNull() Class<TResource> resourceClass, @NonNull() ResourceEncoder<TResource> encoder)Prepends the given ResourceEncoder into the list of available ResourceEncodersso that it is attempted before all later and default ResourceEncoders for the givendata type. Registryregister(@NonNull() DataRewinder.Factory<out Object> factory)Registers a new com.mobwith.imgmodule.load.data.DataRewinder.Factory to handle anon-default data type that can be rewind to allow for efficient reads of file headers. <TResource, Transcode> Registryregister(@NonNull() Class<TResource> resourceClass, @NonNull() Class<Transcode> transcodeClass, @NonNull() ResourceTranscoder<TResource, Transcode> transcoder)Registers the given ResourceTranscoder to convert from the given resource Class to the given transcode Class. Registryregister(@NonNull() ImageHeaderParser parser)Registers a new ImageHeaderParser that can obtain some basic metadata from an imageheader (orientation, type etc). <Model, Data> Registryappend(@NonNull() Class<Model> modelClass, @NonNull() Class<Data> dataClass, @NonNull() ModelLoaderFactory<Model, Data> factory)Appends a new ModelLoaderFactory onto the end of the existing set so that theconstructed ModelLoader will be tried after all default and previously registered ModelLoaders for the given model and data classes. <Model, Data> Registryprepend(@NonNull() Class<Model> modelClass, @NonNull() Class<Data> dataClass, @NonNull() ModelLoaderFactory<Model, Data> factory)Prepends a new ModelLoaderFactory onto the beginning of the existing set so that theconstructed ModelLoader will be tried before all default and previously registered ModelLoaders for the given model and data classes. <Model, Data> Registryreplace(@NonNull() Class<Model> modelClass, @NonNull() Class<Data> dataClass, @NonNull() ModelLoaderFactory<out Model, out Data> factory)Removes all default and previously registered ModelLoaderFactorys for the given dataand model class and replaces all of them with the single ModelLoader provided. <Data, TResource, Transcode> LoadPath<Data, TResource, Transcode>getLoadPath(@NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() Class<Transcode> transcodeClass)<Model, TResource, Transcode> List<Class<out Object>>getRegisteredResourceClasses(@NonNull() Class<Model> modelClass, @NonNull() Class<TResource> resourceClass, @NonNull() Class<Transcode> transcodeClass)booleanisResourceEncoderAvailable(@NonNull() Resource<out Object> resource)<X> ResourceEncoder<X>getResultEncoder(@NonNull() Resource<X> resource)<X> Encoder<X>getSourceEncoder(@NonNull() X data)<X> DataRewinder<X>getRewinder(@NonNull() X data)<Model> List<ModelLoader<Model, out Object>>getModelLoaders(@NonNull() Model model)List<ImageHeaderParser>getImageHeaderParsers()-
-
Method Detail
-
register
@NonNull()@Deprecated() <Data> Registry register(@NonNull() Class<Data> dataClass, @NonNull() Encoder<Data> encoder)
Registers the given Encoder for the given data class (InputStream, FileDescriptor etc).
The Encoder will be used both for the exact data class and any subtypes. Forexample, registering an Encoder for java.io.InputStream will result in the Encoder being used for , java.io.FileInputStream and any other subclass.
If multiple Encoders are registered for the same type or super type, the that is registered first will be used.
-
append
@NonNull() <Data> Registry append(@NonNull() Class<Data> dataClass, @NonNull() Encoder<Data> encoder)
Appends the given Encoder onto the list of available Encoders so that it isattempted 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. Forexample, registering an Encoder for java.io.InputStream will result in the Encoder being used for , java.io.FileInputStream and any other subclass.
If multiple Encoders are registered for the same type or super type, the that is registered first will be used.
-
prepend
@NonNull() <Data> Registry prepend(@NonNull() Class<Data> dataClass, @NonNull() Encoder<Data> encoder)
Prepends the given Encoder into the list of available Encoders so that it isattempted before all later and default Encoders for the given data class.
This method allows you to replace the default Encoder because it ensures theregistered Encoder will run first. If multiple Encoders are registered for thesame type or super type, the Encoder that is registered first will be used.
-
append
@NonNull() <Data, TResource> Registry append(@NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() ResourceDecoder<Data, TResource> decoder)
Appends the given ResourceDecoder onto the list of all available s allowing it to be used if all earlier and default ResourceDecodersfor the given types fail (or there are none).
If you're attempting to replace an existing ResourceDecoder or would like to ensurethat your ResourceDecoder gets the chance to run before an existing , use prepend. This method is best fornew types of resources and data or as a way to add an additional fallback decoder for anexisting type of data.
- Parameters:
dataClass- The data that will be decoded from (java.io.InputStream, etc).resourceClass- The resource that will be decoded to (android.graphics.Bitmap,com.mobwith.imgmodule.load.resource.gif.GifDrawable etc).decoder- The ResourceDecoder to register.
-
append
@NonNull() <Data, TResource> Registry append(@NonNull() String bucket, @NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() ResourceDecoder<Data, TResource> decoder)
Appends the given ResourceDecoder onto the list of available ResourceDecodersin this bucket, allowing it to be used if all earlier and default ResourceDecoders forthe given types in this bucket fail (or there are none).
If you're attempting to replace an existing ResourceDecoder or would like to ensurethat your ResourceDecoder gets the chance to run before an existing , use prepend. This method is best fornew types of resources and data or as a way to add an additional fallback decoder for anexisting type of data.
- Parameters:
bucket- The bucket identifier to add this decoder to.dataClass- The data that will be decoded from (java.io.InputStream, etc).resourceClass- The resource that will be decoded to (android.graphics.Bitmap,com.mobwith.imgmodule.load.resource.gif.GifDrawable etc).decoder- The ResourceDecoder to register.
-
prepend
@NonNull() <Data, TResource> Registry prepend(@NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() ResourceDecoder<Data, TResource> decoder)
Prepends the given ResourceDecoder into the list of all available s so that it is attempted before all later and default ResourceDecodersfor the given types.
This method allows you to replace the default ResourceDecoder because it ensures theregistered ResourceDecoder will run first. You can use the to fall back to the default ResourceDecodersif you only want to change the default functionality for certain types of data.
- Parameters:
dataClass- The data that will be decoded from (java.io.InputStream, etc).resourceClass- The resource that will be decoded to (android.graphics.Bitmap,com.mobwith.imgmodule.load.resource.gif.GifDrawable etc).decoder- The ResourceDecoder to register.
-
prepend
@NonNull() <Data, TResource> Registry prepend(@NonNull() String bucket, @NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() ResourceDecoder<Data, TResource> decoder)
Prepends the given ResourceDecoder into the list of available ResourceDecodersin the same bucket so that it is attempted before all later and default s for the given types in that bucket.
This method allows you to replace the default ResourceDecoder for this bucketbecause it ensures the registered ResourceDecoder will run first. You can use the handles to fall back to the default s if you only want to change the default functionality for certain types ofdata.
- Parameters:
bucket- The bucket identifier to add this decoder to.dataClass- The data that will be decoded from (java.io.InputStream, etc).resourceClass- The resource that will be decoded to (android.graphics.Bitmap,com.mobwith.imgmodule.load.resource.gif.GifDrawable etc).decoder- The ResourceDecoder to register.
-
setResourceDecoderBucketPriorityList
@NonNull() final Registry setResourceDecoderBucketPriorityList(@NonNull() List<String> buckets)
Overrides the default ordering of resource decoder buckets. You may also add custom bucketswhich are identified as a unique string. ImageModule will attempt to decode using decoders in thehighest priority bucket before moving on to the next one.
The default order is [BUCKET_GIF, BUCKET_BITMAP, ].
When registering decoders, you can use these buckets to specify the ordering relative onlyto other decoders in that bucket.
- Parameters:
buckets- The list of bucket identifiers in order from highest priority to least priority.
-
register
@NonNull()@Deprecated() <TResource> Registry register(@NonNull() Class<TResource> resourceClass, @NonNull() ResourceEncoder<TResource> encoder)
Appends the given ResourceEncoder into the list of available ResourceEncodersso that it is attempted after all earlier and default ResourceEncoders for the givendata type.
The ResourceEncoder will be used both for the exact resource class and any subtypes.For example, registering an ResourceEncoder for (not recommended) will result in the being used for android.graphics.drawable.BitmapDrawable and 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.
-
append
@NonNull() <TResource> Registry append(@NonNull() Class<TResource> resourceClass, @NonNull() ResourceEncoder<TResource> encoder)
Appends the given ResourceEncoder into the list of available ResourceEncodersso that it is attempted after all earlier and default ResourceEncoders for the givendata type.
The ResourceEncoder will be used both for the exact resource class and any subtypes.For example, registering an ResourceEncoder for (not recommended) will result in the being used for android.graphics.drawable.BitmapDrawable and 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
@NonNull() <TResource> Registry prepend(@NonNull() Class<TResource> resourceClass, @NonNull() ResourceEncoder<TResource> encoder)
Prepends the given ResourceEncoder into the list of available ResourceEncodersso that it is attempted before all later and default ResourceEncoders for the givendata type.
This method allows you to replace the default ResourceEncoder because it ensures theregistered ResourceEncoder will run first. If multiple ResourceEncoders areregistered for the same type or super type, the ResourceEncoder that is registeredfirst will be used.
-
register
@NonNull() Registry register(@NonNull() DataRewinder.Factory<out Object> factory)
Registers a new com.mobwith.imgmodule.load.data.DataRewinder.Factory to handle anon-default data type that can be rewind to allow for efficient reads of file headers.
-
register
@NonNull() <TResource, Transcode> Registry register(@NonNull() Class<TResource> resourceClass, @NonNull() Class<Transcode> transcodeClass, @NonNull() ResourceTranscoder<TResource, Transcode> transcoder)
Registers the given ResourceTranscoder to convert from the given resource Class to the given transcode Class.
- Parameters:
resourceClass- The class that will be transcoded from (e.g.transcodeClass- The class that will be transcoded to (e.g.transcoder- The ResourceTranscoder to register.
-
register
@NonNull() Registry register(@NonNull() ImageHeaderParser parser)
Registers a new ImageHeaderParser that can obtain some basic metadata from an imageheader (orientation, type etc).
-
append
@NonNull() <Model, Data> Registry append(@NonNull() Class<Model> modelClass, @NonNull() Class<Data> dataClass, @NonNull() ModelLoaderFactory<Model, Data> factory)
Appends a new ModelLoaderFactory onto the end of the existing set so that theconstructed 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. This method is best for new types of models and/or data or as away to add an additional fallback loader for an existing type of model/data.
If multiple ModelLoaderFactorys are registered for the same model and/or dataclasses, the ModelLoaders they produce will be attempted in the order the s were registered. Only if all ModelLoaders fail will the entirerequest fail.
- Parameters:
modelClass- The model class (e.g.dataClass- the data class (e.g.
-
prepend
@NonNull() <Model, Data> Registry prepend(@NonNull() Class<Model> modelClass, @NonNull() Class<Data> dataClass, @NonNull() ModelLoaderFactory<Model, Data> factory)
Prepends a new ModelLoaderFactory onto the beginning of the existing set so that theconstructed 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 onlyafter the default ModelLoaders run, use append. This method is best for adding an additional case to ImageModule existingfunctionality that should run first. This method will still run ImageModule default s if the prepended ModelLoaders fail.
If multiple ModelLoaderFactorys are registered for the same model and/or dataclasses, the ModelLoaders they produce will be attempted in the order the s were registered. Only if all ModelLoaders fail will the entirerequest fail.
- Parameters:
modelClass- The model class (e.g.dataClass- the data class (e.g.
-
replace
@NonNull() <Model, Data> Registry replace(@NonNull() Class<Model> modelClass, @NonNull() Class<Data> dataClass, @NonNull() ModelLoaderFactory<out Model, out Data> factory)
Removes all default and previously registered ModelLoaderFactorys for the given dataand 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 onlyafter the default ModelLoaders run, use append. This method should be used only when you want to ensure that ImageModuledefault ModelLoaders do not run.
One good use case for this method is when you want to replace ImageModule default networkinglibrary with your OkHttp, Volley, or your own implementation. Using prepend or append may stillallow ImageModule default networking library to run in some cases. Using this method will ensurethat only your networking library will run and that the request will fail otherwise.
- Parameters:
modelClass- The model class (e.g.dataClass- the data class (e.g.
-
getLoadPath
@Nullable() <Data, TResource, Transcode> LoadPath<Data, TResource, Transcode> getLoadPath(@NonNull() Class<Data> dataClass, @NonNull() Class<TResource> resourceClass, @NonNull() Class<Transcode> transcodeClass)
-
getRegisteredResourceClasses
@NonNull() <Model, TResource, Transcode> List<Class<out Object>> getRegisteredResourceClasses(@NonNull() Class<Model> modelClass, @NonNull() Class<TResource> resourceClass, @NonNull() Class<Transcode> transcodeClass)
-
isResourceEncoderAvailable
boolean isResourceEncoderAvailable(@NonNull() Resource<out Object> resource)
-
getResultEncoder
@NonNull() <X> ResourceEncoder<X> getResultEncoder(@NonNull() Resource<X> resource)
-
getSourceEncoder
@NonNull() <X> Encoder<X> getSourceEncoder(@NonNull() X data)
-
getRewinder
@NonNull() <X> DataRewinder<X> getRewinder(@NonNull() X data)
-
getModelLoaders
@NonNull() <Model> List<ModelLoader<Model, out Object>> getModelLoaders(@NonNull() Model model)
-
getImageHeaderParsers
@NonNull() List<ImageHeaderParser> getImageHeaderParsers()
-
-
-
-