From 357ef1df6974e62804304b832acbd20c5580d11f Mon Sep 17 00:00:00 2001 From: Karim Abou Zeid Date: Sat, 11 Jul 2015 15:41:18 +0200 Subject: [PATCH] Notification text color changes to match the background. Cleaned up notification related code. --- .../helper/PlayingNotificationHelper.java | 108 ++++++++---- .../res/drawable-hdpi/ic_close_black_24dp.png | Bin 0 -> 244 bytes .../res/drawable-mdpi/ic_close_black_24dp.png | Bin 0 -> 195 bytes .../drawable-xhdpi/ic_close_black_24dp.png | Bin 0 -> 314 bytes .../drawable-xxhdpi/ic_close_black_24dp.png | Bin 0 -> 383 bytes .../drawable-xxxhdpi/ic_close_black_24dp.png | Bin 0 -> 513 bytes ...cation_controller.xml => notification.xml} | 7 +- ...ontroller_big.xml => notification_big.xml} | 10 +- .../notification_controller_big_colored.xml | 160 ------------------ .../notification_controller_colored.xml | 141 --------------- app/src/main/res/values-v21/colors.xml | 13 -- app/src/main/res/values-v21/styles.xml | 5 - app/src/main/res/values/colors.xml | 9 +- app/src/main/res/values/styles.xml | 4 - app/src/main/res/values/styles_parents.xml | 9 - 15 files changed, 86 insertions(+), 380 deletions(-) create mode 100644 app/src/main/res/drawable-hdpi/ic_close_black_24dp.png create mode 100644 app/src/main/res/drawable-mdpi/ic_close_black_24dp.png create mode 100644 app/src/main/res/drawable-xhdpi/ic_close_black_24dp.png create mode 100644 app/src/main/res/drawable-xxhdpi/ic_close_black_24dp.png create mode 100644 app/src/main/res/drawable-xxxhdpi/ic_close_black_24dp.png rename app/src/main/res/layout/{notification_controller.xml => notification.xml} (93%) rename app/src/main/res/layout/{notification_controller_big.xml => notification_big.xml} (92%) delete mode 100644 app/src/main/res/layout/notification_controller_big_colored.xml delete mode 100644 app/src/main/res/layout/notification_controller_colored.xml delete mode 100644 app/src/main/res/values-v21/colors.xml 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 97c91ce7..63e5b602 100644 --- a/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java +++ b/app/src/main/java/com/kabouzeid/gramophone/helper/PlayingNotificationHelper.java @@ -13,6 +13,8 @@ import android.content.Context; import android.content.Intent; import android.content.IntentFilter; import android.graphics.Bitmap; +import android.graphics.Color; +import android.os.Build; import android.support.annotation.NonNull; import android.support.annotation.Nullable; import android.support.v4.app.NotificationCompat; @@ -26,12 +28,15 @@ import com.kabouzeid.gramophone.service.MusicService; import com.kabouzeid.gramophone.ui.activities.MainActivity; import com.kabouzeid.gramophone.util.MusicUtil; import com.kabouzeid.gramophone.util.PreferenceUtil; +import com.nostra13.universalimageloader.core.DisplayImageOptions; import com.nostra13.universalimageloader.core.ImageLoader; import com.nostra13.universalimageloader.core.assist.FailReason; import com.nostra13.universalimageloader.core.assist.ImageSize; import com.nostra13.universalimageloader.core.assist.ViewScaleType; +import com.nostra13.universalimageloader.core.imageaware.ImageAware; import com.nostra13.universalimageloader.core.imageaware.NonViewAware; import com.nostra13.universalimageloader.core.listener.SimpleImageLoadingListener; +import com.nostra13.universalimageloader.core.process.BitmapProcessor; public class PlayingNotificationHelper { @@ -53,13 +58,13 @@ public class PlayingNotificationHelper { private Song currentSong; private boolean isPlaying; - private String currentAlbumArtUri; + private boolean isDark; private boolean isColored; private boolean isReceiverRegistered; private boolean isNotificationShown; - private int bigNotificationImageSize; + private ImageAware notificationImageAware; @NonNull final IntentFilter intentFilter; @@ -72,7 +77,8 @@ public class PlayingNotificationHelper { intentFilter = new IntentFilter(); intentFilter.addAction(ACTION_NOTIFICATION_COLOR_PREFERENCE_CHANGED); - bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size); + int bigNotificationImageSize = service.getResources().getDimensionPixelSize(R.dimen.notification_big_image_size); + notificationImageAware = new NonViewAware(new ImageSize(bigNotificationImageSize, bigNotificationImageSize), ViewScaleType.CROP); } @NonNull @@ -106,10 +112,8 @@ public class PlayingNotificationHelper { isReceiverRegistered = true; isNotificationShown = true; - notificationLayout = new RemoteViews(service.getPackageName(), - isColored ? R.layout.notification_controller_colored : R.layout.notification_controller); - notificationLayoutExpanded = new RemoteViews(service.getPackageName(), - isColored ? R.layout.notification_controller_big_colored : R.layout.notification_controller_big); + notificationLayout = new RemoteViews(service.getPackageName(), R.layout.notification); + notificationLayoutExpanded = new RemoteViews(service.getPackageName(), R.layout.notification_big); notification = new NotificationCompat.Builder(service) .setSmallIcon(R.drawable.ic_notification) @@ -148,8 +152,7 @@ public class PlayingNotificationHelper { notificationLayoutExpanded.setOnClickPendingIntent(R.id.action_quit, retrievePlaybackActions(4)); - notificationLayoutExpanded.setImageViewResource(R.id.action_play_pause, - isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_arrow_white_36dp); + notificationLayoutExpanded.setImageViewResource(R.id.action_play_pause, getPlayPauseRes()); } private void setUpPlaybackActions() { @@ -162,8 +165,7 @@ public class PlayingNotificationHelper { notificationLayout.setOnClickPendingIntent(R.id.action_prev, retrievePlaybackActions(3)); - notificationLayout.setImageViewResource(R.id.action_play_pause, - isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_arrow_white_36dp); + notificationLayout.setImageViewResource(R.id.action_play_pause, getPlayPauseRes()); } private PendingIntent retrievePlaybackActions(final int which) { @@ -214,41 +216,55 @@ public class PlayingNotificationHelper { } private void loadAlbumArt() { - currentAlbumArtUri = MusicUtil.getSongImageLoaderString(currentSong); + ImageLoader.getInstance().cancelDisplayTask(notificationImageAware); ImageLoader.getInstance().displayImage( - currentAlbumArtUri, - new NonViewAware(new ImageSize(bigNotificationImageSize, bigNotificationImageSize), ViewScaleType.CROP), + MusicUtil.getSongImageLoaderString(currentSong), + notificationImageAware, + new DisplayImageOptions.Builder() + .postProcessor(new BitmapProcessor() { + @Override + public Bitmap process(Bitmap bitmap) { + setAlbumArt(bitmap); + return bitmap; + } + }).build(), new SimpleImageLoadingListener() { @Override public void onLoadingComplete(String imageUri, View view, Bitmap loadedImage) { - if (currentAlbumArtUri.equals(imageUri)) - setAlbumArt(loadedImage); + if (loadedImage == null) { + onLoadingFailed(imageUri, view, null); + } } @Override public void onLoadingFailed(String imageUri, View view, FailReason failReason) { - if (currentAlbumArtUri.equals(imageUri)) - setAlbumArt(null); + setAlbumArt(null); } }); } private void setAlbumArt(@Nullable Bitmap albumArt) { + boolean backgroundColorSet = false; if (albumArt != null) { notificationLayout.setImageViewBitmap(R.id.icon, albumArt); notificationLayoutExpanded.setImageViewBitmap(R.id.icon, albumArt); if (isColored) { - int defaultColor = service.getResources().getColor(R.color.default_colored_notification_color); - int newColor = Palette.from(albumArt).resizeBitmapSize(100).generate().getVibrantColor(defaultColor); - setBackgroundColor(newColor); + Palette.Swatch vibrantSwatch = Palette.from(albumArt).resizeBitmapSize(100).generate().getVibrantSwatch(); + if (vibrantSwatch != null) { + int bgColor = vibrantSwatch.getRgb(); + setBackgroundColor(bgColor); + setNotificationTextDark((Color.red(bgColor) * 0.299 + Color.green(bgColor) * 0.587 + Color.blue(bgColor) * 0.114) > 186); + backgroundColorSet = true; + } } } 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); - } + } + + if (!backgroundColorSet) { + setBackgroundColor(Color.TRANSPARENT); + setNotificationTextDark(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP); } if (notification != null) { @@ -270,20 +286,50 @@ public class PlayingNotificationHelper { isNotificationShown = false; } - public void updatePlayState(final boolean isPlaying) { - this.isPlaying = isPlaying; + public void updatePlayState(final boolean setPlaying) { + isPlaying = setPlaying; if (notification == null) { updateNotification(); } + int playPauseRes = getPlayPauseRes(); if (notificationLayout != null) { - notificationLayout.setImageViewResource(R.id.action_play_pause, - isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_arrow_white_36dp); + notificationLayout.setImageViewResource(R.id.action_play_pause, playPauseRes); } if (notificationLayoutExpanded != null) { - notificationLayoutExpanded.setImageViewResource(R.id.action_play_pause, - isPlaying ? R.drawable.ic_pause_white_36dp : R.drawable.ic_play_arrow_white_36dp); + notificationLayoutExpanded.setImageViewResource(R.id.action_play_pause, playPauseRes); } notificationManager.notify(NOTIFICATION_ID, notification); } + + private void setNotificationTextDark(boolean setDark) { + isDark = setDark; + + if (notificationLayout != null && notificationLayoutExpanded != null) { + int darkContentColor = service.getResources().getColor(R.color.notification_dark_text_content_color); + int darkContentSecondaryColor = service.getResources().getColor(R.color.notification_dark_text_secondary_content_color); + int contentColor = service.getResources().getColor(R.color.notification_content_color); + int contentSecondaryColor = service.getResources().getColor(R.color.notification_secondary_content_color); + + notificationLayout.setTextColor(R.id.title, setDark ? darkContentColor : contentColor); + notificationLayout.setTextColor(R.id.text, setDark ? darkContentSecondaryColor : contentSecondaryColor); + notificationLayout.setImageViewResource(R.id.action_prev, setDark ? R.drawable.ic_skip_previous_black_36dp : R.drawable.ic_skip_previous_white_36dp); + notificationLayout.setImageViewResource(R.id.action_play_pause, getPlayPauseRes()); + notificationLayout.setImageViewResource(R.id.action_next, setDark ? R.drawable.ic_skip_next_black_36dp : R.drawable.ic_skip_next_white_36dp); + + notificationLayoutExpanded.setTextColor(R.id.title, setDark ? darkContentColor : contentColor); + notificationLayoutExpanded.setTextColor(R.id.text, setDark ? darkContentSecondaryColor : contentSecondaryColor); + notificationLayoutExpanded.setTextColor(R.id.text2, setDark ? darkContentSecondaryColor : contentSecondaryColor); + notificationLayoutExpanded.setImageViewResource(R.id.action_prev, setDark ? R.drawable.ic_skip_previous_black_36dp : R.drawable.ic_skip_previous_white_36dp); + notificationLayoutExpanded.setImageViewResource(R.id.action_play_pause, getPlayPauseRes()); + notificationLayoutExpanded.setImageViewResource(R.id.action_next, setDark ? R.drawable.ic_skip_next_black_36dp : R.drawable.ic_skip_next_white_36dp); + notificationLayoutExpanded.setImageViewResource(R.id.action_quit, setDark ? R.drawable.ic_close_black_24dp : R.drawable.ic_close_white_24dp); + } + } + + private int getPlayPauseRes() { + return isPlaying ? + (isDark ? R.drawable.ic_pause_black_36dp : R.drawable.ic_pause_white_36dp) : + (isDark ? R.drawable.ic_play_arrow_black_36dp : R.drawable.ic_play_arrow_white_36dp); + } } diff --git a/app/src/main/res/drawable-hdpi/ic_close_black_24dp.png b/app/src/main/res/drawable-hdpi/ic_close_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..0fcb0efb591bda540a11a52b1a9700103c6f1041 GIT binary patch literal 244 zcmeAS@N?(olHy`uVBq!ia0y~yU{C>J4mJh`hKCF@W-u@??DlkV45_&FcG_#M1_hqh zwcl5@zx)(bR(ZuIvB^Vn*G;9e1bZ%<-!o3k3{sltQL^%0ShL0bCic#>=yu&$j;9G_ zA0#x@9{2Es=uK(=_?-XEl9AnXKTO%=}f#hhwWN zulbMvR%e7oxP4w_-AI_XAR@tz{mV-2-POLcn6&xOb)12Lfx*+&&t;ucLK6U4GGXWd literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-mdpi/ic_close_black_24dp.png b/app/src/main/res/drawable-mdpi/ic_close_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..4342c7650734abdcd8c15c3a007192be2820039c GIT binary patch literal 195 zcmeAS@N?(olHy`uVBq!ia0y~yV2}V|4mJh`h6m-gKNuJox;$MRLn>}1CrGd=i@jj_ z7^fhn>aWuUjQ(hayp0Re5ond_J1>-SSYPmEG>`W>2i_e` zX$(i(9&d8#nboGeTkNLLDycqQj}>_qXLTL;Kc99{OWedGu4=?NIoHC_b4JqPkE)52 wy1TqxL_`g|zfDYPg5W3=9kmp00i_>zopr0FZG&tpET3 literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xhdpi/ic_close_black_24dp.png b/app/src/main/res/drawable-xhdpi/ic_close_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..6201097f015697e18c1c383882acfc5578756a2e GIT binary patch literal 314 zcmeAS@N?(olHy`uVBq!ia0y~yU@!n-4mJh`hH$2z?FekWCYlWR}uU*@{ zwoUk7YWAko4po^yFK+KE_Oz*C7v9)1?_mAwRWs~1Do*1#xZA8h=5R+)QgMY>ryj%q zdrb437FqnU7fO0itn!QXhx5y$x~@(-HC-(gKTJCX{=~hC(^LuM{WHr&^n)SeM6SSsC5la!Ix1P>5#OqTh-0#MLjRuGx^JQuN@cN5GrhF3&G5zki-p z)p*$L!Q-R8a>9|B&Ie-6Y-i^2KNB)PcYEit@&ko!xqoNpi!>>4G$~Ad!kkmhvn8JY S*eV7F1_n=8KbLh*2~7a!DuM9; literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxhdpi/ic_close_black_24dp.png b/app/src/main/res/drawable-xxhdpi/ic_close_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..2214293fa7431d63e00edc69c3fc554ce86580ef GIT binary patch literal 383 zcmeAS@N?(olHy`uVBq!ia0y~yVDJE84mJh`hS0a0-5D4d-8@|!Ln>~)y>*(e$w0v2 z;=2!*YihJl9lE}JFfNF+gY&L!g9iy$4gwa*wk5r3N50QM7xERY{le0 z7=CUz`uK=KX!B?Opi+zMiK~u8ets3wE!-W#dTzf*=)*OxtAyAU;tcDS{G5Hg!GkmppxNQm7k{P|}A3dVqoGPy2Fz61}3F`VhCuu^ET-i+bQ-wkqVw%ql zGtaa)JSse+=qa~hw!^Cy^XdB)VpSTCbx*pr{y}H_GaHM&(=D#vDY3O$$EbhIwMYpH c{_bU9Ss&GL=J>R43=9kmp00i_>zopr0B!A}B>(^b literal 0 HcmV?d00001 diff --git a/app/src/main/res/drawable-xxxhdpi/ic_close_black_24dp.png b/app/src/main/res/drawable-xxxhdpi/ic_close_black_24dp.png new file mode 100644 index 0000000000000000000000000000000000000000..9e965ad4fc27bab74e0af0abca7fdaf18e16db32 GIT binary patch literal 513 zcmeAS@N?(olHy`uVBq!ia0y~yU`POA4mJh`hDS5XEf^RWPk6dGhE&{oJ0~{luz>(u zY2!Z`wOr3j&FV{Q-@Z=_y2QLh$l?L}^|Mm5|Ax(KtUcXq!mN03S`ZTh3Yc-uciwUv z{>E#2PHsM39NPS+-)6bZeMcpcpU3mguCH9T_|*QhpKsxN54rqSMz; zQ8}?Wg8PrVU;64#A zS-(gqG3{sYKXrk`w4W{l6Z}~if4a<2s9)Kx=`tho-<0DWE(KG-f&vr#Tlh||R`%Yj zaXW{F_2*f)fJygbSX_UebqSajU)#d*X?5R+IZ3kIn_O + android:textColor="@color/notification_secondary_content_color" /> diff --git a/app/src/main/res/layout/notification_controller_big.xml b/app/src/main/res/layout/notification_big.xml similarity index 92% rename from app/src/main/res/layout/notification_controller_big.xml rename to app/src/main/res/layout/notification_big.xml index 3688c175..93f8d49e 100644 --- a/app/src/main/res/layout/notification_controller_big.xml +++ b/app/src/main/res/layout/notification_big.xml @@ -41,7 +41,6 @@ android:layout_marginTop="2dp" android:background="@drawable/notification_selector" android:src="@drawable/ic_close_white_24dp" - android:tint="@color/default_notification_content_color" tools:ignore="ContentDescription" /> + android:textColor="@color/notification_content_color" /> + android:textColor="@color/notification_secondary_content_color" /> + android:textColor="@color/notification_secondary_content_color" /> diff --git a/app/src/main/res/layout/notification_controller_big_colored.xml b/app/src/main/res/layout/notification_controller_big_colored.xml deleted file mode 100644 index bfd9a571..00000000 --- a/app/src/main/res/layout/notification_controller_big_colored.xml +++ /dev/null @@ -1,160 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/layout/notification_controller_colored.xml b/app/src/main/res/layout/notification_controller_colored.xml deleted file mode 100644 index e7a0b2eb..00000000 --- a/app/src/main/res/layout/notification_controller_colored.xml +++ /dev/null @@ -1,141 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/app/src/main/res/values-v21/colors.xml b/app/src/main/res/values-v21/colors.xml deleted file mode 100644 index d19798df..00000000 --- a/app/src/main/res/values-v21/colors.xml +++ /dev/null @@ -1,13 +0,0 @@ - - - #de000000 - #aa000000 - - @color/grey_800 - #deFFFFFF - #aaFFFFFF - - - - - \ No newline at end of file diff --git a/app/src/main/res/values-v21/styles.xml b/app/src/main/res/values-v21/styles.xml index 0b4c2b3a..c4cd95d8 100644 --- a/app/src/main/res/values-v21/styles.xml +++ b/app/src/main/res/values-v21/styles.xml @@ -22,11 +22,6 @@ @string/transition_fab - - - diff --git a/app/src/main/res/values/styles_parents.xml b/app/src/main/res/values/styles_parents.xml index 3423b1a1..8eac4fc4 100644 --- a/app/src/main/res/values/styles_parents.xml +++ b/app/src/main/res/values/styles_parents.xml @@ -73,15 +73,6 @@ wrap_content - - -