Open Source Project Universal Image Loader for Android documentation (1) Introduction

Source: Internet
Author: User



When developing applications-Android, one often facesthe problem of displaying some graphical content from the interne T. youshould provide image loading from the Web in a Android app, their processingand displaying with limited memory Again and again. And despite the problemhomogeneity, each new project imposes it own specific requirements on thetask.

Need to organize caching of downloaded images; Ifimages is rather large, it's necessary to ensure effective working with thememory to prevent the disastrous mistake Ou Tofmemoryerror. It is also possiblethat an image-stub have to be showed during the image loading; And maybe Thesame image should is displayed in different size variations, etc.

As a result, time and resources is 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 was solution universalization of the above Describedproblem in a flexible and configurable 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 is various lists, tables, galleries, whereyou need to display images From the Web.

The top of the list of words is why the author did the project.

Now this class library can be used anywhere, for example, you need to download and display pictures from the network, or read from your phone locally. Where imageloader can be used include a variety of lists,tables,galleries

The main features of the Imageloader for Android is:

Key features include:

? asynchronous loading and displaying images from the Internet or the Sd-card;

Load and display pictures asynchronously from a network or SD card

? Ability ofcaching loaded images in memory and/or the device ' s file system;

Cache a picture locally or in memory

? Ability Tomonitor The loading process by means of "listeners"

Monitoring the loading process with "listener"

? effectiveworking with the memory while caching images in the memory;

More efficient work when caching pictures to memory

? wideopportunities to customize the tool-to-fit it to your needs.

Highly customizable

Optional settings for Imageloader

What can is configured in the Imageloader?

Global Settings :

? themaximum size of images cached in the memory;

Maximum size of picture cached in memory

? Timeoutfor Connection establishing and image loading;

Connection timeout and picture load time-out time

? themaximum number of simultaneously working threads for images loading;

Number of simultaneous worker threads used when loading pictures

? threadspriority during downloading and displaying images;

Thread priority when downloading and displaying pictures

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

Use defined local cache or custom

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

Use defined memory cache or custom

? Default options of Image downloading

Default options for picture downloads

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

The picture loading options can be set up as follows:

? whether todisplay the image-stub in the ImageView and while the real image is being loaded (if yes and then you need to spec Ify this "stub");

Whether the image-stub is displayed when the real picture is loaded successfully. (If yes, stub required)

? Whether Tocache The downloaded image in the memory.

Whether the downloaded picture is cached in memory

? Whether Tocache The downloaded image in the file system.

Whether the downloaded picture is cached locally

? Type ofimage decoding (the fastest or the most economical 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 the most likely, you'll be quitesatisfied with the ready solutions, and most of the which is 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 caching methods, but usually the implemented methods in the jar package are already available to meet your needs. For example......

There is enough configuration options, but this is not thecase as "the main principle of UNIX": "U can Configureeverythin G. And you'll configure everything. ":) In the Theimageloader case, can customize everything, but it isn't necessary at all:?? The default configuration is all available and suitable in the most cases.

Although UIL has provided many settings, the Distance "Unix core spirit: You can configure any option that you can configure any option" still has a gap. In UIL, you can customize any of the 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's, looking ahead, the call Imageloader.displayimage (ImageView, Imageu RL) are performed in a separate thread, except if the Pictureis in cache in the Memory-then it's just immediately displ Ayed.here is a separate threads queue where tasks get if theneeded image is cached on the file system. The rightimage in the cache and then the task-thread gets in the thread pool. Therefore,there is no obstacles for a fast displaying of cached images.

Briefly describe the structure of the project. Each picture's load and display tasks are run in a separate thread, unless the picture is cached in memory, and this scenario is immediately displayed. If the desired picture is cached locally, they will open a separate thread queue. If there is no correct picture in the cache, the task thread is fetched from the thread pool, so there is no obvious obstacle to quickly displaying the cached picture.

He algorithm of the taskprocessing is epresented on the scheme:

The rules of the process are described in simple terms:

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 above mentioned threads queue and thread pool

? cache in Thememory;

Cache to Memory

? disk cache;

Cache to Local

? image Decoder,which decodes image files into Bitmap objects.

Image parsing, parsing a picture into a bitmap object

The main class Imageloader manages it all; The maininteraction with the user is performed through it.

The most important class Imageloader manages all the operations, and the user's interaction is also primarily through that class.

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.