Forked from sensen/LollipopBitmapMemoryCacheParamsSupplier.java
Created
September 5, 2017 06:53
-
-
Save BALUSANGEM/2982f6a4f71a255089dece4424bd7e89 to your computer and use it in GitHub Desktop.
Fresco's custom BitmapMemoryCacheParamsSupplier for Lollipop devices
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
public class LollipopBitmapMemoryCacheParamsSupplier implements Supplier<MemoryCacheParams> { | |
private ActivityManager activityManager; | |
public LollipopBitmapMemoryCacheParamsSupplier(ActivityManager activityManager) { | |
this.activityManager = activityManager; | |
} | |
@Override | |
public MemoryCacheParams get() { | |
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { | |
return new MemoryCacheParams(getMaxCacheSize(), 1, 1, 1, 1); | |
} else { | |
return new MemoryCacheParams( | |
getMaxCacheSize(), | |
256, | |
Integer.MAX_VALUE, | |
Integer.MAX_VALUE, | |
Integer.MAX_VALUE); | |
} | |
} | |
private int getMaxCacheSize() { | |
final int maxMemory = | |
Math.min(activityManager.getMemoryClass() * ByteConstants.MB, Integer.MAX_VALUE); | |
if (maxMemory < 32 * ByteConstants.MB) { | |
return 4 * ByteConstants.MB; | |
} else if (maxMemory < 64 * ByteConstants.MB) { | |
return 6 * ByteConstants.MB; | |
} else { | |
if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.GINGERBREAD) { | |
return 8 * ByteConstants.MB; | |
} else { | |
return maxMemory / 4; | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment