Created
September 4, 2015 03:33
-
-
Save sensen/a61eb1e7a1b7ea649cb0 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
This is just a workaround for the OOM issue when using Fresco on Lollipop devices.
Usage: