private static int getMaxSize(ActivityManager activityManager, float maxSizeMultiplier, float lowMemoryMaxSizeMultiplier) { final int memoryClassBytes = activityManager.getMemoryClass() * 1024 * 1024; final boolean isLowMemoryDevice = isLowMemoryDevice(activityManager); return Math.round(memoryClassBytes * (isLowMemoryDevice ? lowMemoryMaxSizeMultiplier : maxSizeMultiplier)); }
public Builder(Context context) { this.context = context; activityManager = (ActivityManager) context.getSystemService(Context.ACTIVITY_SERVICE); screenDimensions = new DisplayMetricsScreenDimensions(context.getResources().getDisplayMetrics()); // On Android O+ Bitmaps are allocated natively, ART is much more efficient at managing // garbage and we rely heavily on HARDWARE Bitmaps, making Bitmap re-use much less important. // We prefer to preserve RAM on these devices and take the small performance hit of not // re-using Bitmaps and textures when loading very small images or generating thumbnails. if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.O && isLowMemoryDevice(activityManager)) { bitmapPoolScreens = 0; } }
isLowMemoryDevice(builder.activityManager) ? builder.arrayPoolSizeBytes / LOW_MEMORY_BYTE_ARRAY_POOL_DIVISOR : builder.arrayPoolSizeBytes; + builder.activityManager.getMemoryClass() + ", isLowMemoryDevice: " + isLowMemoryDevice(builder.activityManager));
private static int getMaxSize(ActivityManager activityManager) { final int memoryClassBytes = activityManager.getMemoryClass() * 1024 * 1024; final boolean isLowMemoryDevice = isLowMemoryDevice(activityManager); return Math.round(memoryClassBytes * (isLowMemoryDevice ? LOW_MEMORY_MAX_SIZE_MULTIPLIER : MAX_SIZE_MULTIPLIER)); }
MemorySizeCalculator(Context context, ActivityManager activityManager, ScreenDimensions screenDimensions) { this.context = context; final int maxSize = getMaxSize(activityManager); final int screenSize = screenDimensions.getWidthPixels() * screenDimensions.getHeightPixels() * BYTES_PER_ARGB_8888_PIXEL; int targetPoolSize = screenSize * BITMAP_POOL_TARGET_SCREENS; int targetMemoryCacheSize = screenSize * MEMORY_CACHE_TARGET_SCREENS; if (targetMemoryCacheSize + targetPoolSize <= maxSize) { memoryCacheSize = targetMemoryCacheSize; bitmapPoolSize = targetPoolSize; } else { int part = Math.round((float) maxSize / (BITMAP_POOL_TARGET_SCREENS + MEMORY_CACHE_TARGET_SCREENS)); memoryCacheSize = part * MEMORY_CACHE_TARGET_SCREENS; bitmapPoolSize = part * BITMAP_POOL_TARGET_SCREENS; } if (Log.isLoggable(TAG, Log.DEBUG)) { Log.d(TAG, "Calculated memory cache size: " + toMb(memoryCacheSize) + " pool size: " + toMb(bitmapPoolSize) + " memory class limited? " + (targetMemoryCacheSize + targetPoolSize > maxSize) + " max size: " + toMb(maxSize) + " memoryClass: " + activityManager.getMemoryClass() + " isLowMemoryDevice: " + isLowMemoryDevice(activityManager)); } }
private static int getMaxSize(ActivityManager activityManager, float maxSizeMultiplier, float lowMemoryMaxSizeMultiplier) { final int memoryClassBytes = activityManager.getMemoryClass() * 1024 * 1024; final boolean isLowMemoryDevice = isLowMemoryDevice(activityManager); return Math.round(memoryClassBytes * (isLowMemoryDevice ? lowMemoryMaxSizeMultiplier : maxSizeMultiplier)); }
isLowMemoryDevice(builder.activityManager) ? builder.arrayPoolSizeBytes / LOW_MEMORY_BYTE_ARRAY_POOL_DIVISOR : builder.arrayPoolSizeBytes; + builder.activityManager.getMemoryClass() + ", isLowMemoryDevice: " + isLowMemoryDevice(builder.activityManager));