Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a8cb126d authored by Selim Cinek's avatar Selim Cinek
Browse files

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
parent d836c4f8
Loading
Loading
Loading
Loading
+31 −19
Original line number Diff line number Diff line
@@ -5182,17 +5182,22 @@ public class Notification implements Parcelable
        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 @@ public class Notification implements Parcelable
                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 class Notification implements Parcelable
        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);
            }
        }
+15 −0
Original line number Diff line number Diff line
@@ -592,6 +592,21 @@
    <!-- The size of the right icon -->
    <dimen name="notification_right_icon_size">40dp</dimen>

    <!-- The maximum height of any image in a remote view. This is applied to all images in custom remoteviews. -->
    <dimen name="notification_custom_view_max_image_height_low_ram">208dp</dimen>
    <!-- The maximum height of any image in a remote view. This is applied to all images in custom remoteviews. -->
    <dimen name="notification_custom_view_max_image_width_low_ram">294dp</dimen>
    <!-- The maximum height of a big picture in a notification. The images will be reduced to that height in case they are bigger. -->
    <dimen name="notification_big_picture_max_height_low_ram">208dp</dimen>
    <!-- The maximum width of a big picture in a notification. The images will be reduced to that width in case they are bigger. -->
    <dimen name="notification_big_picture_max_width_low_ram">294dp</dimen>
    <!-- The maximum height of a image in a media notification. The images will be reduced to that height in case they are bigger. -->
    <dimen name="notification_media_image_max_height_low_ram">100dp</dimen>
    <!-- The maximum width of a image in a media notification. The images will be reduced to that width in case they are bigger.-->
    <dimen name="notification_media_image_max_width_low_ram">100dp</dimen>
    <!-- The size of the right icon image when on low ram -->
    <dimen name="notification_right_icon_size_low_ram">40dp</dimen>

    <!-- Max width/height of the autofill data set picker as a fraction of the screen width/height -->
    <dimen name="autofill_dataset_picker_max_size">90%</dimen>

+8 −0
Original line number Diff line number Diff line
@@ -2932,6 +2932,14 @@
  <java-symbol type="dimen" name="notification_custom_view_max_image_height"/>
  <java-symbol type="dimen" name="notification_custom_view_max_image_width"/>

  <java-symbol type="dimen" name="notification_big_picture_max_height_low_ram"/>
  <java-symbol type="dimen" name="notification_big_picture_max_width_low_ram"/>
  <java-symbol type="dimen" name="notification_media_image_max_width_low_ram"/>
  <java-symbol type="dimen" name="notification_media_image_max_height_low_ram"/>
  <java-symbol type="dimen" name="notification_right_icon_size_low_ram"/>
  <java-symbol type="dimen" name="notification_custom_view_max_image_height_low_ram"/>
  <java-symbol type="dimen" name="notification_custom_view_max_image_width_low_ram"/>

  <!-- Accessibility fingerprint gestures -->
  <java-symbol type="string" name="capability_title_canCaptureFingerprintGestures" />
  <java-symbol type="string" name="capability_desc_canCaptureFingerprintGestures" />