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