Created
June 26, 2013 09:23
-
-
Save svangsgaard/5866044 to your computer and use it in GitHub Desktop.
A very simple BitmapCache - a wrapper around LruCache<String, Bitmap>. Can be used with volley.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| import android.graphics.Bitmap; | |
| import android.support.v4.util.LruCache; | |
| import com.android.volley.toolbox.ImageLoader.ImageCache; | |
| public class BitmapLruCache extends LruCache<String, Bitmap> implements ImageCache { | |
| public static int getDefaultLruCacheSize() { | |
| final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024); | |
| final int cacheSize = maxMemory / 8; | |
| return cacheSize; | |
| } | |
| 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); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment