Introduction to the open-source project universal image loader for Android (1)

Source: Internet
Author: User

When developing applications for Android, one often facesthe problem of displaying some graphical content from the Internet. So, youshoshould provide image loading from the web in an Android app, their processingand displaying
Limited Memory again and again. And despite the problemhomogeneity, each new project imposes its own specific ments on thetask.

You may need to organize caching of downloaded images; ifimages are rather large, it is necessary to ensure valid working. It is also possiblethat an image-stub
Has to be showed during the image loading; and maybe thesame image shocould be displayed in different size variations, etc.

As a result, time and resources are wasted for codeadaptation to specific needs. it is this problem What urged me on creating alibrary with open source code-universal image loader for image loading in anandroid app. its aim
Is solution universalization of the above describedproblem in a flexible and retriable tool.

Currently, the Library can be used everywhere, where youhave to download and display (and possibly even to cache) an image from theInternet or from the file system of your smartphone. Classic examples forpossibility of imageloader
Using are various lists, tables, galleries, whereyou need to display images from the web.

The above is a lot of talk about why the author is working on this project.

Currently, this class library can be used anywhere. For example, you need to download and display images from the Internet or read images locally from your mobile phone. Imageloader can be used in various scenarios, including lists, tables, and galleries.

 

The main features of the imageloader for Android are:

Main features include:

• Asynchronous loading and displaying images from the Internet or the SD-card;

Asynchronously load and display images from network or SD card

• Ability ofcaching Loaded Images in memory and/or the device's file system;

Cache images locally or in memory

• Ability tomonitor the loading process by means of "listeners"

Monitor the loading process through "listener"

• Keep tiveworking with the memory while caching images in the memory;

It is more efficient to cache images to memory.

• Wideopportunities to customize the tool to fit it to your needs.

Highly customizable

 

Optional settings of imageloader

What can be configured in the imageloader?

Global settings:

• Themaximum size of images cached in the memory;

Maximum size of images cached in memory

• Timeoutfor connection establishing and image loading;

Connection timeout and image loading timeout

• Themaximum Number of simultaneously working threads for images loading;

Number of concurrent worker threads used for image loading

• Threadspriority during downloading and displaying images;

Thread priority for downloading and displaying images

• Implementation of disk cache (you can choose from ready-made implementations orcreate your own );

Use the defined local cache or custom

• Implementation of cache in the memory (you can choose from ready-madeimplementations or create your own );

Use the defined memory cache or custom

• Default options of image downloading

Default options for image download

Image loading options (applied to each individual callimageloader. displayimage (...) provide the ability to specify:

You can set the image loading options as follows:

• Whether todisplay the image-stub in the imageview, while the real image is being loaded (If yes, then you need to specify this "stub ");

Whether to display image-stub after the real image is loaded successfully. (If yes, Stub needs to be created)

• Whether Tocache the downloaded image in the memory.

Indicates whether the downloaded images are cached in the memory.

• Whether Tocache the downloaded image in the file system.

Indicates whether the downloaded image is cached locally.

• Type ofimage decoding (the fastest or the most economy mical for the memory ).

Image decoding method (Fast/economical)

As already mentioned, you can implement your own version ofthe disk cache and the cache in memory. but most likely, you will be quitesatisfied with ready solutions, most of which are caches, limited by someparameter (size, number
Of files) and having their own logic of Self-cleaningby limit excess (FIFO, the oldest object, the largest object, the most seldomused ).

As mentioned above, you can implement your own local cache and memory cache methods, but the methods already implemented in the jar package can already meet your needs. For example ......

 

There are enough configuration options, but this is not thecase as "the main principle of Unix": "u can configureeverything. And you will configure everything." In theimageloader case, you can customize
Everything, but it is not necessary at all: the default configuration is always available and suitable in the most cases.

Although UIL already provides many settings, there is still a gap between "core UNIX spirit: You can configure any options and you can configure any options. In UIL, you can customize any options, but this is not necessary, because the default settings are usually available and these settings are applicable in most cases.

Implementationpeculiarities

Implementation of specific requirements

Few words about the project structure. each task for image loadingand displaying (and that is, looking ahead, the call imageloader. displayimage (imageview, imageurl) is saved med in a separate thread, could T if the pictureis in
Cache in the memory-then it is just immediately displayed. here is a separate threads queue where tasks get If theneeded image is cached on the file system. if you do not have the rightimage in the cache, then the task-thread gets
In the thread pool. Therefore, there are no obstacles for a fast displaying of cached images.

Briefly describe the structure of this project. Each image loading and display task runs in a separate thread, unless the image is cached in the memory, this will be immediately displayed. If the image is cached locally, an independent thread queue is enabled. If there is no correct picture in the cache, the task thread will get it from the thread pool. Therefore, there is no obvious obstacle to quickly display the cached picture.

He algorithm of the taskprocessing is
Epresented on the Scheme:

The rules to be processed are described as follows:

 

 

The main actors of the project can relatively be divided:

The main functions of UIL can be divided into the following parts:

• The above mentionedqueue and pool of threads;

The thread queue and thread pool mentioned above

• Cache in thememory;

Cache to memory

• Disk cache;

Cache to local

• Image decoder, which decodes image files into bitmap objects.

Parse the image into a bitmap object

The main class imageloader
Manages it all; the maininteraction with the user is already med through it.

The most important class imageloader manages all operations and interacts with users through this class.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.