Skip to content

Commit

Permalink
fix(android): support set custom image pool size
Browse files Browse the repository at this point in the history
  • Loading branch information
siguangli2018 committed Nov 4, 2024
1 parent 82eaecf commit 248b541
Showing 1 changed file with 25 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,29 +22,35 @@

public class ImageDataPool extends BasePool<ImageDataKey, ImageRecycleObject> {

private static final int DEFAULT_IMAGE_POOL_SIZE = 16;
private LruCache<ImageDataKey, ImageRecycleObject> mPools;
private static int IMAGE_POOL_SIZE = 24;
private static LruCache<ImageDataKey, ImageRecycleObject> 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<ImageDataKey, ImageRecycleObject>(
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<ImageDataKey, ImageRecycleObject>(
IMAGE_POOL_SIZE) {
@Override
protected void entryRemoved(boolean evicted, @NonNull ImageDataKey key,
@NonNull ImageRecycleObject oldValue, @Nullable ImageRecycleObject newValue) {
if (evicted) {
onEntryEvicted(oldValue);
}
}
}
};
};
}
}

@Override
Expand Down

0 comments on commit 248b541

Please sign in to comment.