Merge branch 'mchelen-notifymore2' into develop

This commit is contained in:
daniel oeh 2014-09-29 17:34:34 +02:00
commit 441165ff3f
5 changed files with 128 additions and 7 deletions

View File

@ -90,6 +90,7 @@
<string name="download_label">Download</string> <string name="download_label">Download</string>
<string name="play_label">Play</string> <string name="play_label">Play</string>
<string name="pause_label">Pause</string> <string name="pause_label">Pause</string>
<string name="stop_label">Stop</string>
<string name="stream_label">Stream</string> <string name="stream_label">Stream</string>
<string name="remove_label">Remove</string> <string name="remove_label">Remove</string>
<string name="remove_episode_lable">Remove episode</string> <string name="remove_episode_lable">Remove episode</string>
@ -250,6 +251,11 @@
<string name="pref_seek_delta_sum">Seek this many seconds when rewinding or fast-forwarding</string> <string name="pref_seek_delta_sum">Seek this many seconds when rewinding or fast-forwarding</string>
<string name="pref_gpodnet_sethostname_title">Set hostname</string> <string name="pref_gpodnet_sethostname_title">Set hostname</string>
<string name="pref_gpodnet_sethostname_use_default_host">Use default host</string> <string name="pref_gpodnet_sethostname_use_default_host">Use default host</string>
<string name="pref_expandNotify_title">Expand Notification</string>
<string name="pref_expandNotify_sum">Always expand the notification to show playback buttons.</string>
<string name="pref_persistNotify_title">Persistent playback controls</string>
<string name="pref_persistNotify_sum">Keep notification and lockscreen controls when playback is paused.</string>
<string name="pref_expand_notify_unsupport_toast">Android versions before 4.1 do not support expanded notifications.</string>
<!-- Auto-Flattr dialog --> <!-- Auto-Flattr dialog -->
<string name="auto_flattr_enable">Enable automatic flattring</string> <string name="auto_flattr_enable">Enable automatic flattring</string>

View File

@ -9,6 +9,18 @@
android:key="prefTheme" android:key="prefTheme"
android:summary="@string/pref_set_theme_sum" android:summary="@string/pref_set_theme_sum"
android:defaultValue="0"/> android:defaultValue="0"/>
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
android:key="prefExpandNotify"
android:summary="@string/pref_expandNotify_sum"
android:title="@string/pref_expandNotify_title"/>
<CheckBoxPreference
android:defaultValue="false"
android:enabled="true"
android:key="prefPersistNotify"
android:summary="@string/pref_persistNotify_sum"
android:title="@string/pref_persistNotify_title"/>
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory android:title="@string/playback_pref"> <PreferenceCategory android:title="@string/playback_pref">
<CheckBoxPreference <CheckBoxPreference

View File

@ -9,6 +9,7 @@ import android.content.res.Resources.Theme;
import android.net.wifi.WifiConfiguration; import android.net.wifi.WifiConfiguration;
import android.net.wifi.WifiManager; import android.net.wifi.WifiManager;
import android.os.Bundle; import android.os.Bundle;
import android.os.Build;
import android.preference.CheckBoxPreference; import android.preference.CheckBoxPreference;
import android.preference.ListPreference; import android.preference.ListPreference;
import android.preference.Preference; 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_LOGOUT = "pref_gpodnet_logout";
private static final String PREF_GPODNET_HOSTNAME = "pref_gpodnet_hostname"; 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; private CheckBoxPreference[] selectedNetworks;
@SuppressLint("NewApi") @SuppressLint("NewApi")
@ -77,6 +81,23 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
} }
addPreferencesFromResource(R.xml.preferences); 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( findPreference(PREF_FLATTR_THIS_APP).setOnPreferenceClickListener(
new OnPreferenceClickListener() { new OnPreferenceClickListener() {
@ -272,8 +293,6 @@ public class PreferenceActivity extends android.preference.PreferenceActivity {
buildAutodownloadSelectedNetworsPreference(); buildAutodownloadSelectedNetworsPreference();
setSelectedNetworksEnabled(UserPreferences setSelectedNetworksEnabled(UserPreferences
.isEnableAutodownloadWifiFilter()); .isEnableAutodownloadWifiFilter());
} }
private void updateGpodnetPreferenceScreen() { private void updateGpodnetPreferenceScreen() {

View File

@ -6,6 +6,7 @@ import android.content.Context;
import android.content.Intent; import android.content.Intent;
import android.content.SharedPreferences; import android.content.SharedPreferences;
import android.preference.PreferenceManager; import android.preference.PreferenceManager;
import android.support.v4.app.NotificationCompat;
import android.util.Log; import android.util.Log;
import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.StringUtils;
@ -53,6 +54,8 @@ public class UserPreferences implements
private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray"; private static final String PREF_PLAYBACK_SPEED_ARRAY = "prefPlaybackSpeedArray";
public static final String PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS = "prefPauseForFocusLoss"; 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_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 // TODO: Make this value configurable
private static final float PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT = 0.8f; private static final float PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT = 0.8f;
@ -82,6 +85,8 @@ public class UserPreferences implements
private boolean pauseForFocusLoss; private boolean pauseForFocusLoss;
private int seekDeltaSecs; private int seekDeltaSecs;
private boolean isFreshInstall; private boolean isFreshInstall;
private int notifyPriority;
private boolean persistNotify;
private UserPreferences(Context context) { private UserPreferences(Context context) {
this.context = context; this.context = context;
@ -138,6 +143,13 @@ public class UserPreferences implements
PREF_PLAYBACK_SPEED_ARRAY, null)); PREF_PLAYBACK_SPEED_ARRAY, null));
pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false); pauseForFocusLoss = sp.getBoolean(PREF_PAUSE_PLAYBACK_FOR_FOCUS_LOSS, false);
seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30")); seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30"));
if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
notifyPriority = NotificationCompat.PRIORITY_MAX;
}
else {
notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
}
persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
} }
private int readThemeValue(String valueFromPrefs) { private int readThemeValue(String valueFromPrefs) {
@ -243,6 +255,17 @@ public class UserPreferences implements
return instance.autoFlattr; 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 * Returns the time after which an episode should be auto-flattr'd in percent of the episode's
* duration. * duration.
@ -366,6 +389,15 @@ public class UserPreferences implements
} else if (key.equals(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD)) { } else if (key.equals(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD)) {
autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD, autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD,
PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT); PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT);
} else if (key.equals(PREF_EXPANDED_NOTIFICATION)) {
if (sp.getBoolean(PREF_EXPANDED_NOTIFICATION, false)) {
notifyPriority = NotificationCompat.PRIORITY_MAX;
}
else {
notifyPriority = NotificationCompat.PRIORITY_DEFAULT;
}
} else if (key.equals(PREF_PERSISTENT_NOTIFICATION)) {
persistNotify = sp.getBoolean(PREF_PERSISTENT_NOTIFICATION, false);
} }
} }

View File

@ -297,7 +297,12 @@ public class PlaybackService extends Service {
case KeyEvent.KEYCODE_HEADSETHOOK: case KeyEvent.KEYCODE_HEADSETHOOK:
case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE: case KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE:
if (status == PlayerStatus.PLAYING) { 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) { } else if (status == PlayerStatus.PAUSED || status == PlayerStatus.PREPARED) {
mediaPlayer.resume(); mediaPlayer.resume();
} else if (status == PlayerStatus.PREPARING) { } else if (status == PlayerStatus.PREPARING) {
@ -317,7 +322,12 @@ public class PlaybackService extends Service {
break; break;
case KeyEvent.KEYCODE_MEDIA_PAUSE: case KeyEvent.KEYCODE_MEDIA_PAUSE:
if (status == PlayerStatus.PLAYING) { if (status == PlayerStatus.PLAYING) {
if (UserPreferences.isPersistNotify()) {
mediaPlayer.pause(false, true);
}
else {
mediaPlayer.pause(true, true); mediaPlayer.pause(true, true);
}
} }
break; break;
case KeyEvent.KEYCODE_MEDIA_NEXT: case KeyEvent.KEYCODE_MEDIA_NEXT:
@ -328,6 +338,12 @@ public class PlaybackService extends Service {
case KeyEvent.KEYCODE_MEDIA_REWIND: case KeyEvent.KEYCODE_MEDIA_REWIND:
mediaPlayer.seekDelta(-UserPreferences.getSeekDeltaMs()); mediaPlayer.seekDelta(-UserPreferences.getSeekDeltaMs());
break; break;
case KeyEvent.KEYCODE_MEDIA_STOP:
if (status == PlayerStatus.PLAYING) {
mediaPlayer.pause(true, true);
}
stopForeground(true); // gets rid of persistent notification
break;
default: default:
if (info.playable != null && info.playerStatus == PlayerStatus.PLAYING) { // only notify the user about an unknown key event if it is actually doing something 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); String message = String.format(getResources().getString(R.string.unknown_media_key), keycode);
@ -401,7 +417,13 @@ public class PlaybackService extends Service {
taskManager.cancelPositionSaver(); taskManager.cancelPositionSaver();
saveCurrentPosition(false, 0); saveCurrentPosition(false, 0);
taskManager.cancelWidgetUpdater(); taskManager.cancelWidgetUpdater();
stopForeground(true); if (UserPreferences.isPersistNotify()) {
// do not remove notification on pause
}
else {
// remove notifcation on pause
stopForeground(true);
}
break; break;
case STOPPED: case STOPPED:
@ -713,7 +735,7 @@ public class PlaybackService extends Service {
String contentTitle = info.playable.getEpisodeTitle(); String contentTitle = info.playable.getEpisodeTitle();
Notification notification = null; Notification notification = null;
if (android.os.Build.VERSION.SDK_INT >= 16) { if (android.os.Build.VERSION.SDK_INT >= 16) {
Intent pauseButtonIntent = new Intent( Intent pauseButtonIntent = new Intent( // pause button intent
PlaybackService.this, PlaybackService.class); PlaybackService.this, PlaybackService.class);
pauseButtonIntent.putExtra( pauseButtonIntent.putExtra(
MediaButtonReceiver.EXTRA_KEYCODE, MediaButtonReceiver.EXTRA_KEYCODE,
@ -722,6 +744,24 @@ public class PlaybackService extends Service {
.getService(PlaybackService.this, 0, .getService(PlaybackService.this, 0,
pauseButtonIntent, pauseButtonIntent,
PendingIntent.FLAG_UPDATE_CURRENT); 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( Notification.Builder notificationBuilder = new Notification.Builder(
PlaybackService.this) PlaybackService.this)
.setContentTitle(contentTitle) .setContentTitle(contentTitle)
@ -730,9 +770,16 @@ public class PlaybackService extends Service {
.setContentIntent(pIntent) .setContentIntent(pIntent)
.setLargeIcon(icon) .setLargeIcon(icon)
.setSmallIcon(R.drawable.ic_stat_antenna) .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), 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(); notification = notificationBuilder.build();
} else { } else {
NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder( NotificationCompat.Builder notificationBuilder = new NotificationCompat.Builder(
@ -949,7 +996,12 @@ public class PlaybackService extends Service {
*/ */
private void pauseIfPauseOnDisconnect() { private void pauseIfPauseOnDisconnect() {
if (UserPreferences.isPauseOnHeadsetDisconnect()) { if (UserPreferences.isPauseOnHeadsetDisconnect()) {
if (UserPreferences.isPersistNotify()) {
mediaPlayer.pause(false, true);
}
else {
mediaPlayer.pause(true, true); mediaPlayer.pause(true, true);
}
} }
} }