Reducing the image sizes further for low-ram devices
We're reducing the image sizes by a factor of 2, which is
a good compromise between image quality and memory reduction.
Test: add notifications on a low ram device, observe normal notifications
Change-Id: I344494bdcda950ad7461c43d9a08bf63c0bae266
Fixes: 62253442
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index a218274..dea1dbe 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -5182,17 +5182,22 @@
if (extras.getBoolean(EXTRA_REDUCED_IMAGES)) {
return;
}
+ boolean isLowRam = ActivityManager.isLowRamDeviceStatic();
if (mLargeIcon != null || largeIcon != null) {
Resources resources = context.getResources();
Class<? extends Style> style = getNotificationStyle();
- int maxWidth = resources.getDimensionPixelSize(R.dimen.notification_right_icon_size);
+ int maxWidth = resources.getDimensionPixelSize(isLowRam
+ ? R.dimen.notification_right_icon_size_low_ram
+ : R.dimen.notification_right_icon_size);
int maxHeight = maxWidth;
if (MediaStyle.class.equals(style)
|| DecoratedMediaCustomViewStyle.class.equals(style)) {
- maxHeight = resources.getDimensionPixelSize(
- R.dimen.notification_media_image_max_height);
- maxWidth = resources.getDimensionPixelSize(
- R.dimen.notification_media_image_max_width);
+ maxHeight = resources.getDimensionPixelSize(isLowRam
+ ? R.dimen.notification_media_image_max_height_low_ram
+ : R.dimen.notification_media_image_max_height);
+ maxWidth = resources.getDimensionPixelSize(isLowRam
+ ? R.dimen.notification_media_image_max_width_low_ram
+ : R.dimen.notification_media_image_max_width);
}
if (mLargeIcon != null) {
mLargeIcon.scaleDownIfNecessary(maxWidth, maxHeight);
@@ -5201,19 +5206,22 @@
largeIcon = Icon.scaleDownIfNecessary(largeIcon, maxWidth, maxHeight);
}
}
- reduceImageSizesForRemoteView(contentView, context);
- reduceImageSizesForRemoteView(headsUpContentView, context);
- reduceImageSizesForRemoteView(bigContentView, context);
+ reduceImageSizesForRemoteView(contentView, context, isLowRam);
+ reduceImageSizesForRemoteView(headsUpContentView, context, isLowRam);
+ reduceImageSizesForRemoteView(bigContentView, context, isLowRam);
extras.putBoolean(EXTRA_REDUCED_IMAGES, true);
}
- private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context) {
+ private void reduceImageSizesForRemoteView(RemoteViews remoteView, Context context,
+ boolean isLowRam) {
if (remoteView != null) {
Resources resources = context.getResources();
- int maxWidth = resources.getDimensionPixelSize(
- R.dimen.notification_custom_view_max_image_width);
- int maxHeight = resources.getDimensionPixelSize(
- R.dimen.notification_custom_view_max_image_height);
+ int maxWidth = resources.getDimensionPixelSize(isLowRam
+ ? R.dimen.notification_custom_view_max_image_width_low_ram
+ : R.dimen.notification_custom_view_max_image_width);
+ int maxHeight = resources.getDimensionPixelSize(isLowRam
+ ? R.dimen.notification_custom_view_max_image_height_low_ram
+ : R.dimen.notification_custom_view_max_image_height);
remoteView.reduceImageSizes(maxWidth, maxHeight);
}
}
@@ -5629,16 +5637,20 @@
public void reduceImageSizes(Context context) {
super.reduceImageSizes(context);
Resources resources = context.getResources();
+ boolean isLowRam = ActivityManager.isLowRamDeviceStatic();
if (mPicture != null) {
- int maxPictureWidth = resources.getDimensionPixelSize(
- R.dimen.notification_big_picture_max_height);
- int maxPictureHeight = resources.getDimensionPixelSize(
- R.dimen.notification_big_picture_max_width);
+ int maxPictureWidth = resources.getDimensionPixelSize(isLowRam
+ ? R.dimen.notification_big_picture_max_height_low_ram
+ : R.dimen.notification_big_picture_max_height);
+ int maxPictureHeight = resources.getDimensionPixelSize(isLowRam
+ ? R.dimen.notification_big_picture_max_width_low_ram
+ : R.dimen.notification_big_picture_max_width);
mPicture = Icon.scaleDownIfNecessary(mPicture, maxPictureWidth, maxPictureHeight);
}
if (mBigLargeIcon != null) {
- int rightIconSize = resources.getDimensionPixelSize(
- R.dimen.notification_right_icon_size);
+ int rightIconSize = resources.getDimensionPixelSize(isLowRam
+ ? R.dimen.notification_right_icon_size_low_ram
+ : R.dimen.notification_right_icon_size);
mBigLargeIcon.scaleDownIfNecessary(rightIconSize, rightIconSize);
}
}