標籤:rpo necessary sim struct data org test ace 本機快取
When developing applications for Android, one often facesthe problem of displaying some graphical content from the Internet. So, youshould provide image loading from the Web in an Android app, their processingand displaying with limited memory again and again. And despite the problemhomogeneity, each new project imposes its own specific requirements on thetask.
You may need to organize caching of downloaded images; ifimages are rather large, it is necessary to ensure effective working with thememory to prevent the disastrous mistake OutOfMemoryError . It is also possiblethat an image-stub has to be showed during the image loading; and maybe thesame image should 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 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 are various lists, tables, galleries, whereyou need to display images from the Web.
上面一大堆話,是說作者為什麼做這個項目
如今這個類庫能夠用在隨意地方。比如。你須要從網路上下載和顯示圖片。或者從手機本地讀取。ImageLoader能夠用的地方包含各種lists,tables。galleries
The main features of the ImageLoader for Android are:
主要特性包含:
?asynchronous loading and displaying images from the Internet or the SD-card;
從網路或SD卡非同步載入和顯示圖片
? ability ofcaching loaded images in memory and / or the device‘s file system;
在本地或記憶體中緩衝圖片
? ability tomonitor the loading process by means of "listeners"
通過“listener”監視載入的過程
? effectiveworking with the memory while caching images in the memory;
緩衝圖片至記憶體時,更加高效的工作
? wideopportunities to customize the tool to fit it to your needs.
高度可定製化
ImageLoader的可選設定項
What can be configured in the ImageLoader?
全域設定:
? themaximum size of images cached in the memory;
在記憶體中緩衝的圖片最大尺寸
? timeoutfor connection establishing and image loading;
連線逾時時間和圖片載入逾時時間
? themaximum number of simultaneously working threads for images loading;
載入圖片時使用的同一時候背景工作執行緒數量
? threadspriority during downloading and displaying images;
下載和顯示圖片時的線程優先順序
?implementation of disk cache (you can choose from ready-made implementations orcreate your own);
使用已定義本機快取或自己定義
?implementation of cache in the memory (you can choose from ready-madeimplementations or create your own);
使用已定義記憶體緩衝或自己定義
? default options of image downloading
圖片下載的預設選項
Image loading options (applied to each individual callImageLoader.displayImage(...)) provide the ability to specify:
圖片載入選項能夠進行下面設定:
? whether todisplay the image-stub in the ImageView, while the real image is being loaded(if yes, then you need to specify this "stub");
當真實圖片載入成功以後,是否顯示image-stub。
(假設是,須要制定stub)
? Whether tocache the downloaded image in the memory.
在記憶體中是否緩衝已下載圖片
? Whether tocache the downloaded image in the file system.
在本地是否緩衝已下載圖片
? Type ofimage decoding (the fastest or the most economical for the memory).
圖片解碼方式(高速/經濟)
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).
如上所述。你能夠實現你自己的本機快取和記憶體緩衝方法,可是通常Jar包中已實現的方法已經能夠滿足你的需求。
比如。
。。。。
。
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.
雖然UIL已經提供了非常多設定,可是距離“UNIX的核心精神:你能夠配置不論什麼選項。你能夠配置不論什麼選項”仍有差距。在UIL中,你能夠自己定義不論什麼選項。但這並非必須的。由於通常已經有了預設設定,並且這些設定在大多數情況下都是適用的。
Implementationpeculiarities
特定需求的實現
Few words about the project structure. Each task for image loadingand displaying (and that is, looking ahead, the call ImageLoader.displayImage(imageView, imageUrl)) is performed in a separate thread, except 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.
簡單描寫敘述一下這個項目的結構。
每個圖片的載入和顯示任務都執行在獨立的線程中,除非這個圖片緩衝在記憶體中,這樣的情況片會馬上顯示。假設須要的圖片緩衝在本地,他們會開啟一個獨立的線程隊列。假設在緩衝中沒有正確的圖片,任務線程會從線程池中擷取,因此,高速顯示緩衝圖片時不會有明顯的障礙。
he algorithm of the taskprocessing isepresented on the scheme:
處理的規則用進行簡單的描寫敘述:
The main actors of the project can relatively be divided:
UIL的主要功能能夠分為下面及部分
? the above mentionedqueue and pool of threads;
上面提到的線程隊列和線程池
? cache in thememory;
緩衝至記憶體
? disk cache;
緩衝至本地
? Image decoder,which decodes image files into Bitmap objects.
圖片解析,將圖片解析為Bitmap對象
The main class ImageLoader manages it all; the maininteraction with the user is performed through it.
最重要的類ImageLoader管理了全部的操作。和使用者的互動也主要通過該類。
開源項目Universal Image Loader for Android 說明文檔 (1) 簡單介紹