ImageLoader source code analysis -----ImageLoader structure

Recently, I have been studying the source code of ImageLoader, hoping to share my own ideas. The specific source code is downloaded from Github: https://github.com/nostra13/Android-Universal-Image-Loader
We are not in a hurry to explain the source code. If there is any mistake, please leave a message to discuss, let's first understand the ImageLoader A brief structure diagram of related class dependencies:

Paste_Image.png

From the figure we can be divided into three layers:
1: UI layer.
2: Load the display logic layer: various configurations, LoadTask, DisplayTask.
3: Get the image data layer.

Let's introduce the classes in ImageLoader:

Entry control class:
ImageLoader: The entry class, as the entry control class of the entire framework, uses the single-column mode.
Configuration class
ImageLoaderConfiguration: proposes the configuration of ImageLoader. Builder mode is used.
DefaultConfigurationFactory: The default configuration factory class for ImageLoaderConfiguration. Use the static factory pattern.
DisplayImageOptions: Contains some image display options: such as image loading failure, loading, and abnormally displayed images. Builder mode.
ImageLoadingInfo: Information class in image loading. Encapsulate some keys, display View, DisplayImageOptions, image loading listeners and process listeners, etc.
Task class:
ImageLoaderEngine: All the groups that need to load the thread pool execution thread asynchronously are done through this class.
DisplayBitmapTask: Display the loaded Bitmap image by executing this task.
ProcessAndDisplayImageTask: When the memory is replaced with a Bitmap, the task that is called when post-processor processing is required. That is, it is called when options.shouldPostProcess() is established.
LoadAndDisplayImageTask: The task that loads the image stream and displays the call.

The following classes are divided according to the package path:
com.nostra13.universalimageloader.core.download (downloader module):
ImageDownloader: The interface defined by the image downloader, and the enumeration type and the method of returning InputStream are defined. Through this method, we know that the ImageLoader framework supports: HTTP("http"), HTTPS("https"), FILE("file"), CONTENT("content"), ASSETS("assets"), DRAWABLE("drawable" ), six protocols.
BaseImageDownloader: Implemented ImageDownloader to complete the implementation of various protocols to obtain InputStream.

com.nostra13.universalimageloader.core.decode (the decoder module of the image stream):
ImageDecodingInfo: The data used in the process of decoding the image stream.
ImageDecoder: The interface that defines the image decoding stream. Convert the stream to Bitmap through the incoming ImageDecodingInfo.
BaseImageDecoder: The implementation class of ImageDecoder.

com.nostra13.universalimageloader.core.imageaware (wrapper class)
ImageAware: wraps the display class, such as the interface of ImageView, and extends some methods. Define to get the width and height, get the ViewScaleType type, get the encapsulated object getWrappedView, whether to recycle isCollected, get IDgetId, setImageDrawable, setImageBitmap.
ViewAware: An abstract class that implements the ImageAware interface. Wrap an Android View with a weak reference.
NonViewAware: An abstract class that implements the ImageAware interface and defines methods that do not depend on View display. This general method is used only in the case of downloading images.
ImageViewAware: Implement the ViewAware abstract method. Reproduces an ImageView-specific operation.

com.nostra13.universalimageloader.core.listener (listener)
ImageLoadingListener: The listener for image loading, which defines the start, failure, completion, and cancellation.
ImageLoadingProgressListener: Image loading progress listener, defines the onProgressUpdate method.
SimpleImageLoadingListener: Implement the empty ImageLoadingListener method.
PauseOnScrollListener: Temporarily load when listening for fast scrolling.

com.nostra13.universalimageloader.core.assist (helper class)
ViewScaleType: View scaling type.
QueueProcessingType: The task processing type. FIFO or LIFO.
LoadedFrom: Loaded type. Network, local, memory.
ImageSize: Image size.
ImageScaleType: The type of image scaling.
FlushedInputStream: Solve the streaming problem of slow networks.
FailReason: The reason for the failure.
ContentLengthInputStream: encapsulates the return stream.
com.nostra13.universalimageloader.core.assist.deque: Queue.

Let's talk about the classification algorithm of the core local cache and memory cache:

com.nostra13.universalimageloader.cache.memory (memory cache)
MemoryCache: An interface that defines memory caching methods.
BaseMemoryCache: Abstract class for base behavior. Implement simple methods to set, get, delete, clean up memory objects and get all keys. The abstract class that exposes the reference.
LimitedMemoryCache: Abstract class to limit memory size.

WeakMemoryCache: Implements the BaseMemoryCache abstract class to use a soft reference strategy.
FuzzyKeyMemoryCache: Implement BaseMemoryCache. If you traverse before setting the key, if the cache exists, delete it first and then set it.

UsingFreqLimitedMemoryCache: Implement LimitedMemoryCache, record the number of times of use, and delete the least used one if the size exceeds the limit.
FIFOLimitedMemoryCache: Implements LimitedMemoryCache, uses a first-in first-out algorithm, uses a list to save the Bitmap list, and deletes 0 first when deleting.
LargestLimitedMemoryCache: Implement LimitedMemoryCache, record the size of the bitmap, and delete the largest bitmap.
LRULimitedMemoryCache: Implements LimitedMemoryCache, the least recently used algorithm. Use the features of LinkedHashMap to find the Bitmap that has not been used for the longest time and delete it, weak reference.

LruMemoryCache: Implements MemoryCache, the least recently used algorithm. Strong citations.

com.nostra13.universalimageloader.cache.disc (hard disk cache)
DiskCache: interface to define cache

com.nostra13.universalimageloader.cache.disc.naming (file name generator)
FileNameGenerator: defines the interface
HashCodeFileNameGenerator: uses URL to generate hashcode code to string.
Md5FileNameGenerator: Use MD5 to load URL to generate unique key.

com.nostra13.universalimageloader.cache.disc.impl (hard disk cache implementation):
BaseDiskCache: abstract class.
UnlimitedDiskCache: Implement BaseDiskCache without any restrictions.
LimitedAgeDiskCache: Implement BaseDiskCache and delete it over time.

LruDiskCache: The least recently used algorithm implements hard disk caching.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325530341&siteId=291194637