diff --git a/modules/android/pool/src/main/java/com/openhippy/pool/ImageDataPool.java b/modules/android/pool/src/main/java/com/openhippy/pool/ImageDataPool.java index af5258655b5..d082661ed4e 100644 --- a/modules/android/pool/src/main/java/com/openhippy/pool/ImageDataPool.java +++ b/modules/android/pool/src/main/java/com/openhippy/pool/ImageDataPool.java @@ -22,29 +22,35 @@ public class ImageDataPool extends BasePool { - private static final int DEFAULT_IMAGE_POOL_SIZE = 16; - private LruCache mPools; + private static int IMAGE_POOL_SIZE = 24; + private static LruCache mPools; - public ImageDataPool() { - init(DEFAULT_IMAGE_POOL_SIZE); - } - - @SuppressWarnings("unused") - public ImageDataPool(int size) { - init(Math.max(DEFAULT_IMAGE_POOL_SIZE, size)); + public static void setImagePoolSize(int size) { + if (size > 0) { + IMAGE_POOL_SIZE = size; + if (mPools != null) { + try { + mPools.resize(size); + } catch (IllegalArgumentException e) { + // ignore incorrect value settings + } + } + } } - private void init(int size) { - mPools = new LruCache( - size) { - @Override - protected void entryRemoved(boolean evicted, @NonNull ImageDataKey key, - @NonNull ImageRecycleObject oldValue, @Nullable ImageRecycleObject newValue) { - if (evicted) { - onEntryEvicted(oldValue); + public ImageDataPool() { + if (mPools == null) { + mPools = new LruCache( + IMAGE_POOL_SIZE) { + @Override + protected void entryRemoved(boolean evicted, @NonNull ImageDataKey key, + @NonNull ImageRecycleObject oldValue, @Nullable ImageRecycleObject newValue) { + if (evicted) { + onEntryEvicted(oldValue); + } } - } - }; + }; + } } @Override