Skip to content

Instantly share code, notes, and snippets.

@NLMartian
Created September 1, 2013 07:29
Show Gist options
  • Save NLMartian/6402884 to your computer and use it in GitHub Desktop.
Save NLMartian/6402884 to your computer and use it in GitHub Desktop.
Simple implementation Volley's ImageCache
package jp.classmethod.android.sample.volley;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import com.android.volley.toolbox.ImageLoader.ImageCache;
public class BitmapCache implements ImageCache {
private LruCache<String, Bitmap> mCache;
public BitmapCache() {
int maxSize = 10 * 1024 * 1024;
mCache = new LruCache<String, Bitmap>(maxSize) {
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight();
}
};
}
@Override
public Bitmap getBitmap(String url) {
return mCache.get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
mCache.put(url, bitmap);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment