Forked from sensen/LollipopBitmapMemoryCacheParamsSupplier.java
Created
April 12, 2017 03:43
-
-
Save vipulasri/6420dc29525f1682dc794876fa840637 to your computer and use it in GitHub Desktop.
Fresco's custom BitmapMemoryCacheParamsSupplier for Lollipop devices
This file contains hidden or 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