diff options
Diffstat (limited to 'src/de/danoeh/antennapod')
3 files changed, 109 insertions, 7 deletions
diff --git a/src/de/danoeh/antennapod/activity/PreferenceActivity.java b/src/de/danoeh/antennapod/activity/PreferenceActivity.java index cd6731c02..a21985bb8 100644 --- a/src/de/danoeh/antennapod/activity/PreferenceActivity.java +++ b/src/de/danoeh/antennapod/activity/PreferenceActivity.java @@ -9,6 +9,7 @@ import android.content.res.Resources.Theme; import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiManager; import android.os.Bundle; +import android.os.Build; import android.preference.CheckBoxPreference; import android.preference.ListPreference; import android.preference.Preference; @@ -60,6 +61,9 @@ public class PreferenceActivity extends android.preference.PreferenceActivity { private static final String PREF_GPODNET_LOGOUT = "pref_gpodnet_logout"; private static final String PREF_GPODNET_HOSTNAME = "pref_gpodnet_hostname"; + private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify"; + private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify"; + private CheckBoxPreference[] selectedNetworks; @SuppressLint("NewApi") @@ -77,6 +81,23 @@ public class PreferenceActivity extends android.preference.PreferenceActivity { } addPreferencesFromResource(R.xml.preferences); + + if (android.os.Build.VERSION.SDK_INT < Build.VERSION_CODES.JELLY_BEAN) { + // disable expanded notification option on unsupported android versions + findPreference(PREF_EXPANDED_NOTIFICATION).setEnabled(false); + findPreference(PREF_EXPANDED_NOTIFICATION).setOnPreferenceClickListener( + new OnPreferenceClickListener() { + + @Override + public boolean onPreferenceClick(Preference preference) { + Toast toast = Toast.makeText(PreferenceActivity.this, R.string.pref_expand_notify_unsupport_toast, Toast.LENGTH_SHORT); + toast.show(); + return true; + } + } + ); + } + findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener( new OnPreferenceClickListener() { @@ -272,8 +293,6 @@ public class PreferenceActivity extends android.preference.PreferenceActivity { buildAutodownloadSelectedNetworsPreference(); setSelectedNetworksEnabled(UserPreferences .isEnableAutodownloadWifiFilter()); - - } private void updateGpodnetPreferenceScreen() { diff --git a/src/de/danoeh/antennapod/preferences/UserPreferences.java b/src/de/danoeh/antennapod/preferences/UserPreferences.java index 2020ddfae..1f2d720c9 100644 --- a/src/de/danoeh/antennapod/preferences/UserPreferences.java +++ b/src/de/danoeh/antennapod/preferences/UserPreferences.java @@ -53,6 +53,8 @@ public class UserPreferences implements private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray"; public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss"; private static final String PREF_SEEK_DELTA_SECS = "prefSeekDeltaSecs"; + private static final String PREF_EXPANDED_NOTIFICATION = "prefExpandNotify"; + private static final String PREF_PERSISTENT_NOTIFICATION = "prefPersistNotify"; // TODO: Make this value configurable private static final float PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT = 0.8f; @@ -82,6 +84,8 @@ public class UserPreferences implements private boolean pauseForFocusLoss; private int seekDeltaSecs; private boolean isFreshInstall; + private int notifyPriority; + private boolean persistNotify; private UserPreferences(Context context) { this.context = context; @@ -138,6 +142,13 @@ public class UserPreferences implements PREF_PLAYBACK_SPEED_ARRAY, null)); pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false); seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30")); + if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) { + notifyPriority = 2; // max priority + } + else { + notifyPriority = 0; // default priority + } + persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false); } private int readThemeValue(String valueFromPrefs) { @@ -243,6 +254,17 @@ public class UserPreferences implements return instance.autoFlattr; } + public static int getNotifyPriority() { + instanceAvailable(); + return instance.notifyPriority; + } + + public static boolean isPersistNotify() { + instanceAvailable(); + return instance.persistNotify; + } + + /** * Returns the time after which an episode should be auto-flattr'd in percent of the episode's * duration. @@ -366,6 +388,15 @@ public class UserPreferences implements } else if (key.equals(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD)) { autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD, PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT); + } else if (key.equals(PREF_EXPANDED_NOTIFICATION)) { + if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) { + notifyPriority = 2; // max priority + } + else { + notifyPriority = 0; // default priority + } + } else if (key.equals(PREF_PERSISTENT_NOTIFICATION)) { + persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false); } } diff --git a/src/de/danoeh/antennapod/service/playback/PlaybackService.java b/src/de/danoeh/antennapod/service/playback/PlaybackService.java index 59d7ddbb9..d4f66b870 100644 --- a/src/de/danoeh/antennapod/service/playback/PlaybackService.java +++ b/src/de/danoeh/antennapod/service/playback/PlaybackService.java @@ -297,7 +297,12 @@ public class PlaybackService extends Service { case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: if (status == PlayerStatus.PLAYING) { - mediaPlayer.pause(true, true); + if (UserPreferences.isPersistNotify()) { + mediaPlayer.pause(false, true); + } + else { + mediaPlayer.pause(true, true); + } } else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) { mediaPlayer.resume(); } else if (status == PlayerStatus.PREPARING) { @@ -317,7 +322,12 @@ public class PlaybackService extends Service { break; case KeyEvent.KEYCODE_MEDIA_PAUSE: if (status == PlayerStatus.PLAYING) { + if (UserPreferences.isPersistNotify()) { + mediaPlayer.pause(false, true); + } + else { mediaPlayer.pause(true, true); + } } break; case KeyEvent.KEYCODE_MEDIA_NEXT: @@ -328,6 +338,12 @@ public class PlaybackService extends Service { case KeyEvent.KEYCODE_MEDIA_REWIND: mediaPlayer.seekDelta(-UserPreferences.getSeekDeltaMs()); break; + case KeyEvent.KEYCODE_MEDIA_STOP: + if (status == PlayerStatus.PLAYING) { + mediaPlayer.pause(true, true); + } + stopForeground(true); // gets rid of persistent notification + break; default: if (info.playable != null && info.playerStatus == PlayerStatus.PLAYING) { // only notify the user about an unknown key event if it is actually doing something String message = String.format(getResources().getString(R.string.unknown_media_key), keycode); @@ -401,7 +417,13 @@ public class PlaybackService extends Service { taskManager.cancelPositionSaver(); saveCurrentPosition(false, 0); taskManager.cancelWidgetUpdater(); - stopForeground(true); + if (UserPreferences.isPersistNotify()) { + // do not remove notification on pause + } + else { + // remove notifcation on pause + stopForeground(true); + } break; case STOPPED: @@ -713,7 +735,7 @@ public class PlaybackService extends Service { String contentTitle = info.playable.getEpisodeTitle(); Notification notification = null; if (android.os.Build.VERSION.SDK_INT >= 16) { - Intent pauseButtonIntent = new Intent( + Intent pauseButtonIntent = new Intent( // pause button intent PlaybackService.this, PlaybackService.class); pauseButtonIntent.putExtra( MediaButtonReceiver.EXTRA_KEYCODE, @@ -722,6 +744,24 @@ public class PlaybackService extends Service { .getService(PlaybackService.this, 0, pauseButtonIntent, PendingIntent.FLAG_UPDATE_CURRENT); + Intent playButtonIntent = new Intent( // play button intent + PlaybackService.this, PlaybackService.class); + playButtonIntent.putExtra( + MediaButtonReceiver.EXTRA_KEYCODE, + KeyEvent.KEYCODE_MEDIA_PLAY); + PendingIntent playButtonPendingIntent = PendingIntent + .getService(PlaybackService.this, 1, + playButtonIntent, + PendingIntent.FLAG_UPDATE_CURRENT); + Intent stopButtonIntent = new Intent( // stop button intent + PlaybackService.this, PlaybackService.class); + stopButtonIntent.putExtra( + MediaButtonReceiver.EXTRA_KEYCODE, + KeyEvent.KEYCODE_MEDIA_STOP); + PendingIntent stopButtonPendingIntent = PendingIntent + .getService(PlaybackService.this, 2, + stopButtonIntent, + PendingIntent.FLAG_UPDATE_CURRENT); Notification.Builder notificationBuilder = new Notification.Builder( PlaybackService.this) .setContentTitle(contentTitle) @@ -730,9 +770,16 @@ public class PlaybackService extends Service { .setContentIntent(pIntent) .setLargeIcon(icon) .setSmallIcon(R.drawable.ic_stat_antenna) - .addAction(android.R.drawable.ic_media_pause, + .setPriority(UserPreferences.getNotifyPriority()) // set notification priority + .addAction(android.R.drawable.ic_media_play, //play action + getString(R.string.play_label), + playButtonPendingIntent) + .addAction(android.R.drawable.ic_media_pause, //pause action getString(R.string.pause_label), - pauseButtonPendingIntent); + pauseButtonPendingIntent) + .addAction(android.R.drawable.ic_menu_close_clear_cancel, // stop action + getString(R.string.stop_label), + stopButtonPendingIntent); notification = notificationBuilder.build(); } else { NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( @@ -949,7 +996,12 @@ public class PlaybackService extends Service { */ private void pauseIfPauseOnDisconnect() { if (UserPreferences.isPauseOnHeadsetDisconnect()) { + if (UserPreferences.isPersistNotify()) { + mediaPlayer.pause(false, true); + } + else { mediaPlayer.pause(true, true); + } } } |