ImageLoader architecture diagram

The diagram below, from the Internet, is one of the most common architecture diagrams of Universal image-Loader. Based on this chart, this paper analyzes and explains.

Universal image-loader structure division

In the figure above, it is divided into four parts by color:

  1. ImageLoader: The API exposed by the framework to the user, who uses the functionality provided by the framework by calling the public API;
  2. ImageLoaderEngine: control of image loading process, including: priority of different cache data, effective control of data to be loaded, synchronous and asynchronous control of loading process, etc.
  3. BitmapDisplayer: processing of loaded image data, such as rounded corners, gradient control, etc.
  4. Data Interface & Data: image Data cache related Interface definition and implementation;

The Universal image-loader parameter is configured

To use the Universal image-loader framework, you only need to set some parameters of the framework to use the framework. The framework can work with the default Settings even if it does not set any parameters, but we still need to know these parameters.

DisplayImageOptions

Image load configuration. The framework supports setting a separate DisplayImageOptions object for each image load. If this is not set, the value in the ImageLoaderConfiguration object is used as the default value.

// The default values in the following code are defined in Builder in the source code
public final class DisplayImageOptions {
   // Image loading placeholder: valid if a memoryCache hit fails
   private final int imageResOnLoading = 0;
   private final Drawable imageOnLoading = null;
   // Empty connection placeholder
   private final int imageResForEmptyUri = 0;
   private final Drawable imageForEmptyUri = null;
   // Image loading failed placeholder map
   private final int imageResOnFail = 0;
   private final Drawable imageOnFail = null;
   
   // Whether to clear images before loading: memoryCache is valid only when a memoryCache hit fails
   private final boolean resetViewBeforeLoading = false;
   
   / / enable MemoryCache
   private final boolean cacheInMemory = false;
   // Enable DiskCache
   private final boolean cacheOnDisk = false;
   // asynchronous load control
   private final boolean isSyncLoading = false;
   private final int delayBeforeLoading = 0;
   
   // Image Exif information processing
   private final boolean considerExifParams = false;
   
   // Image download engine personalization, custom ImageDownloader use
   private final Object extraForDownloader = null;
   
   // Image files loaded into memory Settings
   private final Options decodingOptions = new Options();
   private final ImageScaleType imageScaleType = ImageScaleType.IN_SAMPLE_POWER_OF_2;
   
   // The Bitmap is preprocessed before loading into the View
   private final BitmapProcessor preProcessor;
   private final BitmapProcessor postProcessor;
   
   // Image loading handler
   private final BitmapDisplayer displayer = new SimpleBitmapDisplayer();
   // Post tool for asynchronously loading images
   private final Handler handler;
}
Copy the code

ImageLoaderConfiguration

Framework configuration, including cache implementation classes, image download control, thread pools, and so on.

Public Final class ImageLoaderConfiguration {// Resource manager final Resources Resources; / / MemoryCache picture size limit, less than or equal to zero, according to the pictures the default attribute values final int maxImageWidthForMemoryCache = 0; final int maxImageHeightForMemoryCache = 0; / / DiskCache picture size limit, 0 at the same time don't do deal with final int maxImageWidthForDiskCache; final int maxImageHeightForDiskCache; Final BitmapProcessor processorForDiskCache; final BitmapProcessor processorForDiskCache; final Executor taskExecutor; final Executor taskExecutorForCachedImages; final boolean customExecutor; final boolean customExecutorForCachedImages; final int threadPoolSize; final int threadPriority; final QueueProcessingType tasksProcessingType; MemoryCache Implementation class final MemoryCache MemoryCache; // LruMemoryCache // DiskCache implementation class final DiskCache DiskCache; // UnlimitedDiskCache final ImageDecoder decoder; // BaseImageDecoder // ImageDownloader // BaseImageDownloader final ImageDownloader networkDeniedDownloader; final ImageDownloader slowNetworkDownloader; / / show the default display Settings final DisplayImageOptions defaultDisplayImageOptions; }Copy the code