Advertisement
rachmadi

LruBitmapCache.java

Jul 15th, 2016
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.94 KB | None | 0 0
  1. import android.graphics.Bitmap;
  2. import android.support.v4.util.LruCache;
  3.  
  4. import com.android.volley.toolbox.ImageLoader.ImageCache;
  5.  
  6. public class LruBitmapCache extends LruCache<String, Bitmap> implements
  7.         ImageCache {
  8.     public static int getDefaultLruCacheSize() {
  9.         final int maxMemory = (int) (Runtime.getRuntime().maxMemory() / 1024);
  10.         final int cacheSize = maxMemory / 8;
  11.  
  12.         return cacheSize;
  13.     }
  14.  
  15.     public LruBitmapCache() {
  16.         this(getDefaultLruCacheSize());
  17.     }
  18.  
  19.     public LruBitmapCache(int sizeInKiloBytes) {
  20.         super(sizeInKiloBytes);
  21.     }
  22.  
  23.     @Override
  24.     protected int sizeOf(String key, Bitmap value) {
  25.         return value.getRowBytes() * value.getHeight() / 1024;
  26.     }
  27.  
  28.     @Override
  29.     public Bitmap getBitmap(String url) {
  30.         return get(url);
  31.     }
  32.  
  33.     @Override
  34.     public void putBitmap(String url, Bitmap bitmap) {
  35.         put(url, bitmap);
  36.     }
  37. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement