From 9375969eee84c48aed3d509d76fcc010568d010e Mon Sep 17 00:00:00 2001 From: Adrian Ulrich Date: Sun, 31 May 2015 18:18:26 +0200 Subject: [PATCH] implement verbose notifications (nag) --- res/values/translatable.xml | 3 ++ res/xml/preference_notifications.xml | 5 ++++ .../android/vanilla/PlaybackService.java | 28 +++++++++++++++---- .../android/vanilla/PrefKeys.java | 3 +- 4 files changed, 33 insertions(+), 6 deletions(-) diff --git a/res/values/translatable.xml b/res/values/translatable.xml index a8db1dd1..cc02f013 100644 --- a/res/values/translatable.xml +++ b/res/values/translatable.xml @@ -186,6 +186,9 @@ THE SOFTWARE. Invert Notification Color Use white text instead of black text + Very verbose notification + Announce song changes using a \'Heads-Up-Notification\' + Playback Screen Open on Startup Open playback view on startup diff --git a/res/xml/preference_notifications.xml b/res/xml/preference_notifications.xml index b05a03ac..e27f2b13 100644 --- a/res/xml/preference_notifications.xml +++ b/res/xml/preference_notifications.xml @@ -35,4 +35,9 @@ THE SOFTWARE. android:entries="@array/notification_action_entries" android:entryValues="@array/entry_values" android:defaultValue="0" /> + diff --git a/src/ch/blinkenlights/android/vanilla/PlaybackService.java b/src/ch/blinkenlights/android/vanilla/PlaybackService.java index a74ff6b7..823f2e0a 100644 --- a/src/ch/blinkenlights/android/vanilla/PlaybackService.java +++ b/src/ch/blinkenlights/android/vanilla/PlaybackService.java @@ -282,7 +282,14 @@ public final class PlaybackService extends Service * music player. */ private boolean mStockBroadcast; + /** + * Behaviour of the notification + */ private int mNotificationMode; + /** + * If true, create a notification with ticker text or heads up display + */ + private boolean mNotificationNag; /** * If true, audio will not be played through the speaker. */ @@ -421,6 +428,7 @@ public final class PlaybackService extends Service SharedPreferences settings = getSettings(this); settings.registerOnSharedPreferenceChangeListener(this); mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, "1")); + mNotificationNag = settings.getBoolean(PrefKeys.NOTIFICATION_NAG, false); mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false); mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, false) ? settings.getInt(PrefKeys.IDLE_TIMEOUT, 3600) : 0; @@ -789,6 +797,9 @@ public final class PlaybackService extends Service // mode. stopForeground(true); updateNotification(); + } else if (PrefKeys.NOTIFICATION_NAG.equals(key)) { + mNotificationNag = settings.getBoolean(PrefKeys.NOTIFICATION_NAG, false); + // no need to update notification: happens on next event } else if (PrefKeys.SCROBBLE.equals(key)) { mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, false); } else if (PrefKeys.MEDIA_BUTTON.equals(key) || PrefKeys.MEDIA_BUTTON_BEEP.equals(key)) { @@ -1931,8 +1942,6 @@ public final class PlaybackService extends Service expanded.setImageViewBitmap(R.id.cover, cover); } - String title = song.title; - int playButton = ThemeHelper.getPlayButtonResource(playing); views.setImageViewResource(R.id.play_pause, playButton); @@ -1959,9 +1968,9 @@ public final class PlaybackService extends Service views.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0)); expanded.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0)); - views.setTextViewText(R.id.title, title); + views.setTextViewText(R.id.title, song.title); views.setTextViewText(R.id.artist, song.artist); - expanded.setTextViewText(R.id.title, title); + expanded.setTextViewText(R.id.title, song.title); expanded.setTextViewText(R.id.album, song.album); expanded.setTextViewText(R.id.artist, song.artist); @@ -1973,11 +1982,20 @@ public final class PlaybackService extends Service if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.JELLY_BEAN) { // expanded view is available since 4.1 notification.bigContentView = expanded; - notification.priority = 42; } if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { notification.visibility = Notification.VISIBILITY_PUBLIC; } + + if(mNotificationNag) { + if(Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) { + notification.priority = Notification.PRIORITY_MAX; + notification.vibrate = new long[0]; // needed to get headsup + } else { + notification.tickerText = song.title + " - " + song.artist; + } + } + return notification; } diff --git a/src/ch/blinkenlights/android/vanilla/PrefKeys.java b/src/ch/blinkenlights/android/vanilla/PrefKeys.java index 2751f359..747783a4 100644 --- a/src/ch/blinkenlights/android/vanilla/PrefKeys.java +++ b/src/ch/blinkenlights/android/vanilla/PrefKeys.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2012-2013 Adrian Ulrich + * Copyright (C) 2012-2015 Adrian Ulrich * Copyright (C) 2012 Christopher Eby * * Permission is hereby granted, free of charge, to any person obtaining a copy @@ -47,6 +47,7 @@ public class PrefKeys { public static final String MEDIA_BUTTON_BEEP = "media_button_beep"; public static final String NOTIFICATION_ACTION = "notification_action"; public static final String NOTIFICATION_MODE = "notification_mode"; + public static final String NOTIFICATION_NAG = "notification_nag"; public static final String PLAYBACK_ON_STARTUP = "playback_on_startup"; public static final String SCROBBLE = "scrobble"; public static final String SHAKE_ACTION = "shake_action";