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 in casual places. Like what. You need to download and display images from the Web. or read locally from your phone. Imageloader can be used to 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 onboarding 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 time-out and picture load time-out
? themaximum number of simultaneously working threads for images loading;
Number of worker threads used at the same time 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 define yourself
? implementation of cache in the memory (you can choose from ready-madeimplementations or create your own);
Use a defined memory cache or define it yourself
? 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 image loading option allows you to set the following:
? 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 after the real picture has been loaded successfully.
(Assuming that a stub is needed)
? 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 (high speed/economy)
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).
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.
Like what.
。。。。
。
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 a lot of settings, it is the core spirit of Unix: You can configure whatever options are available. You can configure no matter what option "there is still a gap. In UIL, you can define whatever options you have. But that's not necessary. Since the default settings are usually available, 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.
A brief description of the structure of the project.
Each picture's load and display tasks are executed in a separate thread, unless the picture is cached in memory, and the film is displayed immediately. Assuming that the required images are cached locally, they will open a separate thread queue. Assuming that there is no correct picture in the cache, the task thread is fetched from the thread pool, so there is no obvious obstacle to the high-speed display of the cached picture.
He algorithm of the taskprocessing is epresented on the scheme:
The rules are dealt with in a simple descriptive narrative:
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 of the operations. The interaction with the user is also primarily through this class.
Open Source Project Universal Image Loader for Android documentation (1) Brief introduction