I'm implementing a Lollipop-style notification to a FTP streaming music player app using the new Notification.MediaStyle class. I am setting the album art as my "large icon".
Given that the album art is taken directly from the file currently being played, the size of this album art varies depending on the source (potentially up to 5000x5000).
From my pre-lollipop code I decode the bitmap under a maximum size defined by:
android.R.dimen.notification_large_icon_width
and
android.R.dimen.notification_large_icon_height
which works well as decoding time is much faster and memory usage is ideal.
However, when this code is applied to my MediaStyle style, the expanded view uses a icon much larger than defined by the dimension parameters resulting in a blurry album art when expanded.
Is there some constant to define the maximum size the expanded view for a MediaStyle large icon can be? Or is there some workaround to this issue? As it currently stands, it is unacceptable for the art to be decoded at full resolution as it may cause the app to crash due to OOM.
From Lollipop source code I can see image size is 128dp, see notification_template_material_big_media.xml on GitHub:
<!-- Layout to be used with only max 3 actions. It has a much larger picture at the left side-->
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/status_bar_latest_event_content"
android:layout_width="match_parent"
android:layout_height="128dp"
android:background="#00000000"
android:tag="bigMediaNarrow"
>
<ImageView android:id="@+id/icon"
android:layout_width="128dp"
android:layout_height="128dp"
android:scaleType="centerCrop"
/>
<!-- ...Nothing interesting for us futher... -->
</RelativeLayout>
This is for expanded layout with 3 or less action buttons. Looking to Notification.MediaStyle.getBigLayoutResource(int) on GrepCode, if there are more buttons it seems notification_template_material_big_media.xml is used:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/status_bar_latest_event_content"
android:layout_width="match_parent"
android:layout_height="128dp"
android:background="#00000000"
android:tag="bigMedia"
>
<include layout="@layout/notification_template_icon_group"
android:layout_width="@dimen/notification_large_icon_width"
android:layout_height="@dimen/notification_large_icon_height"
/>
<!-- ...Nothing interesting for us futher... -->
</RelativeLayout>
And notification_template_icon_group.xml looks like this:
<FrameLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:internal="http://schemas.android.com/apk/prv/res/android"
android:layout_width="@dimen/notification_large_icon_width"
android:layout_height="@dimen/notification_large_icon_height"
android:id="@+id/icon_group"
>
<ImageView android:id="@+id/icon"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="12dp"
android:layout_marginBottom="12dp"
android:layout_marginStart="12dp"
android:layout_marginEnd="12dp"
android:scaleType="centerInside"
/>
<ImageView android:id="@+id/right_icon"
android:layout_width="16dp"
android:layout_height="16dp"
android:padding="3dp"
android:layout_gravity="end|bottom"
android:scaleType="centerInside"
android:visibility="gone"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
/>
</FrameLayout>
You can find notification_large_icon_width
and notification_large_icon_height
in .../res/values/dimens.xml:
<!-- The width of the big icons in notifications. -->
<dimen name="notification_large_icon_width">64dp</dimen>
<!-- The width of the big icons in notifications. -->
<dimen name="notification_large_icon_height">64dp</dimen>
So the final answer - 128dp for expanded layout with 3 or less action buttons and 64dp if there are more then 3.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With