Skip to content

Commit c935475

Browse files
committed
Merge pull request nostra13#279 from googolmo/percent
add memoryCachePercent method
2 parents 665c3de + be8e74e commit c935475

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

library/src/com/nostra13/universalimageloader/core/ImageLoaderConfiguration.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -349,6 +349,31 @@ public Builder memoryCacheSize(int memoryCacheSize) {
349349
return this;
350350
}
351351

352+
/**
353+
* Sets maximum memory cache size percent in system memory for {@link android.graphics.Bitmap bitmaps} (in bytes).<br />
354+
* Default value - 1/8 of available app memory.<br />
355+
* <b>NOTE:</b> If you use this method then
356+
* {@link com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache LruMemoryCache} will be used as
357+
* memory cache. You can use {@link #memoryCache(MemoryCacheAware)} method to set your own implementation of
358+
* {@link MemoryCacheAware}.
359+
*/
360+
public Builder memoryCachePercent(int memoryCachePercent) {
361+
if (memoryCachePercent <= 0) throw new IllegalArgumentException("memoryCacheSize must be a positive number");
362+
363+
if (memoryCache != null) {
364+
L.w(WARNING_OVERLAP_MEMORY_CACHE);
365+
}
366+
367+
if (memoryCachePercent > 80) {
368+
memoryCachePercent = 80;
369+
}
370+
int capacity = (int) ((Runtime.getRuntime().maxMemory() * (memoryCachePercent / 100f)));
371+
if (capacity > 0) {
372+
this.memoryCacheSize = capacity;
373+
}
374+
return this;
375+
}
376+
352377
/**
353378
* Sets memory cache for {@link android.graphics.Bitmap bitmaps}.<br />
354379
* Default value - {@link com.nostra13.universalimageloader.cache.memory.impl.LruMemoryCache LruMemoryCache}

0 commit comments

Comments
 (0)