Skip to content

Instantly share code, notes, and snippets.

@TheLittleNaruto
Created April 19, 2016 05:40
Show Gist options
  • Save TheLittleNaruto/85f54143cf3185f4e4ff65a8c013745d to your computer and use it in GitHub Desktop.
Save TheLittleNaruto/85f54143cf3185f4e4ff65a8c013745d to your computer and use it in GitHub Desktop.
import android.graphics.Bitmap;
import android.util.LruCache;
import com.android.volley.toolbox.ImageLoader;
/**
* Created by BabyNaruto on 3/31/2015.
*/
public class BitmapLruCache extends LruCache<String, Bitmap>
implements ImageLoader.ImageCache {
public BitmapLruCache() {
this(getDefaultLruCacheSize());
}
public BitmapLruCache(int sizeInKiloBytes) {
super(sizeInKiloBytes);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight() / 1024;
}
@Override
public Bitmap getBitmap(String url) {
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
put(url, bitmap);
}
public static int getDefaultLruCacheSize() {
final int maxMemory =
(int) (Runtime.getRuntime().maxMemory() / 1024);
final int cacheSize = maxMemory / 8;
return cacheSize;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment