-
public final class ImageLoader.Builder
-
-
Constructor Summary
Constructors Constructor Description ImageLoader.Builder(Context context)
-
Method Summary
Modifier and Type Method Description final <ERROR CLASS>okHttpClient(OkHttpClient okHttpClient)Set the OkHttpClient used for network requests. final <ERROR CLASS>okHttpClient(Function0<OkHttpClient> initializer)Set a lazy callback to create the OkHttpClient used for network requests. final <ERROR CLASS>callFactory(Call.Factory callFactory)Set the Call.Factory used for network requests. final <ERROR CLASS>callFactory(Function0<Call.Factory> initializer)Set a lazy callback to create the Call.Factory used for network requests. final <ERROR CLASS>components(ComponentRegistry components)Set the ComponentRegistry. final <ERROR CLASS>memoryCache(MemoryCache memoryCache)Set the MemoryCache. final <ERROR CLASS>memoryCache(Function0<MemoryCache> initializer)Set a lazy callback to create the MemoryCache. final <ERROR CLASS>diskCache(DiskCache diskCache)Set the DiskCache. final <ERROR CLASS>diskCache(Function0<DiskCache> initializer)Set a lazy callback to create the DiskCache. final <ERROR CLASS>allowHardware(Boolean enable)Allow the use of Bitmap.Config.HARDWARE. final <ERROR CLASS>allowRgb565(Boolean enable)Allow automatically using Bitmap.Config.RGB_565 when an image is guaranteed to not have alpha. final <ERROR CLASS>addLastModifiedToFileCacheKey(Boolean enable)Enables adding File.lastModified to the memory cache key when loading an image from a File. final <ERROR CLASS>networkObserverEnabled(Boolean enable)Enables short circuiting network requests if the device is offline. final <ERROR CLASS>respectCacheHeaders(Boolean enable)Enables support for network cache headers. final <ERROR CLASS>bitmapFactoryMaxParallelism(Integer maxParallelism)Sets the maximum number of parallel BitmapFactory decode operations at once. final <ERROR CLASS>bitmapFactoryExifOrientationPolicy(ExifOrientationPolicy policy)Sets the policy for handling the EXIF orientation flag for images decoded by BitmapFactoryDecoder. final <ERROR CLASS>eventListener(EventListener listener)Set a single EventListener that will receive all callbacks for requests launched by this image loader. final <ERROR CLASS>eventListenerFactory(EventListener.Factory factory)Set the EventListener.Factory to create per-request EventListeners. final <ERROR CLASS>crossfade(Boolean enable)Enable a crossfade animation with duration CrossfadeDrawable.DEFAULT_DURATION milliseconds when a request completes successfully. final <ERROR CLASS>crossfade(Integer durationMillis)Enable a crossfade animation with durationMillis milliseconds when a request completes successfully. final <ERROR CLASS>transitionFactory(Transition.Factory factory)Set the default Transition.Factory for each request. final <ERROR CLASS>precision(Precision precision)Set the default precision for a request. final <ERROR CLASS>bitmapConfig(Bitmap.Config bitmapConfig)Set the preferred Bitmap.Config. final <ERROR CLASS>dispatcher(CoroutineDispatcher dispatcher)A convenience function to set fetcherDispatcher, decoderDispatcher, and transformationDispatcher in one call. final <ERROR CLASS>interceptorDispatcher(CoroutineDispatcher dispatcher)The CoroutineDispatcher that the Interceptor chain will be executed on. final <ERROR CLASS>fetcherDispatcher(CoroutineDispatcher dispatcher)The CoroutineDispatcher that Fetcher.fetch will be executed on. final <ERROR CLASS>decoderDispatcher(CoroutineDispatcher dispatcher)The CoroutineDispatcher that Decoder.decode will be executed on. final <ERROR CLASS>transformationDispatcher(CoroutineDispatcher dispatcher)The CoroutineDispatcher that Transformation.transform will be executed on. final <ERROR CLASS>placeholder(@DrawableRes() Integer drawableResId)Set the default placeholder drawable to use when a request starts. final <ERROR CLASS>placeholder(Drawable drawable)Set the default placeholder drawable to use when a request starts. final <ERROR CLASS>error(@DrawableRes() Integer drawableResId)Set the default error drawable to use when a request fails. final <ERROR CLASS>error(Drawable drawable)Set the default error drawable to use when a request fails. final <ERROR CLASS>fallback(@DrawableRes() Integer drawableResId)Set the default fallback drawable to use if ImageRequest.data is null. final <ERROR CLASS>fallback(Drawable drawable)Set the default fallback drawable to use if ImageRequest.data is null. final <ERROR CLASS>memoryCachePolicy(CachePolicy policy)Set the default memory cache policy. final <ERROR CLASS>diskCachePolicy(CachePolicy policy)Set the default disk cache policy. final <ERROR CLASS>networkCachePolicy(CachePolicy policy)Set the default network cache policy. final <ERROR CLASS>logger(Logger logger)Set the Logger to write logs to. final ImageLoaderbuild()Create a new ImageLoader instance. final ImageLoader.BuilderavailableMemoryPercentage(@FloatRange(from = 0.0.toDouble(), to = 1.0.toDouble()) Double percent)final ImageLoader.BuildertrackWeakReferences(Boolean enable)final ImageLoader.BuilderlaunchInterceptorChainOnMainThread(Boolean enable)final ImageLoader.BuildercomponentRegistry(ComponentRegistry registry)final ImageLoader.Buildertransition(Transition transition)-
-
Constructor Detail
-
ImageLoader.Builder
ImageLoader.Builder(Context context)
-
-
Method Detail
-
okHttpClient
final <ERROR CLASS> okHttpClient(OkHttpClient okHttpClient)
Set the OkHttpClient used for network requests.
This is a convenience function for calling
callFactory(Call.Factory).
-
okHttpClient
final <ERROR CLASS> okHttpClient(Function0<OkHttpClient> initializer)
Set a lazy callback to create the OkHttpClient used for network requests.
This allows lazy creation of the OkHttpClient on a background thread. initializer is guaranteed to be called at most once.
Prefer using this instead of
okHttpClient(OkHttpClient).This is a convenience function for calling
callFactory(() -> Call.Factory).
-
callFactory
final <ERROR CLASS> callFactory(Call.Factory callFactory)
Set the Call.Factory used for network requests.
-
callFactory
final <ERROR CLASS> callFactory(Function0<Call.Factory> initializer)
Set a lazy callback to create the Call.Factory used for network requests.
This allows lazy creation of the Call.Factory on a background thread. initializer is guaranteed to be called at most once.
Prefer using this instead of
callFactory(Call.Factory).
-
components
final <ERROR CLASS> components(ComponentRegistry components)
Set the ComponentRegistry.
-
memoryCache
final <ERROR CLASS> memoryCache(MemoryCache memoryCache)
Set the MemoryCache.
-
memoryCache
final <ERROR CLASS> memoryCache(Function0<MemoryCache> initializer)
Set a lazy callback to create the MemoryCache.
Prefer using this instead of
memoryCache(MemoryCache).
-
diskCache
final <ERROR CLASS> diskCache(DiskCache diskCache)
Set the DiskCache.
NOTE: By default, ImageLoaders share the same disk cache instance. This is necessary as having multiple disk cache instances active in the same directory at the same time can corrupt the disk cache.
-
diskCache
final <ERROR CLASS> diskCache(Function0<DiskCache> initializer)
Set a lazy callback to create the DiskCache.
Prefer using this instead of
diskCache(DiskCache).NOTE: By default, ImageLoaders share the same disk cache instance. This is necessary as having multiple disk cache instances active in the same directory at the same time can corrupt the disk cache.
-
allowHardware
final <ERROR CLASS> allowHardware(Boolean enable)
Allow the use of Bitmap.Config.HARDWARE.
If false, any use of Bitmap.Config.HARDWARE will be treated as Bitmap.Config.ARGB_8888.
NOTE: Setting this to false this will reduce performance on API 26 and above. Only disable this if necessary.
Default: true
-
allowRgb565
final <ERROR CLASS> allowRgb565(Boolean enable)
Allow automatically using Bitmap.Config.RGB_565 when an image is guaranteed to not have alpha.
This will reduce the visual quality of the image, but will also reduce memory usage.
Prefer only enabling this for low memory and resource constrained devices.
Default: false
-
addLastModifiedToFileCacheKey
final <ERROR CLASS> addLastModifiedToFileCacheKey(Boolean enable)
Enables adding File.lastModified to the memory cache key when loading an image from a File.
This allows subsequent requests that load the same file to miss the memory cache if the file has been updated. However, if the memory cache check occurs on the main thread (see interceptorDispatcher) calling File.lastModified will cause a strict mode violation.
Default: true
-
networkObserverEnabled
final <ERROR CLASS> networkObserverEnabled(Boolean enable)
Enables short circuiting network requests if the device is offline.
If true, reading from the network will automatically be disabled if the device is offline. If a cached response is unavailable the request will fail with a '504 Unsatisfiable Request' response.
If false, the image loader will attempt a network request even if the device is offline.
Default: true
-
respectCacheHeaders
final <ERROR CLASS> respectCacheHeaders(Boolean enable)
Enables support for network cache headers. If enabled, this image loader will respect the cache headers returned by network responses when deciding if an image can be stored or served from the disk cache. If disabled, images will always be served from the disk cache (if present) and will only be evicted to stay under the maximum size.
Default: true
-
bitmapFactoryMaxParallelism
final <ERROR CLASS> bitmapFactoryMaxParallelism(Integer maxParallelism)
Sets the maximum number of parallel BitmapFactory decode operations at once.
Increasing this number will allow more parallel BitmapFactory decode operations, however it can result in worse UI performance.
Default: 4
-
bitmapFactoryExifOrientationPolicy
final <ERROR CLASS> bitmapFactoryExifOrientationPolicy(ExifOrientationPolicy policy)
Sets the policy for handling the EXIF orientation flag for images decoded by BitmapFactoryDecoder.
-
eventListener
final <ERROR CLASS> eventListener(EventListener listener)
Set a single EventListener that will receive all callbacks for requests launched by this image loader.
-
eventListenerFactory
final <ERROR CLASS> eventListenerFactory(EventListener.Factory factory)
Set the EventListener.Factory to create per-request EventListeners.
-
crossfade
final <ERROR CLASS> crossfade(Boolean enable)
Enable a crossfade animation with duration CrossfadeDrawable.DEFAULT_DURATION milliseconds when a request completes successfully.
Default: false
-
crossfade
final <ERROR CLASS> crossfade(Integer durationMillis)
Enable a crossfade animation with durationMillis milliseconds when a request completes successfully.
-
transitionFactory
final <ERROR CLASS> transitionFactory(Transition.Factory factory)
Set the default Transition.Factory for each request.
-
precision
final <ERROR CLASS> precision(Precision precision)
Set the default precision for a request. Precision controls whether the size of the loaded image must match the request's size exactly or not.
Default: Precision.AUTOMATIC
-
bitmapConfig
final <ERROR CLASS> bitmapConfig(Bitmap.Config bitmapConfig)
Set the preferred Bitmap.Config.
This is not guaranteed and a different config may be used in some situations.
Default: DEFAULT_BITMAP_CONFIG
-
dispatcher
final <ERROR CLASS> dispatcher(CoroutineDispatcher dispatcher)
A convenience function to set fetcherDispatcher, decoderDispatcher, and transformationDispatcher in one call.
-
interceptorDispatcher
final <ERROR CLASS> interceptorDispatcher(CoroutineDispatcher dispatcher)
The CoroutineDispatcher that the Interceptor chain will be executed on.
Default:
Dispatchers.Main.immediate
-
fetcherDispatcher
final <ERROR CLASS> fetcherDispatcher(CoroutineDispatcher dispatcher)
The CoroutineDispatcher that Fetcher.fetch will be executed on.
Default: Dispatchers.IO
-
decoderDispatcher
final <ERROR CLASS> decoderDispatcher(CoroutineDispatcher dispatcher)
The CoroutineDispatcher that Decoder.decode will be executed on.
Default: Dispatchers.IO
-
transformationDispatcher
final <ERROR CLASS> transformationDispatcher(CoroutineDispatcher dispatcher)
The CoroutineDispatcher that Transformation.transform will be executed on.
Default: Dispatchers.IO
-
placeholder
final <ERROR CLASS> placeholder(@DrawableRes() Integer drawableResId)
Set the default placeholder drawable to use when a request starts.
-
placeholder
final <ERROR CLASS> placeholder(Drawable drawable)
Set the default placeholder drawable to use when a request starts.
-
error
final <ERROR CLASS> error(@DrawableRes() Integer drawableResId)
Set the default error drawable to use when a request fails.
-
error
final <ERROR CLASS> error(Drawable drawable)
Set the default error drawable to use when a request fails.
-
fallback
final <ERROR CLASS> fallback(@DrawableRes() Integer drawableResId)
Set the default fallback drawable to use if ImageRequest.data is null.
-
fallback
final <ERROR CLASS> fallback(Drawable drawable)
Set the default fallback drawable to use if ImageRequest.data is null.
-
memoryCachePolicy
final <ERROR CLASS> memoryCachePolicy(CachePolicy policy)
Set the default memory cache policy.
-
diskCachePolicy
final <ERROR CLASS> diskCachePolicy(CachePolicy policy)
Set the default disk cache policy.
-
networkCachePolicy
final <ERROR CLASS> networkCachePolicy(CachePolicy policy)
Set the default network cache policy.
NOTE: Disabling writes has no effect.
-
build
final ImageLoader build()
Create a new ImageLoader instance.
-
availableMemoryPercentage
final ImageLoader.Builder availableMemoryPercentage(@FloatRange(from = 0.0.toDouble(), to = 1.0.toDouble()) Double percent)
-
trackWeakReferences
final ImageLoader.Builder trackWeakReferences(Boolean enable)
-
launchInterceptorChainOnMainThread
final ImageLoader.Builder launchInterceptorChainOnMainThread(Boolean enable)
-
componentRegistry
final ImageLoader.Builder componentRegistry(ComponentRegistry registry)
-
transition
final ImageLoader.Builder transition(Transition transition)
-
-
-
-