Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Volley ImageLoader - BitmapLruCache parameter?

I am having trouble implementing Image cache using the new Volley library. In the presentation, code look like this

mRequestQueue = Volley.newRequestQueue(context); mImageLoader = new ImageLoader(mRequestQueue, new BitmapLruCache()); 

The BitmapLruCache is obviously not included in the toolkit. Any idea how to implement it or point me to some resources?

http://www.youtube.com/watch?v=yhv8l9F44qo @14:38

Thanks!

like image 983
urSus Avatar asked May 22 '13 02:05

urSus


2 Answers

import android.graphics.Bitmap; import android.support.v4.util.LruCache;  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);     } } 
like image 170
Vladimir Mironov Avatar answered Sep 29 '22 05:09

Vladimir Mironov


Ficus provides this sample code for the Bitmap LRU:

https://gist.github.com/ficusk/5614325

like image 20
Keith Avatar answered Sep 29 '22 04:09

Keith