From cf921dc02f09354e6762136d577aa72b8b230306 Mon Sep 17 00:00:00 2001 From: Karim Abou Zeid Date: Sat, 20 Jun 2015 15:43:19 +0200 Subject: [PATCH] Maybe fixed the "transparent notification bug on Touchwiz" --- .../gramophone/helper/MediaSessionHelper.java | 70 ------------------- .../helper/PlayingNotificationHelper.java | 21 +++--- .../res/layout/notification_controller.xml | 1 - .../layout/notification_controller_big.xml | 3 +- .../notification_controller_big_colored.xml | 2 +- .../notification_controller_colored.xml | 2 +- app/src/main/res/values/colors.xml | 1 - 7 files changed, 16 insertions(+), 84 deletions(-) delete mode 100644 app/src/main/java/com/kabouzeid/gramophone/helper/MediaSessionHelper.java diff --git a/app/src/main/java/com/kabouzeid/gramophone/helper/MediaSessionHelper.java b/app/src/main/java/com/kabouzeid/gramophone/helper/MediaSessionHelper.java deleted file mode 100644 index 373a0ef3..00000000 --- a/app/src/main/java/com/kabouzeid/gramophone/helper/MediaSessionHelper.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.kabouzeid.gramophone.helper; - -import android.media.RemoteControlClient; -import android.os.Build; -import android.support.v4.media.session.MediaSessionCompat; -import android.support.v4.media.session.PlaybackStateCompat; - -public class MediaSessionHelper { - - public static void applyState(MediaSessionCompat session, PlaybackStateCompat playbackState) { - session.setPlaybackState(playbackState); - ensureTransportControls(session, playbackState); - } - - private static void ensureTransportControls(MediaSessionCompat session, PlaybackStateCompat playbackState) { - long actions = playbackState.getActions(); - Object rccObj = session.getRemoteControlClient(); - - if (actions != 0 - && Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH - && Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP - && rccObj != null) { - - int transportControls = 0; - - if ((actions & PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS; - } - - if ((actions & PlaybackStateCompat.ACTION_REWIND) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_REWIND; - } - - if ((actions & PlaybackStateCompat.ACTION_PLAY) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PLAY; - } - - if ((actions & PlaybackStateCompat.ACTION_PLAY_PAUSE) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PLAY_PAUSE; - } - - if ((actions & PlaybackStateCompat.ACTION_PAUSE) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_PAUSE; - } - - if ((actions & PlaybackStateCompat.ACTION_STOP) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_STOP; - } - - if ((actions & PlaybackStateCompat.ACTION_FAST_FORWARD) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_FAST_FORWARD; - } - - if ((actions & PlaybackStateCompat.ACTION_SKIP_TO_NEXT) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_NEXT; - } - - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) { - if ((actions & PlaybackStateCompat.ACTION_SEEK_TO) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_POSITION_UPDATE; - } - - if ((actions & PlaybackStateCompat.ACTION_SET_RATING) != 0) { - transportControls |= RemoteControlClient.FLAG_KEY_MEDIA_RATING; - } - } - ((RemoteControlClient) rccObj).setTransportControlFlags(transportControls); - } - } -} \ No newline at end of file diff --git a/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java b/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java index 9bfd2f1c..6a449f72 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java +++ b/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java @@ -221,25 +221,30 @@ public class PlayingNotificationHelper { } private void setAlbumArt(Bitmap albumArt) { - int defaultColor = isColored ? - service.getResources().getColor(R.color.default_colored_notification_color) : - service.getResources().getColor(R.color.default_notification_color); - int newColor = defaultColor; if (albumArt != null) { notificationLayout.setImageViewBitmap(R.id.icon, albumArt); notificationLayoutExpanded.setImageViewBitmap(R.id.icon, albumArt); - if (isColored) - newColor = Palette.from(albumArt).generate().getVibrantColor(defaultColor); + if (isColored) { + int defaultColor = service.getResources().getColor(R.color.default_colored_notification_color); + int newColor = Palette.from(albumArt).generate().getVibrantColor(defaultColor); + setBackgroundColor(newColor); + } } else { notificationLayout.setImageViewResource(R.id.icon, R.drawable.default_album_art); notificationLayoutExpanded.setImageViewResource(R.id.icon, R.drawable.default_album_art); + if (isColored) { + int defaultColor = service.getResources().getColor(R.color.default_colored_notification_color); + setBackgroundColor(defaultColor); + } } - notificationLayout.setInt(R.id.root, "setBackgroundColor", newColor); - notificationLayoutExpanded.setInt(R.id.root, "setBackgroundColor", newColor); notificationManager.notify(NOTIFICATION_ID, notification); } + private void setBackgroundColor(int color) { + notificationLayoutExpanded.setInt(R.id.root, "setBackgroundColor", color); + } + public void killNotification() { if (isReceiverRegistered) service.unregisterReceiver(notificationColorPreferenceChangedReceiver); diff --git a/app/src/main/res/layout/notification_controller.xml b/app/src/main/res/layout/notification_controller.xml index a6349acb..01800c89 100644 --- a/app/src/main/res/layout/notification_controller.xml +++ b/app/src/main/res/layout/notification_controller.xml @@ -20,7 +20,6 @@ android:id="@+id/root" android:layout_width="match_parent" android:layout_height="64dp" - android:background="@color/default_notification_color" android:orientation="horizontal" internal:layout_maxHeight="64dp" internal:layout_minHeight="64dp" diff --git a/app/src/main/res/layout/notification_controller_big.xml b/app/src/main/res/layout/notification_controller_big.xml index 3610c1c6..0e28f98c 100644 --- a/app/src/main/res/layout/notification_controller_big.xml +++ b/app/src/main/res/layout/notification_controller_big.xml @@ -19,8 +19,7 @@ xmlns:tools="http://schemas.android.com/tools" android:id="@+id/root" android:layout_width="match_parent" - android:layout_height="128dp" - android:background="@color/default_notification_color"> + android:layout_height="128dp"> + android:background="@color/default_colored_notification_color"> #99FFFFFF - @android:color/transparent #deFFFFFF #aaFFFFFF