diff options
author | Andrew Neal <andrew.d.neal@gmail.com> | 2014-12-10 10:51:42 +0100 |
---|---|---|
committer | Danny Baumann <dannybaumann@web.de> | 2014-12-12 15:59:06 +0100 |
commit | 980e8fe4eb99aa4ad2805b4cd5d44ff3c6677360 (patch) | |
tree | d88131d6411ba8059ac5a6da0680b8a7d7606830 /src | |
parent | 40030b0a59b793d2e98208471904de9d85b7f01b (diff) | |
download | android_packages_apps_Eleven-980e8fe4eb99aa4ad2805b4cd5d44ff3c6677360.tar.gz android_packages_apps_Eleven-980e8fe4eb99aa4ad2805b4cd5d44ff3c6677360.tar.bz2 android_packages_apps_Eleven-980e8fe4eb99aa4ad2805b4cd5d44ff3c6677360.zip |
Update Notification background color
This change uses Palette to update Apollo's Notification background
color based on the current artwork.
It also removes the timestamp from the Notification.
Change-Id: I6a292839c223bf9d165e9c90724194eae6ca343c
Diffstat (limited to 'src')
-rw-r--r-- | src/com/cyanogenmod/eleven/MusicPlaybackService.java | 32 |
1 files changed, 27 insertions, 5 deletions
diff --git a/src/com/cyanogenmod/eleven/MusicPlaybackService.java b/src/com/cyanogenmod/eleven/MusicPlaybackService.java index 85f45dd..e6af28f 100644 --- a/src/com/cyanogenmod/eleven/MusicPlaybackService.java +++ b/src/com/cyanogenmod/eleven/MusicPlaybackService.java @@ -51,6 +51,7 @@ import android.os.SystemClock; import android.provider.MediaStore; import android.provider.MediaStore.Audio.AlbumColumns; import android.provider.MediaStore.Audio.AudioColumns; +import android.support.v7.graphics.Palette; import android.text.TextUtils; import android.util.Log; @@ -486,6 +487,7 @@ public class MusicPlaybackService extends Service { // to improve perf, instead of hitting the disk cache or file cache, store the bitmaps in memory private String mCachedKey; private Bitmap[] mCachedBitmap = new Bitmap[2]; + private int mCachedBitmapAccentColor = 0; /** * Image cache @@ -1482,16 +1484,18 @@ public class MusicPlaybackService extends Service { Intent nowPlayingIntent = new Intent("com.cyanogenmod.eleven.AUDIO_PLAYER") .addFlags(Intent.FLAG_ACTIVITY_NEW_TASK); PendingIntent clickIntent = PendingIntent.getActivity(this, 0, nowPlayingIntent, 0); + Bitmap artwork = getAlbumArt(false); // TODO: Add back a beter small icon when we have time - Notification notification = new Notification.Builder(this) + Notification.Builder builder = new Notification.Builder(this) .setSmallIcon(R.drawable.ic_launcher) - .setLargeIcon(getAlbumArt(false)) + .setLargeIcon(artwork) .setContentIntent(clickIntent) .setContentTitle(getTrackName()) .setContentText(text) .setShowWhen(false) .setStyle(style) + .setShowWhen(false) .setVisibility(Notification.VISIBILITY_PUBLIC) .addAction(R.drawable.btn_playback_previous, getString(R.string.accessibility_prev), @@ -1500,10 +1504,27 @@ public class MusicPlaybackService extends Service { retrievePlaybackAction(TOGGLEPAUSE_ACTION)) .addAction(R.drawable.btn_playback_next, getString(R.string.accessibility_next), - retrievePlaybackAction(NEXT_ACTION)) - .build(); + retrievePlaybackAction(NEXT_ACTION)); + + if (mCachedBitmapAccentColor == 0 && artwork != null) { + // Generate a new Palette from the current artwork + final Palette p = Palette.generate(artwork); + if (p != null) { + // Check for dark vibrant colors, then vibrant + Palette.Swatch swatch = p.getDarkVibrantSwatch(); + if (swatch == null) { + swatch = p.getVibrantSwatch(); + } + if (swatch != null) { + mCachedBitmapAccentColor = swatch.getRgb(); + } + } + } + if (mCachedBitmapAccentColor != 0) { + builder.setColor(mCachedBitmapAccentColor); + } - startForeground(hashCode(), notification); + startForeground(hashCode(), builder.build()); } private final PendingIntent retrievePlaybackAction(final String action) { @@ -2603,6 +2624,7 @@ public class MusicPlaybackService extends Service { if (!key.equals(mCachedKey)) { mCachedBitmap[0] = null; mCachedBitmap[1] = null; + mCachedBitmapAccentColor = 0; } // store the new key and bitmap |