Created
September 1, 2013 07:29
-
-
Save NLMartian/6402884 to your computer and use it in GitHub Desktop.
Simple implementation Volley's ImageCache
This file contains 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
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