Maybe fixed the "transparent notification bug on Touchwiz"

This commit is contained in:
Karim Abou Zeid 2015-06-20 15:43:19 +02:00
commit cf921dc02f
7 changed files with 16 additions and 84 deletions

View file

@ -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);
}
}
}

View file

@ -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);

View file

@ -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"

View file

@ -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">
<ImageView
android:id="@+id/icon"

View file

@ -20,7 +20,7 @@
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="128dp"
android:background="@color/default_notification_color">
android:background="@color/default_colored_notification_color">
<ImageView
android:id="@+id/icon"

View file

@ -20,7 +20,7 @@
android:id="@+id/root"
android:layout_width="match_parent"
android:layout_height="64dp"
android:background="@color/default_notification_color"
android:background="@color/default_colored_notification_color"
android:orientation="horizontal"
internal:layout_maxHeight="64dp"
internal:layout_minHeight="64dp"

View file

@ -25,7 +25,6 @@
<color name="sliding_tabs_deactivated">#99FFFFFF</color>
<!--notification-->
<color name="default_notification_color">@android:color/transparent</color>
<color name="default_notification_content_color">#deFFFFFF</color>
<color name="default_notification_secondary_content_color">#aaFFFFFF</color>