Skip to content

Instantly share code, notes, and snippets.

@omarmiatello
Created November 6, 2013 15:29
Show Gist options
  • Save omarmiatello/7337982 to your computer and use it in GitHub Desktop.
Save omarmiatello/7337982 to your computer and use it in GitHub Desktop.
package com.neosperience.egea.utils.volleytoolbox;
import com.android.volley.toolbox.ImageLoader.ImageCache;
import android.graphics.Bitmap;
import android.support.v4.util.LruCache;
import android.util.Log;
/**
* Basic LRU Memory cache.
*
* @author Trey Robinson
*
*/
public class BitmapLruImageCache extends LruCache<String, Bitmap> implements ImageCache{
private final String TAG = BitmapLruImageCache.class.getSimpleName();
public BitmapLruImageCache(int maxSize) {
super(maxSize);
}
@Override
protected int sizeOf(String key, Bitmap value) {
return value.getRowBytes() * value.getHeight();
}
@Override
public Bitmap getBitmap(String url) {
Log.v(TAG, "Retrieved item from Mem Cache");
return get(url);
}
@Override
public void putBitmap(String url, Bitmap bitmap) {
Log.v(TAG, "Added item to Mem Cache");
put(url, bitmap);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment