Created
May 20, 2013 18:44
-
-
Save ficusk/5614325 to your computer and use it in GitHub Desktop.
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 your.awesome.app; | |
import android.graphics.Bitmap; | |
import android.support.v4.util.LruCache; | |
import com.android.volley.toolbox.ImageLoader.ImageCache; | |
public class LruBitmapCache extends LruCache<String, Bitmap> implements ImageCache { | |
public LruBitmapCache(int maxSize) { | |
super(maxSize); | |
} | |
@Override | |
protected int sizeOf(String key, Bitmap value) { | |
return value.getRowBytes() * value.getHeight(); | |
} | |
@Override | |
public Bitmap getBitmap(String url) { | |
return get(url); | |
} | |
@Override | |
public void putBitmap(String url, Bitmap bitmap) { | |
put(url, bitmap); | |
} | |
} |
You can take a look here at the code of the Google way of do this:
http://developer.android.com/training/volley/request.html
After all I think it depends on how you use volley. It makes sense on apps like Instagram or Google Play Store where you have the screen full of images. If you use Volley for request images but you have 1 or 2 images in each activity and they are not really loaded heavily... I have no idea how to work on this cache image stuff. Probably a few MB is enough.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
maxSize for caches that do not override sizeOf(K, V), this is the maximum number of entries in the cache. http://developer.android.com/reference/android/util/LruCache.html#LruCache(int) or int maxSize = (int) (Runtime.getRuntime().maxMemory() / 1024 / 8);