diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotification.java b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotification.java index b444af22..d47f1dfc 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotification.java +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotification.java @@ -14,7 +14,8 @@ import code.name.monkey.retromusic.service.MusicService; public abstract class PlayingNotification { - static final String NOTIFICATION_CHANNEL_ID = "playing_notification"; + protected static final float NOTIFICATION_CONTROLS_SIZE_MULTIPLIER = 1.0f; + static final String NOTIFICATION_CHANNEL_ID = "playing_notification"; private static final int NOTIFICATION_ID = 1; private static final int NOTIFY_MODE_FOREGROUND = 1; private static final int NOTIFY_MODE_BACKGROUND = 0; diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.java b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.java index c0360102..777b96ca 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.java +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationImpl24.java @@ -1,5 +1,10 @@ package code.name.monkey.retromusic.service.notification; +import static code.name.monkey.retromusic.Constants.ACTION_QUIT; +import static code.name.monkey.retromusic.Constants.ACTION_REWIND; +import static code.name.monkey.retromusic.Constants.ACTION_SKIP; +import static code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE; + import android.app.PendingIntent; import android.content.ComponentName; import android.content.Intent; @@ -11,11 +16,6 @@ import android.os.Build; import android.support.v4.app.NotificationCompat; import android.support.v4.media.app.NotificationCompat.MediaStyle; import android.text.Html; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.animation.GlideAnimation; -import com.bumptech.glide.request.target.SimpleTarget; - import code.name.monkey.retromusic.Constants; import code.name.monkey.retromusic.R; import code.name.monkey.retromusic.RetroApplication; @@ -26,121 +26,118 @@ import code.name.monkey.retromusic.service.MusicService; import code.name.monkey.retromusic.ui.activities.MainActivity; import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.util.RetroColorUtil; - -import static code.name.monkey.retromusic.Constants.ACTION_QUIT; -import static code.name.monkey.retromusic.Constants.ACTION_REWIND; -import static code.name.monkey.retromusic.Constants.ACTION_SKIP; -import static code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE; +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.animation.GlideAnimation; +import com.bumptech.glide.request.target.SimpleTarget; public class PlayingNotificationImpl24 extends PlayingNotification { - @Override - public synchronized void update() { - stopped = false; + @Override + public synchronized void update() { + stopped = false; - final Song song = service.getCurrentSong(); - final boolean isPlaying = service.isPlaying(); + final Song song = service.getCurrentSong(); + final boolean isPlaying = service.isPlaying(); + final int playButtonResId = isPlaying ? R.drawable.ic_pause_white_24dp : + R.drawable.ic_play_arrow_white_24dp; - final int playButtonResId = isPlaying ? R.drawable.ic_pause_white_24dp : - R.drawable.ic_play_arrow_white_24dp; + Intent action = new Intent(service, MainActivity.class); + action.putExtra("expand", true); + action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + final PendingIntent clickIntent = PendingIntent + .getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT); - Intent action = new Intent(service, MainActivity.class); - action.putExtra("expand", true); - action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - final PendingIntent clickIntent = PendingIntent - .getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT); + final ComponentName serviceName = new ComponentName(service, MusicService.class); + Intent intent = new Intent(Constants.ACTION_QUIT); + intent.setComponent(serviceName); + final PendingIntent deleteIntent = PendingIntent.getService(service, 0, intent, 0); - final ComponentName serviceName = new ComponentName(service, MusicService.class); - Intent intent = new Intent(Constants.ACTION_QUIT); - intent.setComponent(serviceName); - final PendingIntent deleteIntent = PendingIntent.getService(service, 0, intent, 0); + final int bigNotificationImageSize = service.getResources() + .getDimensionPixelSize(R.dimen.notification_big_image_size); + service.runOnUiThread(() -> SongGlideRequest.Builder.from(Glide.with(service), song) + .checkIgnoreMediaStore(service) + .generatePalette(service).build() + .into(new SimpleTarget(bigNotificationImageSize, + bigNotificationImageSize) { + @Override + public void onResourceReady(BitmapPaletteWrapper resource, + GlideAnimation glideAnimation) { + update(resource.getBitmap(), + PreferenceUtil.getInstance(RetroApplication.getInstance()).isDominantColor() ? + RetroColorUtil.getDominantColor(resource.getBitmap(), Color.TRANSPARENT) : + RetroColorUtil.getColor(resource.getPalette(), Color.TRANSPARENT)); + } - final int bigNotificationImageSize = service.getResources() - .getDimensionPixelSize(R.dimen.notification_big_image_size); - service.runOnUiThread(() -> SongGlideRequest.Builder.from(Glide.with(service), song) - .checkIgnoreMediaStore(service) - .generatePalette(service).build() - .into(new SimpleTarget(bigNotificationImageSize, - bigNotificationImageSize) { - @Override - public void onResourceReady(BitmapPaletteWrapper resource, - GlideAnimation glideAnimation) { - update(resource.getBitmap(), - PreferenceUtil.getInstance(RetroApplication.getInstance()).isDominantColor() ? - RetroColorUtil.getDominantColor(resource.getBitmap(), Color.TRANSPARENT) : - RetroColorUtil.getColor(resource.getPalette(), Color.TRANSPARENT)); - } + @Override + public void onLoadFailed(Exception e, Drawable errorDrawable) { + update(null, Color.TRANSPARENT); + } - @Override - public void onLoadFailed(Exception e, Drawable errorDrawable) { - update(null, Color.TRANSPARENT); - } + void update(Bitmap bitmap, int color) { + if (bitmap == null) { + bitmap = BitmapFactory + .decodeResource(service.getResources(), R.drawable.default_album_art); + } + NotificationCompat.Action playPauseAction = new NotificationCompat.Action( + playButtonResId, + service.getString(R.string.action_play_pause), + retrievePlaybackAction(ACTION_TOGGLE_PAUSE)); - void update(Bitmap bitmap, int color) { - if (bitmap == null) { - bitmap = BitmapFactory - .decodeResource(service.getResources(), R.drawable.default_album_art); - } - NotificationCompat.Action playPauseAction = new NotificationCompat.Action( - playButtonResId, - service.getString(R.string.action_play_pause), - retrievePlaybackAction(ACTION_TOGGLE_PAUSE)); + NotificationCompat.Action closeAction = new NotificationCompat.Action( + R.drawable.ic_close_white_24dp, + service.getString(R.string.close_notification), + retrievePlaybackAction(ACTION_QUIT)); - NotificationCompat.Action closeAction = new NotificationCompat.Action( - R.drawable.ic_close_white_24dp, - service.getString(R.string.close_notification), - retrievePlaybackAction(ACTION_QUIT)); + NotificationCompat.Action previousAction = new NotificationCompat.Action( + R.drawable.ic_skip_previous_white_24dp, + service.getString(R.string.action_previous), + retrievePlaybackAction(ACTION_REWIND)); - NotificationCompat.Action previousAction = new NotificationCompat.Action( - R.drawable.ic_skip_previous_white_24dp, - service.getString(R.string.action_previous), - retrievePlaybackAction(ACTION_REWIND)); + NotificationCompat.Action nextAction = new NotificationCompat.Action( + R.drawable.ic_skip_next_white_24dp, + service.getString(R.string.action_next), + retrievePlaybackAction(ACTION_SKIP)); - NotificationCompat.Action nextAction = new NotificationCompat.Action( - R.drawable.ic_skip_next_white_24dp, - service.getString(R.string.action_next), - retrievePlaybackAction(ACTION_SKIP)); + NotificationCompat.Builder builder = new NotificationCompat.Builder(service, + NOTIFICATION_CHANNEL_ID) + .setSmallIcon(R.drawable.ic_notification) + .setLargeIcon(bitmap) + .setContentIntent(clickIntent) + .setDeleteIntent(deleteIntent) + .setContentTitle(Html.fromHtml("" + song.title + "")) + .setContentText(song.artistName) + .setSubText(Html.fromHtml("" + song.albumName + "")) + .setOngoing(isPlaying) + .setShowWhen(false) + .addAction(previousAction) + .addAction(playPauseAction) + .addAction(nextAction) + .addAction(closeAction); - NotificationCompat.Builder builder = new NotificationCompat.Builder(service, - NOTIFICATION_CHANNEL_ID) - .setSmallIcon(R.drawable.ic_notification) - .setLargeIcon(bitmap) - .setContentIntent(clickIntent) - .setDeleteIntent(deleteIntent) - .setContentTitle(Html.fromHtml("" + song.title + "")) - .setContentText(song.artistName) - .setSubText(Html.fromHtml("" + song.albumName + "")) - .setOngoing(isPlaying) - .setShowWhen(false) - .addAction(previousAction) - .addAction(playPauseAction) - .addAction(nextAction) - .addAction(closeAction); + if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + builder.setStyle(new MediaStyle() + .setMediaSession(service.getMediaSession().getSessionToken()) + .setShowActionsInCompactView(0, 1, 2, 3, 4)) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); + if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && PreferenceUtil + .getInstance(service).coloredNotification()) { + builder.setColor(color); + } + } - if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { - builder.setStyle(new MediaStyle() - .setMediaSession(service.getMediaSession().getSessionToken()) - .setShowActionsInCompactView(0, 1, 2, 3, 4)) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC); - if (Build.VERSION.SDK_INT <= Build.VERSION_CODES.O && PreferenceUtil - .getInstance(service).coloredNotification()) { - builder.setColor(color); - } - } + if (stopped) { + return; // notification has been stopped before loading was finished + } + updateNotifyModeAndPostNotification(builder.build()); + } + })); + } - if (stopped) { - return; // notification has been stopped before loading was finished - } - updateNotifyModeAndPostNotification(builder.build()); - } - })); - } - - private PendingIntent retrievePlaybackAction(final String action) { - final ComponentName serviceName = new ComponentName(service, MusicService.class); - Intent intent = new Intent(action); - intent.setComponent(serviceName); - return PendingIntent.getService(service, 0, intent, 0); - } + private PendingIntent retrievePlaybackAction(final String action) { + final ComponentName serviceName = new ComponentName(service, MusicService.class); + Intent intent = new Intent(action); + intent.setComponent(serviceName); + return PendingIntent.getService(service, 0, intent, 0); + } } \ No newline at end of file diff --git a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.java b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.java index 6a305c6c..7956ed23 100644 --- a/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.java +++ b/app/src/main/java/code/name/monkey/retromusic/service/notification/PlayingNotificationOreo.java @@ -1,5 +1,11 @@ package code.name.monkey.retromusic.service.notification; +import static code.name.monkey.retromusic.Constants.ACTION_QUIT; +import static code.name.monkey.retromusic.Constants.ACTION_REWIND; +import static code.name.monkey.retromusic.Constants.ACTION_SKIP; +import static code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE; +import static code.name.monkey.retromusic.util.RetroUtil.createBitmap; + import android.app.PendingIntent; import android.content.ComponentName; import android.content.Context; @@ -11,12 +17,6 @@ import android.graphics.drawable.Drawable; import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; import android.widget.RemoteViews; - -import com.bumptech.glide.Glide; -import com.bumptech.glide.request.animation.GlideAnimation; -import com.bumptech.glide.request.target.SimpleTarget; -import com.bumptech.glide.request.target.Target; - import code.name.monkey.appthemehelper.util.ColorUtil; import code.name.monkey.appthemehelper.util.MaterialValueHelper; import code.name.monkey.retromusic.R; @@ -28,217 +28,219 @@ import code.name.monkey.retromusic.ui.activities.MainActivity; import code.name.monkey.retromusic.util.PreferenceUtil; import code.name.monkey.retromusic.util.RetroUtil; import code.name.monkey.retromusic.util.color.MediaNotificationProcessor; - -import static code.name.monkey.retromusic.Constants.ACTION_QUIT; -import static code.name.monkey.retromusic.Constants.ACTION_REWIND; -import static code.name.monkey.retromusic.Constants.ACTION_SKIP; -import static code.name.monkey.retromusic.Constants.ACTION_TOGGLE_PAUSE; -import static code.name.monkey.retromusic.util.RetroUtil.createBitmap; +import com.bumptech.glide.Glide; +import com.bumptech.glide.request.animation.GlideAnimation; +import com.bumptech.glide.request.target.SimpleTarget; +import com.bumptech.glide.request.target.Target; /** * @author Hemanth S (h4h13). */ public class PlayingNotificationOreo extends PlayingNotification { - private Target target; + private Target target; - private RemoteViews getCombinedRemoteViews(boolean collapsed, Song song) { - RemoteViews remoteViews = new RemoteViews(service.getPackageName(), - collapsed ? R.layout.layout_notification_collapsed : R.layout.layout_notification_expanded); + private RemoteViews getCombinedRemoteViews(boolean collapsed, Song song) { + RemoteViews remoteViews = new RemoteViews(service.getPackageName(), + collapsed ? R.layout.layout_notification_collapsed : R.layout.layout_notification_expanded); - remoteViews.setTextViewText(R.id.appName, service.getString(R.string.app_name) + " • " + song.albumName); - remoteViews.setTextViewText(R.id.title, song.title); - remoteViews.setTextViewText(R.id.subtitle, song.artistName); + remoteViews.setTextViewText(R.id.appName, + service.getString(R.string.app_name) + " • " + song.albumName); + remoteViews.setTextViewText(R.id.title, song.title); + remoteViews.setTextViewText(R.id.subtitle, song.artistName); - TypedArray typedArray = service - .obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground}); - int selectableItemBackground = typedArray.getResourceId(0, 0); - typedArray.recycle(); + TypedArray typedArray = service + .obtainStyledAttributes(new int[]{android.R.attr.selectableItemBackground}); + int selectableItemBackground = typedArray.getResourceId(0, 0); + typedArray.recycle(); - remoteViews.setInt(R.id.content, "setBackgroundResource", selectableItemBackground); + remoteViews.setInt(R.id.content, "setBackgroundResource", selectableItemBackground); - linkButtons(remoteViews); + linkButtons(remoteViews); - //setNotificationContent(remoteViews, ColorUtil.isColorLight(backgroundColor)); - return remoteViews; - } + //setNotificationContent(remoteViews, ColorUtil.isColorLight(backgroundColor)); + return remoteViews; + } - @Override - public void update() { - stopped = false; - final Song song = service.getCurrentSong(); - final boolean isPlaying = service.isPlaying(); + @Override + public void update() { + stopped = false; + final Song song = service.getCurrentSong(); + final boolean isPlaying = service.isPlaying(); - final RemoteViews notificationLayout = getCombinedRemoteViews(true, song); - final RemoteViews notificationLayoutBig = getCombinedRemoteViews(false, song); + final RemoteViews notificationLayout = getCombinedRemoteViews(true, song); + final RemoteViews notificationLayoutBig = getCombinedRemoteViews(false, song); - Intent action = new Intent(service, MainActivity.class); - action.putExtra("expand", true); - action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); + Intent action = new Intent(service, MainActivity.class); + action.putExtra("expand", true); + action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP); - final PendingIntent clickIntent = PendingIntent - .getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT); - final PendingIntent deleteIntent = buildPendingIntent(service, ACTION_QUIT, null); + final PendingIntent clickIntent = PendingIntent + .getActivity(service, 0, action, PendingIntent.FLAG_UPDATE_CURRENT); + final PendingIntent deleteIntent = buildPendingIntent(service, ACTION_QUIT, null); - final NotificationCompat.Builder builder = new NotificationCompat.Builder(service, - NOTIFICATION_CHANNEL_ID) - .setSmallIcon(R.drawable.ic_notification) - .setContentIntent(clickIntent) - .setDeleteIntent(deleteIntent) - .setCategory(NotificationCompat.CATEGORY_SERVICE) - .setPriority(NotificationCompat.PRIORITY_MAX) - .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) - .setCustomContentView(notificationLayout) - .setCustomBigContentView(notificationLayoutBig) - .setOngoing(isPlaying); + final NotificationCompat.Builder builder = new NotificationCompat.Builder(service, + NOTIFICATION_CHANNEL_ID) + .setSmallIcon(R.drawable.ic_notification) + .setContentIntent(clickIntent) + .setDeleteIntent(deleteIntent) + .setCategory(NotificationCompat.CATEGORY_SERVICE) + .setPriority(NotificationCompat.PRIORITY_MAX) + .setVisibility(NotificationCompat.VISIBILITY_PUBLIC) + .setCustomContentView(notificationLayout) + .setCustomBigContentView(notificationLayoutBig) + .setOngoing(isPlaying); - final int bigNotificationImageSize = service.getResources() - .getDimensionPixelSize(R.dimen.notification_big_image_size); - service.runOnUiThread(new Runnable() { - @Override - public void run() { - if (target != null) { - Glide.clear(target); - } - target = SongGlideRequest.Builder.from(Glide.with(service), song) - .checkIgnoreMediaStore(service) - .generatePalette(service).build() - .into(new SimpleTarget(bigNotificationImageSize, - bigNotificationImageSize) { - @Override - public void onResourceReady(BitmapPaletteWrapper resource, - GlideAnimation glideAnimation) { - - MediaNotificationProcessor mediaNotificationProcessor = new MediaNotificationProcessor(service, service, new MediaNotificationProcessor.onColorThing() { - @Override - public void bothColor(int i, int i2) { - update(resource.getBitmap(), i, i2); - } - }); - mediaNotificationProcessor.processNotification(resource.getBitmap()); - - } - - @Override - public void onLoadFailed(Exception e, Drawable errorDrawable) { - super.onLoadFailed(e, errorDrawable); - update(null, Color.WHITE, Color.BLACK); - } - - private void update(@Nullable Bitmap bitmap, int bgColor, int textColor) { - if (bitmap != null) { - notificationLayout.setImageViewBitmap(R.id.largeIcon, bitmap); - notificationLayoutBig.setImageViewBitmap(R.id.largeIcon, bitmap); - } else { - notificationLayout - .setImageViewResource(R.id.largeIcon, R.drawable.default_album_art); - notificationLayoutBig - .setImageViewResource(R.id.largeIcon, R.drawable.default_album_art); - } - - if (!PreferenceUtil.getInstance(service).coloredNotification()) { - bgColor = Color.WHITE; - } - setBackgroundColor(bgColor); - setNotificationContent(ColorUtil.isColorLight(bgColor)); - - if (stopped) { - return; // notification has been stopped before loading was finished - } - updateNotifyModeAndPostNotification(builder.build()); - } - - private void setBackgroundColor(int color) { - - notificationLayout.setInt(R.id.image, "setBackgroundColor", color); - notificationLayoutBig.setInt(R.id.image, "setBackgroundColor", color); - - notificationLayout.setInt(R.id.foregroundImage, "setColorFilter", color); - notificationLayoutBig.setInt(R.id.foregroundImage, "setColorFilter", color); - } - - private void setNotificationContent(boolean dark) { - int primary = MaterialValueHelper.getPrimaryTextColor(service, dark); - int secondary = MaterialValueHelper.getSecondaryTextColor(service, dark); - - Bitmap close = createBitmap( - RetroUtil.getTintedVectorDrawable(service, R.drawable.ic_close_white_24dp, primary), - 1.3f); - Bitmap prev = createBitmap( - RetroUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, - primary), 1.3f); - Bitmap next = createBitmap( - RetroUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, - primary), 1.3f); - Bitmap playPause = createBitmap(RetroUtil.getTintedVectorDrawable(service, - isPlaying ? R.drawable.ic_pause_white_24dp - : R.drawable.ic_play_arrow_white_24dp, primary), 1.3f); - - notificationLayout.setTextColor(R.id.title, primary); - notificationLayout.setTextColor(R.id.subtitle, secondary); - notificationLayout.setTextColor(R.id.appName, secondary); - - notificationLayout.setImageViewBitmap(R.id.action_prev, prev); - notificationLayout.setImageViewBitmap(R.id.action_next, next); - notificationLayout.setImageViewBitmap(R.id.action_play_pause, playPause); - - notificationLayoutBig.setTextColor(R.id.title, primary); - notificationLayoutBig.setTextColor(R.id.subtitle, secondary); - notificationLayoutBig.setTextColor(R.id.appName, secondary); - - notificationLayoutBig.setImageViewBitmap(R.id.action_quit, close); - notificationLayoutBig.setImageViewBitmap(R.id.action_prev, prev); - notificationLayoutBig.setImageViewBitmap(R.id.action_next, next); - notificationLayoutBig.setImageViewBitmap(R.id.action_play_pause, playPause); - - notificationLayout.setImageViewBitmap(R.id.smallIcon, - createBitmap(RetroUtil.getTintedVectorDrawable(service, R.drawable.ic_notification, secondary), 0.6f)); - notificationLayoutBig.setImageViewBitmap(R.id.smallIcon, - createBitmap(RetroUtil.getTintedVectorDrawable(service, R.drawable.ic_notification, secondary), 0.6f)); - - notificationLayout.setInt(R.id.arrow, "setColorFilter", secondary); - notificationLayoutBig.setInt(R.id.arrow, "setColorFilter", secondary); - - } - }); - } - }); - - if (stopped) { - return; // notification has been stopped before loading was finished + final int bigNotificationImageSize = service.getResources() + .getDimensionPixelSize(R.dimen.notification_big_image_size); + service.runOnUiThread(new Runnable() { + @Override + public void run() { + if (target != null) { + Glide.clear(target); } - updateNotifyModeAndPostNotification(builder.build()); + target = SongGlideRequest.Builder.from(Glide.with(service), song) + .checkIgnoreMediaStore(service) + .generatePalette(service).build() + .into(new SimpleTarget(bigNotificationImageSize, + bigNotificationImageSize) { + @Override + public void onResourceReady(BitmapPaletteWrapper resource, + GlideAnimation glideAnimation) { + + MediaNotificationProcessor mediaNotificationProcessor = new MediaNotificationProcessor( + service, service, (i, i2) -> update(resource.getBitmap(), i, i2)); + mediaNotificationProcessor.processNotification(resource.getBitmap()); + + } + + @Override + public void onLoadFailed(Exception e, Drawable errorDrawable) { + super.onLoadFailed(e, errorDrawable); + update(null, Color.WHITE, Color.BLACK); + } + + private void update(@Nullable Bitmap bitmap, int bgColor, int textColor) { + if (bitmap != null) { + notificationLayout.setImageViewBitmap(R.id.largeIcon, bitmap); + notificationLayoutBig.setImageViewBitmap(R.id.largeIcon, bitmap); + } else { + notificationLayout + .setImageViewResource(R.id.largeIcon, R.drawable.default_album_art); + notificationLayoutBig + .setImageViewResource(R.id.largeIcon, R.drawable.default_album_art); + } + + if (!PreferenceUtil.getInstance(service).coloredNotification()) { + bgColor = Color.WHITE; + } + setBackgroundColor(bgColor); + setNotificationContent(ColorUtil.isColorLight(bgColor)); + + if (stopped) { + return; // notification has been stopped before loading was finished + } + updateNotifyModeAndPostNotification(builder.build()); + } + + private void setBackgroundColor(int color) { + + notificationLayout.setInt(R.id.image, "setBackgroundColor", color); + notificationLayoutBig.setInt(R.id.image, "setBackgroundColor", color); + + notificationLayout.setInt(R.id.foregroundImage, "setColorFilter", color); + notificationLayoutBig.setInt(R.id.foregroundImage, "setColorFilter", color); + } + + private void setNotificationContent(boolean dark) { + int primary = MaterialValueHelper.getPrimaryTextColor(service, dark); + int secondary = MaterialValueHelper.getSecondaryTextColor(service, dark); + + Bitmap close = createBitmap( + RetroUtil + .getTintedVectorDrawable(service, R.drawable.ic_close_white_24dp, primary), + NOTIFICATION_CONTROLS_SIZE_MULTIPLIER); + Bitmap prev = createBitmap( + RetroUtil + .getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, + primary), NOTIFICATION_CONTROLS_SIZE_MULTIPLIER); + Bitmap next = createBitmap( + RetroUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, + primary), NOTIFICATION_CONTROLS_SIZE_MULTIPLIER); + Bitmap playPause = createBitmap(RetroUtil.getTintedVectorDrawable(service, + isPlaying ? R.drawable.ic_pause_white_24dp + : R.drawable.ic_play_arrow_white_24dp, primary), + NOTIFICATION_CONTROLS_SIZE_MULTIPLIER); + + notificationLayout.setTextColor(R.id.title, primary); + notificationLayout.setTextColor(R.id.subtitle, secondary); + notificationLayout.setTextColor(R.id.appName, secondary); + + notificationLayout.setImageViewBitmap(R.id.action_prev, prev); + notificationLayout.setImageViewBitmap(R.id.action_next, next); + notificationLayout.setImageViewBitmap(R.id.action_play_pause, playPause); + + notificationLayoutBig.setTextColor(R.id.title, primary); + notificationLayoutBig.setTextColor(R.id.subtitle, secondary); + notificationLayoutBig.setTextColor(R.id.appName, secondary); + + notificationLayoutBig.setImageViewBitmap(R.id.action_quit, close); + notificationLayoutBig.setImageViewBitmap(R.id.action_prev, prev); + notificationLayoutBig.setImageViewBitmap(R.id.action_next, next); + notificationLayoutBig.setImageViewBitmap(R.id.action_play_pause, playPause); + + notificationLayout.setImageViewBitmap(R.id.smallIcon, + createBitmap(RetroUtil + .getTintedVectorDrawable(service, R.drawable.ic_notification, secondary), + 0.6f)); + notificationLayoutBig.setImageViewBitmap(R.id.smallIcon, + createBitmap(RetroUtil + .getTintedVectorDrawable(service, R.drawable.ic_notification, secondary), + 0.6f)); + + notificationLayout.setInt(R.id.arrow, "setColorFilter", secondary); + notificationLayoutBig.setInt(R.id.arrow, "setColorFilter", secondary); + + } + }); + } + }); + + if (stopped) { + return; // notification has been stopped before loading was finished } + updateNotifyModeAndPostNotification(builder.build()); + } - private PendingIntent buildPendingIntent(Context context, final String action, - final ComponentName serviceName) { - Intent intent = new Intent(action); - intent.setComponent(serviceName); - return PendingIntent.getService(context, 0, intent, 0); - } + private PendingIntent buildPendingIntent(Context context, final String action, + final ComponentName serviceName) { + Intent intent = new Intent(action); + intent.setComponent(serviceName); + return PendingIntent.getService(context, 0, intent, 0); + } - private void linkButtons(final RemoteViews notificationLayout) { - PendingIntent pendingIntent; + private void linkButtons(final RemoteViews notificationLayout) { + PendingIntent pendingIntent; - final ComponentName serviceName = new ComponentName(service, MusicService.class); + final ComponentName serviceName = new ComponentName(service, MusicService.class); - // Previous track - pendingIntent = buildPendingIntent(service, ACTION_REWIND, serviceName); - notificationLayout.setOnClickPendingIntent(R.id.action_prev, pendingIntent); + // Previous track + pendingIntent = buildPendingIntent(service, ACTION_REWIND, serviceName); + notificationLayout.setOnClickPendingIntent(R.id.action_prev, pendingIntent); - // Play and pause - pendingIntent = buildPendingIntent(service, ACTION_TOGGLE_PAUSE, serviceName); - notificationLayout.setOnClickPendingIntent(R.id.action_play_pause, pendingIntent); + // Play and pause + pendingIntent = buildPendingIntent(service, ACTION_TOGGLE_PAUSE, serviceName); + notificationLayout.setOnClickPendingIntent(R.id.action_play_pause, pendingIntent); - // Next track - pendingIntent = buildPendingIntent(service, ACTION_SKIP, serviceName); - notificationLayout.setOnClickPendingIntent(R.id.action_next, pendingIntent); + // Next track + pendingIntent = buildPendingIntent(service, ACTION_SKIP, serviceName); + notificationLayout.setOnClickPendingIntent(R.id.action_next, pendingIntent); - // Close - pendingIntent = buildPendingIntent(service, ACTION_QUIT, serviceName); - notificationLayout.setOnClickPendingIntent(R.id.action_quit, pendingIntent); - } + // Close + pendingIntent = buildPendingIntent(service, ACTION_QUIT, serviceName); + notificationLayout.setOnClickPendingIntent(R.id.action_quit, pendingIntent); + } }