Reduce notification visibility modes to when_playing and always.
The NEVER didn't really work well since 5.x (we were more likely to get killed) and is broken on 8.x, so we just get rid of it.
This commit is contained in:
parent
0030c1777e
commit
b79dfc49ba
@ -197,7 +197,7 @@ THE SOFTWARE.
|
||||
<string name="cycle_continuous_shuffling_summary">\'Shuffle mode\' will play tracks in completely random order</string>
|
||||
|
||||
<string name="notifications">Notifications</string>
|
||||
<string name="notification_mode_title">Notification mode</string>
|
||||
<string name="notification_visibility_title">Notification visibility</string>
|
||||
<string name="notification_action_title">Notification action</string>
|
||||
|
||||
<string name="notification_nag">Very verbose notification</string>
|
||||
|
@ -125,8 +125,7 @@ THE SOFTWARE.
|
||||
</string-array>
|
||||
<!-- END default action entries definition -->
|
||||
|
||||
<string-array name="notification_mode_entries">
|
||||
<item>@string/never_show</item>
|
||||
<string-array name="notification_visibility_entries">
|
||||
<item>@string/show_when_playing</item>
|
||||
<item>@string/always_show</item>
|
||||
</string-array>
|
||||
|
@ -24,11 +24,11 @@ THE SOFTWARE.
|
||||
xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
android:persistent="true">
|
||||
<ch.blinkenlights.android.vanilla.ListPreferenceSummary
|
||||
android:key="notification_mode"
|
||||
android:title="@string/notification_mode_title"
|
||||
android:entries="@array/notification_mode_entries"
|
||||
android:key="notification_visibility"
|
||||
android:title="@string/notification_visibility_title"
|
||||
android:entries="@array/notification_visibility_entries"
|
||||
android:entryValues="@array/entry_values"
|
||||
android:defaultValue="1" />
|
||||
android:defaultValue="0" />
|
||||
<ch.blinkenlights.android.vanilla.ListPreferenceSummary
|
||||
android:key="notification_action"
|
||||
android:title="@string/notification_action_title"
|
||||
|
@ -178,9 +178,11 @@ public final class PlaybackService extends Service
|
||||
*/
|
||||
public static final String ACTION_CLOSE_NOTIFICATION = "ch.blinkenlights.android.vanilla.CLOSE_NOTIFICATION";
|
||||
|
||||
public static final int NEVER = 0;
|
||||
public static final int WHEN_PLAYING = 1;
|
||||
public static final int ALWAYS = 2;
|
||||
/**
|
||||
* Visibility modes of the notification.
|
||||
*/
|
||||
public static final int VISIBILITY_WHEN_PLAYING = 0;
|
||||
public static final int VISIBILITY_ALWAYS = 1;
|
||||
|
||||
/**
|
||||
* Notification click action: open LaunchActivity.
|
||||
@ -301,7 +303,7 @@ public final class PlaybackService extends Service
|
||||
/**
|
||||
* Behaviour of the notification
|
||||
*/
|
||||
private int mNotificationMode;
|
||||
private int mNotificationVisibility;
|
||||
/**
|
||||
* If true, create a notification with ticker text or heads up display
|
||||
*/
|
||||
@ -451,7 +453,7 @@ public final class PlaybackService extends Service
|
||||
|
||||
SharedPreferences settings = getSettings(this);
|
||||
settings.registerOnSharedPreferenceChangeListener(this);
|
||||
mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, PrefDefaults.NOTIFICATION_MODE));
|
||||
mNotificationVisibility = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_VISIBILITY, PrefDefaults.NOTIFICATION_VISIBILITY));
|
||||
mNotificationNag = settings.getBoolean(PrefKeys.NOTIFICATION_NAG, PrefDefaults.NOTIFICATION_NAG);
|
||||
mScrobble = settings.getBoolean(PrefKeys.SCROBBLE, PrefDefaults.SCROBBLE);
|
||||
mIdleTimeout = settings.getBoolean(PrefKeys.USE_IDLE_TIMEOUT, PrefDefaults.USE_IDLE_TIMEOUT) ? settings.getInt(PrefKeys.IDLE_TIMEOUT, PrefDefaults.IDLE_TIMEOUT) : 0;
|
||||
@ -847,8 +849,8 @@ public final class PlaybackService extends Service
|
||||
} else if (PrefKeys.NOTIFICATION_ACTION.equals(key)) {
|
||||
mNotificationAction = createNotificationAction(settings);
|
||||
updateNotification();
|
||||
} else if (PrefKeys.NOTIFICATION_MODE.equals(key)){
|
||||
mNotificationMode = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_MODE, PrefDefaults.NOTIFICATION_MODE));
|
||||
} else if (PrefKeys.NOTIFICATION_VISIBILITY.equals(key)){
|
||||
mNotificationVisibility = Integer.parseInt(settings.getString(PrefKeys.NOTIFICATION_VISIBILITY, PrefDefaults.NOTIFICATION_VISIBILITY));
|
||||
// This is the only way to remove a notification created by
|
||||
// startForeground(), even if we are not currently in foreground
|
||||
// mode.
|
||||
@ -999,8 +1001,8 @@ public final class PlaybackService extends Service
|
||||
if (mMediaPlayerInitialized)
|
||||
mMediaPlayer.start();
|
||||
|
||||
if (mNotificationMode != NEVER)
|
||||
startForeground(NOTIFICATION_ID, createNotification(mCurrentSong, mState, mNotificationMode));
|
||||
// Update the notification with the current song information.
|
||||
startForeground(NOTIFICATION_ID, createNotification(mCurrentSong, mState, mNotificationVisibility));
|
||||
|
||||
final int result = mAudioManager.requestAudioFocus(this, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
|
||||
if (result != AudioManager.AUDIOFOCUS_REQUEST_GRANTED) {
|
||||
@ -1023,7 +1025,7 @@ public final class PlaybackService extends Service
|
||||
// In both cases we will update the notification to reflect the
|
||||
// actual playback state (or to hit cancel() as this is required to
|
||||
// get rid of it if it was created via notify())
|
||||
boolean removeNotification = (mForceNotificationVisible == false && mNotificationMode != ALWAYS);
|
||||
boolean removeNotification = (mForceNotificationVisible == false && mNotificationVisibility != VISIBILITY_ALWAYS);
|
||||
stopForeground(removeNotification);
|
||||
updateNotification();
|
||||
|
||||
@ -1146,10 +1148,12 @@ public final class PlaybackService extends Service
|
||||
|
||||
private void updateNotification()
|
||||
{
|
||||
if ((mForceNotificationVisible || mNotificationMode == ALWAYS || mNotificationMode == WHEN_PLAYING && (mState & FLAG_PLAYING) != 0) && mCurrentSong != null)
|
||||
mNotificationHelper.notify(NOTIFICATION_ID, createNotification(mCurrentSong, mState, mNotificationMode));
|
||||
else
|
||||
if ((mForceNotificationVisible || mNotificationVisibility == VISIBILITY_ALWAYS
|
||||
|| mNotificationVisibility == VISIBILITY_WHEN_PLAYING && (mState & FLAG_PLAYING) != 0) && mCurrentSong != null) {
|
||||
mNotificationHelper.notify(NOTIFICATION_ID, createNotification(mCurrentSong, mState, mNotificationVisibility));
|
||||
} else {
|
||||
mNotificationHelper.cancel(NOTIFICATION_ID);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@ -2092,7 +2096,7 @@ public final class PlaybackService extends Service
|
||||
views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));
|
||||
expanded.setOnClickPendingIntent(R.id.next, PendingIntent.getService(this, 0, next, 0));
|
||||
|
||||
int closeButtonVisibility = (mode == WHEN_PLAYING) ? View.VISIBLE : View.INVISIBLE;
|
||||
int closeButtonVisibility = (mode == VISIBILITY_WHEN_PLAYING) ? View.VISIBLE : View.INVISIBLE;
|
||||
Intent close = new Intent(PlaybackService.ACTION_CLOSE_NOTIFICATION);
|
||||
close.setComponent(service);
|
||||
views.setOnClickPendingIntent(R.id.close, PendingIntent.getService(this, 0, close, 0));
|
||||
|
@ -45,7 +45,7 @@ public class PrefDefaults {
|
||||
public static final boolean MEDIA_BUTTON = true;
|
||||
public static final boolean MEDIA_BUTTON_BEEP = true;
|
||||
public static final String NOTIFICATION_ACTION = "0";
|
||||
public static final String NOTIFICATION_MODE = "1";
|
||||
public static final String NOTIFICATION_VISIBILITY = "0";
|
||||
public static final boolean NOTIFICATION_NAG = false;
|
||||
public static final boolean PLAYBACK_ON_STARTUP = false;
|
||||
public static final boolean SCROBBLE = false;
|
||||
|
@ -46,7 +46,7 @@ public class PrefKeys {
|
||||
public static final String MEDIA_BUTTON = "media_button";
|
||||
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_VISIBILITY = "notification_visibility";
|
||||
public static final String NOTIFICATION_NAG = "notification_nag";
|
||||
public static final String PLAYBACK_ON_STARTUP = "playback_on_startup";
|
||||
public static final String SCROBBLE = "scrobble";
|
||||
|
Loading…
x
Reference in New Issue
Block a user