package com.amaze.filemanager.utils;
import android.graphics.Bitmap;
import android.util.LruCache;
import com.android.volley.toolbox.ImageLoader;
/**
* Created by vishal on 7/6/16.
*/
public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageLoader.ImageCache {
/**
* @param maxSize for caches that do not override {@link #sizeOf}, this is
* the maximum number of entries in the cache. For all other caches,
* this is the maximum sum of the sizes of the entries in this cache.
*/
public LruBitmapCache(int maxSize) {
super(maxSize);
}
public LruBitmapCache() {
this(getDefaultCacheSize());
}
private static int getDefaultCacheSize() {
int memory = (int) (Runtime.getRuntime().maxMemory()/1024);
return memory/8;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getByteCount();
}
}