-
public final class ImageBuilderA builder class for setting default structural classes for ImageModule to use.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description public final classImageBuilder.WaitForFramesAfterTrimMemorySee setWaitForFramesAfterTrimMemory.
public final classImageBuilder.LogRequestOriginsSee setLogRequestOrigins.
-
Field Summary
Fields Modifier and Type Field Description private final Map<Class<out Object>, TransitionOptions<out Object, out Object>>defaultTransitionOptionsprivate BitmapPoolbitmapPoolprivate ArrayPoolarrayPoolprivate MemoryCachememoryCacheprivate ImageExecutorsourceExecutorprivate ImageExecutordiskCacheExecutorprivate MemorySizeCalculatormemorySizeCalculatorprivate ConnectivityMonitorFactoryconnectivityMonitorFactoryprivate intlogLevelprivate ImageExecutoranimationExecutorprivate booleanisActiveResourceRetentionAllowed
-
Method Summary
Modifier and Type Method Description <T> ImageBuildersetDefaultTransitionOptions(@NonNull() Class<T> clazz, @Nullable() TransitionOptions<out Object, T> options)Sets the default TransitionOptions to use when starting a request that will load aresource with the given Class. ImageBuildersetBitmapPool(@Nullable() BitmapPool bitmapPool)Sets the com.mobwith.imgmodule.load.engine.bitmap_recycle.BitmapPool implementation to useto store and retrieve reused Bitmaps. ImageBuildersetArrayPool(@Nullable() ArrayPool arrayPool)Sets the ArrayPool implementation to allow variable sized arrays to be stored andretrieved as needed. ImageBuildersetMemoryCache(@Nullable() MemoryCache memoryCache)Sets the com.mobwith.imgmodule.load.engine.cache.MemoryCache implementation to store com.mobwith.imgmodule.load.engine.Resources that are not currently in use. ImageBuildersetSourceExecutor(@Nullable() ImageExecutor service)Sets the ImageExecutor to use when retrieving s that are not already in the cache. ImageBuildersetDiskCacheExecutor(@Nullable() ImageExecutor service)Sets the ImageExecutor to use when retrieving s that are currently in ImageModule disk caches. ImageBuildersetMemorySizeCalculator(@NonNull() MemorySizeCalculator.Builder builder)Sets the MemorySizeCalculator to use to calculate maximum sizes for default MemoryCaches and/or default BitmapPools. ImageBuildersetConnectivityMonitorFactory(@Nullable() ConnectivityMonitorFactory factory)Sets the com.mobwith.imgmodule.manager.ConnectivityMonitorFactory to use to notify of connectivity events. ImageBuildersetLogLevel(int logLevel)Sets a log level constant from those in Log to indicate the desired log verbosity. ImageBuildersetAnimationExecutor(@Nullable() ImageExecutor service)Sets the ImageExecutor to use when loading frames of animated images and particularlyof com.mobwith.imgmodule.load.resource.gif.GifDrawables. ImageBuildersetIsActiveResourceRetentionAllowed(boolean isActiveResourceRetentionAllowed)If set to {@code true}, allows ImageModule to re-capture resources that are loaded into s which are subsequently de-referenced and garbagecollected without being cleared.ImageBuildersetDiskCache(@Nullable() DiskCache.Factory diskCacheFactory)Sets the com.mobwith.imgmodule.load.engine.cache.DiskCache.Factory implementation to useto construct the com.mobwith.imgmodule.load.engine.cache.DiskCache to use to store data on disk. ImageBuildersetResizeExecutor(@Nullable() ImageExecutor service)Sets the ImageExecutor to use when retrieving s that are not already in the cache. ImageBuildersetDefaultRequestOptions(@Nullable() RequestOptions requestOptions)Sets the default RequestOptions to use for all loads across the app. ImageBuildersetDefaultRequestOptions(@NonNull() ImageModule.RequestOptionsFactory factory)Sets a factory for the default RequestOptions to use for all loads across the app andreturns this {@code ImageModuleBuilder}.ImageBuilderaddGlobalRequestListener(@NonNull() RequestListener<Object> listener)Adds a global RequestListener that will be added to every request started with ImageModule. ImageBuildersetLogRequestOrigins(boolean isEnabled)Set to {@code true}to make ImageModule populate for failed requests.ImageBuildersetImageDecoderEnabledForBitmaps(boolean isEnabled)Set to {@code true}to make ImageModule use android.graphics.ImageDecoder when decoding Bitmaps on Android P and higher.-
-
Method Detail
-
setDefaultTransitionOptions
@NonNull() <T> ImageBuilder setDefaultTransitionOptions(@NonNull() Class<T> clazz, @Nullable() TransitionOptions<out Object, T> options)
Sets the default TransitionOptions to use when starting a request that will load aresource with the given Class.
It's preferable but not required for the requested resource class to match the resourceclass applied here as long as the resource class applied here is assignable from the requestedresource class. For example you can set a default transition for and that default transition will be used if yousubsequently start requests for specific android.graphics.drawable.Drawable types like com.mobwith.imgmodule.load.resource.gif.GifDrawable or . Specific types are always preferred so if youregister a default transition for both android.graphics.drawable.Drawable and and then start a request for s, the transition you registered for s will be used.
-
setBitmapPool
@NonNull() ImageBuilder setBitmapPool(@Nullable() BitmapPool bitmapPool)
Sets the com.mobwith.imgmodule.load.engine.bitmap_recycle.BitmapPool implementation to useto store and retrieve reused Bitmaps.
- Parameters:
bitmapPool- The pool to use.
-
setArrayPool
@NonNull() ImageBuilder setArrayPool(@Nullable() ArrayPool arrayPool)
Sets the ArrayPool implementation to allow variable sized arrays to be stored andretrieved as needed.
- Parameters:
arrayPool- The pool to use.
-
setMemoryCache
@NonNull() ImageBuilder setMemoryCache(@Nullable() MemoryCache memoryCache)
Sets the com.mobwith.imgmodule.load.engine.cache.MemoryCache implementation to store com.mobwith.imgmodule.load.engine.Resources that are not currently in use.
- Parameters:
memoryCache- The cache to use.
-
setSourceExecutor
@NonNull() ImageBuilder setSourceExecutor(@Nullable() ImageExecutor service)
Sets the ImageExecutor to use when retrieving s that are not already in the cache.
The thread count defaults to the number of cores available on the device, with a maximum of4.
Use the newSourceExecutor methods if you'd like to specify optionsfor the source executor.
- Parameters:
service- The ExecutorService to use.
-
setDiskCacheExecutor
@NonNull() ImageBuilder setDiskCacheExecutor(@Nullable() ImageExecutor service)
Sets the ImageExecutor to use when retrieving s that are currently in ImageModule disk caches.
Defaults to a single thread which is usually the best combination of memory usage, jank, andperformance, even on high end devices.
Use the newDiskCacheExecutor if you'd like to specify options forthe disk cache executor.
- Parameters:
service- The ImageExecutor to use.
-
setMemorySizeCalculator
@NonNull() ImageBuilder setMemorySizeCalculator(@NonNull() MemorySizeCalculator.Builder builder)
Sets the MemorySizeCalculator to use to calculate maximum sizes for default MemoryCaches and/or default BitmapPools.
- Parameters:
builder- The builder to use (will not be modified).
-
setConnectivityMonitorFactory
@NonNull() ImageBuilder setConnectivityMonitorFactory(@Nullable() ConnectivityMonitorFactory factory)
Sets the com.mobwith.imgmodule.manager.ConnectivityMonitorFactory to use to notify of connectivity events. If not set would be used.
- Parameters:
factory- The factory to use
-
setLogLevel
@NonNull() ImageBuilder setLogLevel(int logLevel)
Sets a log level constant from those in Log to indicate the desired log verbosity.
The level must be one of VERBOSE, DEBUG, INFO, , or ERROR.
VERBOSE means one or more lines will be logged per request, including timinglogs and failures. DEBUG means at most one line will be logged per successfulrequest, including timing logs, although many lines may be logged for failures includingmultiple complete stack traces. INFO means failed loads will be logged includingmultiple complete stack traces, but successful loads will not be logged at all. means only summaries of failed loads will be logged. ERROR means onlyexceptional cases will be logged.
All logs will be logged using the 'ImageModule' tag.
Many other debugging logs are available in individual classes. The log level supplied hereonly controls a small set of informative and well formatted logs. Users wishing to debugcertain aspects of the library can look for individual
TAGvariables at the topsof classes and useadb shell setprop log.tag.TAGto enable or disable any relevanttags.- Parameters:
logLevel- The log level to use from Log.
-
setAnimationExecutor
@NonNull() ImageBuilder setAnimationExecutor(@Nullable() ImageExecutor service)
Sets the ImageExecutor to use when loading frames of animated images and particularlyof com.mobwith.imgmodule.load.resource.gif.GifDrawables.
Defaults to one or two threads, depending on the number of cores available.
Use the newAnimationExecutor methods if you'd like to specifyoptions for the animation executor.
- Parameters:
service- The ImageExecutor to use.
-
setIsActiveResourceRetentionAllowed
@NonNull() ImageBuilder setIsActiveResourceRetentionAllowed(boolean isActiveResourceRetentionAllowed)
If set to
{@code true}, allows ImageModule to re-capture resources that are loaded into s which are subsequently de-referenced and garbagecollected without being cleared.Defaults to
{@code false}.ImageModule resource re-use system is permissive, which means that's acceptable for callers toload resources into com.mobwith.imgmodule.request.target.Targets and then never clear the com.mobwith.imgmodule.request.target.Target. To do so, ImageModule uses s to track resources that belong to s that haven't yet been cleared. Setting this methodto
{@code true}allows ImageModule to also maintain a hard reference to the underlying resource sothat if the com.mobwith.imgmodule.request.target.Target is garbage collected, ImageModule canreturn the underlying resource to it's memory cache so that subsequent requests will notunexpectedly re-load the resource from disk or source. As a side affect, it will take thesystem slightly longer to garbage collect the underlying resource because the weak referencehas to be cleared and processed before the hard reference is removed. As a result, setting thismethod to{@code true}may transiently increase the memory usage of an application.Leaving this method at the default
{@code false}value will allow the platform to garbagecollect resources more quickly, but will lead to unexpected memory cache misses if callers loadresources into com.mobwith.imgmodule.request.target.Targets but never clear them.If you set this method to
{@code true}you must not call recycle or mutate any Bitmaps returned by ImageModule. If this method is set to{@code false}, recycling ormutating Bitmaps is inefficient but safe as long as you do not clear the corresponding used to load the Bitmap. However, if you setthis method to{@code true}and recycle or mutate any returned Bitmaps or other mutableresources, ImageModule may recover those resources and attempt to use them later on, resulting incrashes, graphical corruption or undefined behavior.Regardless of what value this method is set to, it's always good practice to clear s when you're done with the corresponding resource.Clearing com.mobwith.imgmodule.request.target.Targets allows ImageModule to maximize resourcere-use, minimize memory overhead and minimize unexpected behavior resulting from edge cases. Ifyou use clear, calling recycle or mutating Bitmaps is not only unsafe, it's also totally unnecessary and should be avoided. In allcases, prefer clear to recycle.
-
setDiskCache
@NonNull() ImageBuilder setDiskCache(@Nullable() DiskCache.Factory diskCacheFactory)
Sets the com.mobwith.imgmodule.load.engine.cache.DiskCache.Factory implementation to useto construct the com.mobwith.imgmodule.load.engine.cache.DiskCache to use to store data on disk.
- Parameters:
diskCacheFactory- The disk cache factory to use.
-
setResizeExecutor
@Deprecated() ImageBuilder setResizeExecutor(@Nullable() ImageExecutor service)
Sets the ImageExecutor to use when retrieving s that are not already in the cache.
The thread count defaults to the number of cores available on the device, with a maximum of4.
Use the newSourceExecutor methods if you'd like to specify optionsfor the source executor.
- Parameters:
service- The ExecutorService to use.
-
setDefaultRequestOptions
@NonNull() ImageBuilder setDefaultRequestOptions(@Nullable() RequestOptions requestOptions)
Sets the default RequestOptions to use for all loads across the app.
Applying additional options with apply willoverride defaults set here.
- Parameters:
requestOptions- The options to use by default.
-
setDefaultRequestOptions
@NonNull() ImageBuilder setDefaultRequestOptions(@NonNull() ImageModule.RequestOptionsFactory factory)
Sets a factory for the default RequestOptions to use for all loads across the app andreturns this
{@code ImageModuleBuilder}.This factory will NOT be called once per load. Instead it will be called a handfulof times and memoized. It's not safe to assume that this factory will be called again for everynew load.
Applying additional options with apply willoverride defaults set here.
-
addGlobalRequestListener
@NonNull() ImageBuilder addGlobalRequestListener(@NonNull() RequestListener<Object> listener)
Adds a global RequestListener that will be added to every request started with ImageModule.
Multiple RequestListeners can be added here, in RequestManager scopes or toindividual RequestBuilders. RequestListeners are called in the order they'readded. Even if an earlier RequestListener returns
{@code true}from or , it will notprevent subsequent RequestListeners from being called.Because ImageModule requests can be started for any number of individual resource types, anylistener added here has to accept any generic resource type in . If you must basethe behavior of the listener on the resource type, you will need to use
{@code instanceof}todo so. It's not safe to cast resource types without first checking with{@code instanceof}.
-
setLogRequestOrigins
ImageBuilder setLogRequestOrigins(boolean isEnabled)
Set to
{@code true}to make ImageModule populate for failed requests.The exception set by this method is not printed by ImageModuleException and can only beviewed via a RequestListener that reads the field via .
This is an experimental API that may be removed in the future.
-
setImageDecoderEnabledForBitmaps
ImageBuilder setImageDecoderEnabledForBitmaps(boolean isEnabled)
Set to
{@code true}to make ImageModule use android.graphics.ImageDecoder when decoding Bitmaps on Android P and higher.Calls to this method on versions of Android less than Q are ignored. Although ImageDecoderwas added in Android O a bug prevents it from scaling images with exif orientations until Q.See b/136096254.
Specifically android.graphics.ImageDecoder will be used in place of and android.graphics.BitmapFactory to decode Bitmaps. GIFs, resources, and all other types of s are not affected by this flag.
This flag is experimental and may be removed without deprecation in a future version.
When this flag is enabled, Bitmap's will not be re-used when decoding images, though theymay still be used as part of com.mobwith.imgmodule.load.Transformations because does not support Bitmap re-use.
When this flag is enabled isignored. All other com.mobwith.imgmodule.load.resource.bitmap.Downsampler flags areobeyed, although there may be subtle behavior differences because many options are subject tothe whims of android.graphics.BitmapFactory and android.graphics.ImageDecoder which may not agree.
-
-
-
-