提交 6d48bd5b 编写于 作者: J judds 提交者: Sam Judd

Pass Builder directly into constructor of MemorySizeCalculator.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=165653043
上级 71bfc6b6
...@@ -28,30 +28,32 @@ public final class MemorySizeCalculator { ...@@ -28,30 +28,32 @@ public final class MemorySizeCalculator {
int getHeightPixels(); int getHeightPixels();
} }
MemorySizeCalculator(Context context, ActivityManager activityManager, private MemorySizeCalculator(MemorySizeCalculator.Builder builder) {
ScreenDimensions screenDimensions, float memoryCacheScreens, float bitmapPoolScreens, this.context = builder.context;
int targetArrayPoolSize, float maxSizeMultiplier, float lowMemoryMaxSizeMultiplier) {
this.context = context;
arrayPoolSize = arrayPoolSize =
isLowMemoryDevice(activityManager) isLowMemoryDevice(builder.activityManager)
? targetArrayPoolSize / LOW_MEMORY_BYTE_ARRAY_POOL_DIVISOR ? builder.arrayPoolSizeBytes / LOW_MEMORY_BYTE_ARRAY_POOL_DIVISOR
: targetArrayPoolSize; : builder.arrayPoolSizeBytes;
final int maxSize = getMaxSize(activityManager, maxSizeMultiplier, lowMemoryMaxSizeMultiplier); int maxSize =
getMaxSize(
final int screenSize = screenDimensions.getWidthPixels() * screenDimensions.getHeightPixels() builder.activityManager, builder.maxSizeMultiplier, builder.lowMemoryMaxSizeMultiplier);
* BYTES_PER_ARGB_8888_PIXEL;
int screenSize =
int targetPoolSize = Math.round(screenSize * bitmapPoolScreens); builder.screenDimensions.getWidthPixels() *
int targetMemoryCacheSize = Math.round(screenSize * memoryCacheScreens); builder.screenDimensions.getHeightPixels() *
BYTES_PER_ARGB_8888_PIXEL;
int targetPoolSize = Math.round(screenSize * builder.bitmapPoolScreens);
int targetMemoryCacheSize = Math.round(screenSize * builder.memoryCacheScreens);
int availableSize = maxSize - arrayPoolSize; int availableSize = maxSize - arrayPoolSize;
if (targetMemoryCacheSize + targetPoolSize <= availableSize) { if (targetMemoryCacheSize + targetPoolSize <= availableSize) {
memoryCacheSize = targetMemoryCacheSize; memoryCacheSize = targetMemoryCacheSize;
bitmapPoolSize = targetPoolSize; bitmapPoolSize = targetPoolSize;
} else { } else {
float part = availableSize / (bitmapPoolScreens + memoryCacheScreens); float part = availableSize / (builder.bitmapPoolScreens + builder.memoryCacheScreens);
memoryCacheSize = Math.round(part * memoryCacheScreens); memoryCacheSize = Math.round(part * builder.memoryCacheScreens);
bitmapPoolSize = Math.round(part * bitmapPoolScreens); bitmapPoolSize = Math.round(part * builder.bitmapPoolScreens);
} }
if (Log.isLoggable(TAG, Log.DEBUG)) { if (Log.isLoggable(TAG, Log.DEBUG)) {
...@@ -69,9 +71,9 @@ public final class MemorySizeCalculator { ...@@ -69,9 +71,9 @@ public final class MemorySizeCalculator {
+ ", max size: " + ", max size: "
+ toMb(maxSize) + toMb(maxSize)
+ ", memoryClass: " + ", memoryClass: "
+ activityManager.getMemoryClass() + builder.activityManager.getMemoryClass()
+ ", isLowMemoryDevice: " + ", isLowMemoryDevice: "
+ isLowMemoryDevice(activityManager)); + isLowMemoryDevice(builder.activityManager));
} }
} }
...@@ -230,10 +232,8 @@ public final class MemorySizeCalculator { ...@@ -230,10 +232,8 @@ public final class MemorySizeCalculator {
} }
public MemorySizeCalculator build() { public MemorySizeCalculator build() {
return new MemorySizeCalculator(context, activityManager, screenDimensions, return new MemorySizeCalculator(this);
memoryCacheScreens, bitmapPoolScreens, arrayPoolSizeBytes, maxSizeMultiplier, }
lowMemoryMaxSizeMultiplier);
}
} }
private static final class DisplayMetricsScreenDimensions implements ScreenDimensions { private static final class DisplayMetricsScreenDimensions implements ScreenDimensions {
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册