change notification small icon to a white version of the audinaut logo instead of a generic play icon. add additional info to metadata when constructing notification to add basic support for android R's new persistent media controls

(cherry picked from commit ad5615d2bd43b7afe388e08a6a2df07472656b89)
This commit is contained in:
Morgan Lim 2020-07-07 01:34:13 -04:00
parent d10ea92edd
commit 0f525befca
2 changed files with 35 additions and 3 deletions

View File

@ -77,18 +77,27 @@ public final class Notifications {
.setComponent(new ComponentName(context, DownloadService.class)) .setComponent(new ComponentName(context, DownloadService.class))
.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP)); .putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP, KeyEvent.KEYCODE_MEDIA_STOP));
int[] compactActions = new int[]{0, 1, 2}; int[] compactActions = new int[]{0, 1, 2};
MediaSessionCompat mediaSession = new MediaSessionCompat(context, "Audinaut"); MediaSessionCompat mediaSession = new MediaSessionCompat(context, "Audinaut");
MediaSessionCompat.Token mediaToken = mediaSession.getSessionToken();
MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder(); MediaMetadataCompat.Builder metadataBuilder = new MediaMetadataCompat.Builder();
mediaSession.setMetadata(metadataBuilder.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, -1).build());
mediaSession.setMetadata(metadataBuilder
.putLong(MediaMetadataCompat.METADATA_KEY_DURATION, -1)
.putBitmap(MediaMetadataCompat.METADATA_KEY_ALBUM_ART, getAlbumArt(context, song))
//.putBitmap(MediaMetadataCompat.METADATA_KEY_DISPLAY_ICON, R.drawable.notification_logo)
.putString(MediaMetadataCompat.METADATA_KEY_TITLE, song.getTitle())
.putString(MediaMetadataCompat.METADATA_KEY_ARTIST, song.getArtist())
.build() );
MediaStyle mediaStyle = new MediaStyle() MediaStyle mediaStyle = new MediaStyle()
.setShowActionsInCompactView(compactActions) .setShowActionsInCompactView(compactActions)
.setShowCancelButton(true) .setShowCancelButton(true)
.setCancelButtonIntent(PendingIntent.getService(context, 0, cancelIntent, 0)) .setCancelButtonIntent(PendingIntent.getService(context, 0, cancelIntent, 0))
.setMediaSession(mediaSession.getSessionToken()); .setMediaSession(mediaToken);
NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_PLAYING_ID) NotificationCompat.Builder builder = new NotificationCompat.Builder(context, CHANNEL_PLAYING_ID)
.setChannelId(CHANNEL_PLAYING_ID) .setChannelId(CHANNEL_PLAYING_ID)
.setSmallIcon(R.drawable.stat_notify_playing)
.setContentTitle(song.getTitle()) .setContentTitle(song.getTitle())
.setContentText(song.getArtist()) .setContentText(song.getArtist())
.setSubText(song.getAlbum()) .setSubText(song.getAlbum())
@ -97,6 +106,7 @@ public final class Notifications {
.setVisibility(NotificationCompat.VISIBILITY_PUBLIC) .setVisibility(NotificationCompat.VISIBILITY_PUBLIC)
.setShowWhen(false) .setShowWhen(false)
.setLargeIcon(getAlbumArt(context, song)) .setLargeIcon(getAlbumArt(context, song))
.setSmallIcon(R.drawable.notification_logo)
.setStyle(mediaStyle) .setStyle(mediaStyle)
.setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0)); .setContentIntent(PendingIntent.getActivity(context, 0, notificationIntent, 0));
addActions(context, builder, playing); addActions(context, builder, playing);

View File

@ -0,0 +1,22 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:width="166.67238dp"
android:height="166.67238dp"
android:viewportWidth="590.5714"
android:viewportHeight="590.5714">
<path
android:pathData="M206.005,279.058L168.45,348.748C184.87,406.824 193.208,407.309 212.776,486.676C214.12,458.428 238.971,423.03 261.053,402.367C267.354,435.872 255.68,377.04 293.141,513.627C332.1,391.999 316.533,500.618 337.637,405.064C348.539,371.558 363.777,427.159 376.932,476.217C452.166,375.314 412.799,348.86 433.271,294.932L371.724,290.632C392.73,306.667 408.833,320.407 409.993,322.306C377.679,324.685 415.733,456.748 356.878,338.121C335.655,295.343 295.371,348.196 299.665,415.388C297.95,376.901 250.874,314.022 240.121,357.059C228.277,404.462 217.057,313.826 200.801,314.747C200.801,314.747 210.188,298.25 223.167,280.258L206.005,279.058z"
android:strokeLineJoin="miter"
android:strokeWidth="1.06667"
android:fillColor="#ffffff"
android:strokeColor="#00000000"
android:fillType="evenOdd"
android:strokeLineCap="butt"/>
<path
android:pathData="M299.698,57.766C203.66,58.469 106.33,194.128 115.327,470.79C173.525,604.547 148.628,384.605 194.797,317.036C217.046,284.475 360.513,287.543 378.398,310.373C453.87,406.714 408.23,613.071 475.558,467.012C493.324,197.684 398.733,59.207 301.967,57.773C301.211,57.762 300.454,57.761 299.698,57.766zM300.304,107.547C338.677,107.626 377.044,151.72 392.763,245.132C283.141,223.071 277.21,231.481 206.389,242.036C221.118,154.237 260.713,107.465 300.304,107.547z"
android:strokeLineJoin="miter"
android:strokeWidth="4.26667"
android:fillColor="#ffffff"
android:strokeColor="#00000000"
android:fillType="evenOdd"
android:strokeLineCap="butt"/>
</vector>