Created
April 19, 2016 05:40
-
-
Save TheLittleNaruto/85f54143cf3185f4e4ff65a8c013745d 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
import android.graphics.Bitmap; | |
import android.util.LruCache; | |
import com.android.volley.toolbox.ImageLoader; | |
/** | |
* Created by BabyNaruto on 3/31/2015. | |
*/ | |
public class BitmapLruCache extends LruCache<String, Bitmap> | |
implements ImageLoader.ImageCache { | |
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); | |
} | |
public static int getDefaultLruCacheSize() { | |
final int maxMemory = | |
(int) (Runtime.getRuntime().maxMemory() / 1024); | |
final int cacheSize = maxMemory / 8; | |
return cacheSize; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment