Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Executor downloadExecutor = Executors.newFixedThreadPool(5);
Executor cachedExecutor = Executors.newSingleThreadExecutor();
ActivityManager am = (ActivityManager) getSystemService(Context.ACTIVITY_SERVICE);
int memClass = am.getMemoryClass();
final int memoryCacheSize = 1024 * 1024 * memClass / 8;
DisplayImageOptions options = new DisplayImageOptions.Builder()
.showStubImage(android.R.color.transparent)
.bitmapConfig(Bitmap.Config.RGB_565)
.imageScaleType(ImageScaleType.IN_SAMPLE_INT)
.cacheInMemory(true)
.cacheOnDisc(true)
.build();
File cacheDir = StorageUtils.getCacheDirectory(this);
ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
.taskExecutor(downloadExecutor)
.taskExecutorForCachedImages(cachedExecutor)
.memoryCache(new UsingFreqLimitedMemoryCache(memoryCacheSize)) // 2 Mb
.discCache(new TotalSizeLimitedDiscCache(cacheDir, 52428800))
.imageDownloader(new BaseImageDownloader(this, 5 * 1000, 30 * 1000)) // connectTimeout (5 s), readTimeout (30 s)
.defaultDisplayImageOptions(options)
.build();
int memClass = am.getMemoryClass();
final int memoryCacheSize = 1024 * 1024 * memClass / 8;
Note: In this example, one eighth of the application memory is allocated for our cache. On a normal/hdpi device this is a minimum of around 4MB (32/8). A full screen GridView filled with images on a device with 800x480 resolution would use around 1.5MB (800*480*4 bytes), so this would cache a minimum of around 2.5 pages of images in memory.
imageView.post(new Runnable() {
@Override
public void run() {
imageLoader.displayImage(...);
}
});
Экономим память: Picasso vs UniversalImageLoader