Merge branch 'develop' of git://github.com/scarito/AntennaPod into scarito-develop

This commit is contained in:
daniel oeh 2014-12-10 21:34:27 +01:00
commit 520e0ae8db
6 changed files with 64 additions and 0 deletions

View File

@ -41,6 +41,7 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
adapter.open(); adapter.open();
adapter.close(); adapter.close();
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext()); SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(getInstrumentation().getTargetContext());
prefs.edit().putBoolean(UserPreferences.PREF_UNPAUSE_ON_HEADSET_RECONNECT, false).commit();
prefs.edit().putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false).commit(); prefs.edit().putBoolean(UserPreferences.PREF_PAUSE_ON_HEADSET_DISCONNECT, false).commit();
} }

View File

@ -29,6 +29,13 @@
android:key="prefPauseOnHeadsetDisconnect" android:key="prefPauseOnHeadsetDisconnect"
android:summary="@string/pref_pauseOnHeadsetDisconnect_sum" android:summary="@string/pref_pauseOnHeadsetDisconnect_sum"
android:title="@string/pref_pauseOnHeadsetDisconnect_title"/> android:title="@string/pref_pauseOnHeadsetDisconnect_title"/>
<CheckBoxPreference
android:defaultValue="true"
android:enabled="true"
android:dependency="prefPauseOnHeadsetDisconnect"
android:key="prefUnpauseOnHeadsetReconnect"
android:summary="@string/pref_unpauseOnHeadsetReconnect_sum"
android:title="@string/pref_unpauseOnHeadsetReconnect_title"/>
<CheckBoxPreference <CheckBoxPreference
android:defaultValue="false" android:defaultValue="false"
android:enabled="true" android:enabled="true"

View File

@ -38,6 +38,7 @@ public class UserPreferences implements
private static final String TAG = "UserPreferences"; private static final String TAG = "UserPreferences";
public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect"; public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect";
public static final String PREF_UNPAUSE_ON_HEADSET_RECONNECT = "prefUnpauseOnHeadsetReconnect";
public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue"; public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue";
public static final String PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY = "prefDownloadMediaOnWifiOnly"; public static final String PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY = "prefDownloadMediaOnWifiOnly";
public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall"; public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall";
@ -69,6 +70,7 @@ public class UserPreferences implements
// Preferences // Preferences
private boolean pauseOnHeadsetDisconnect; private boolean pauseOnHeadsetDisconnect;
private boolean unpauseOnHeadsetReconnect;
private boolean followQueue; private boolean followQueue;
private boolean downloadMediaOnWifiOnly; private boolean downloadMediaOnWifiOnly;
private long updateInterval; private long updateInterval;
@ -121,6 +123,8 @@ public class UserPreferences implements
R.integer.episode_cache_size_unlimited); R.integer.episode_cache_size_unlimited);
pauseOnHeadsetDisconnect = sp.getBoolean( pauseOnHeadsetDisconnect = sp.getBoolean(
PREF_PAUSE_ON_HEADSET_DISCONNECT, true); PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
unpauseOnHeadsetReconnect = sp.getBoolean(
PREF_UNPAUSE_ON_HEADSET_RECONNECT, true);
followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false); followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false);
downloadMediaOnWifiOnly = sp.getBoolean( downloadMediaOnWifiOnly = sp.getBoolean(
PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY, true); PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY, true);
@ -221,6 +225,11 @@ public class UserPreferences implements
return instance.pauseOnHeadsetDisconnect; return instance.pauseOnHeadsetDisconnect;
} }
public static boolean isUnpauseOnHeadsetReconnect() {
instanceAvailable();
return instance.unpauseOnHeadsetReconnect;
}
public static boolean isFollowQueue() { public static boolean isFollowQueue() {
instanceAvailable(); instanceAvailable();
return instance.followQueue; return instance.followQueue;
@ -388,6 +397,8 @@ public class UserPreferences implements
seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30")); seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30"));
} else if (key.equals(PREF_PAUSE_ON_HEADSET_DISCONNECT)) { } else if (key.equals(PREF_PAUSE_ON_HEADSET_DISCONNECT)) {
pauseOnHeadsetDisconnect = sp.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true); pauseOnHeadsetDisconnect = sp.getBoolean(PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
} else if (key.equals(PREF_UNPAUSE_ON_HEADSET_RECONNECT)) {
unpauseOnHeadsetReconnect = sp.getBoolean(PREF_UNPAUSE_ON_HEADSET_RECONNECT, true);
} 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);

View File

@ -144,6 +144,10 @@ public class PlaybackService extends Service {
* Is true if service has received a valid start command. * Is true if service has received a valid start command.
*/ */
public static boolean started = false; public static boolean started = false;
/**
* Is true if the service was running, but paused due to headphone disconnect
*/
public static boolean transientPause = false;
private static final int NOTIFICATION_ID = 1; private static final int NOTIFICATION_ID = 1;
@ -206,6 +210,8 @@ public class PlaybackService extends Service {
Intent.ACTION_HEADSET_PLUG)); Intent.ACTION_HEADSET_PLUG));
registerReceiver(shutdownReceiver, new IntentFilter( registerReceiver(shutdownReceiver, new IntentFilter(
ACTION_SHUTDOWN_PLAYBACK_SERVICE)); ACTION_SHUTDOWN_PLAYBACK_SERVICE));
registerReceiver(bluetoothStateUpdated, new IntentFilter(
AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
registerReceiver(audioBecomingNoisy, new IntentFilter( registerReceiver(audioBecomingNoisy, new IntentFilter(
AudioManager.ACTION_AUDIO_BECOMING_NOISY)); AudioManager.ACTION_AUDIO_BECOMING_NOISY));
registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter( registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter(
@ -228,6 +234,7 @@ public class PlaybackService extends Service {
unregisterReceiver(headsetDisconnected); unregisterReceiver(headsetDisconnected);
unregisterReceiver(shutdownReceiver); unregisterReceiver(shutdownReceiver);
unregisterReceiver(bluetoothStateUpdated);
unregisterReceiver(audioBecomingNoisy); unregisterReceiver(audioBecomingNoisy);
unregisterReceiver(skipCurrentEpisodeReceiver); unregisterReceiver(skipCurrentEpisodeReceiver);
mediaPlayer.shutdown(); mediaPlayer.shutdown();
@ -966,6 +973,7 @@ public class PlaybackService extends Service {
private BroadcastReceiver headsetDisconnected = new BroadcastReceiver() { private BroadcastReceiver headsetDisconnected = new BroadcastReceiver() {
private static final String TAG = "headsetDisconnected"; private static final String TAG = "headsetDisconnected";
private static final int UNPLUGGED = 0; private static final int UNPLUGGED = 0;
private static final int PLUGGED = 1;
@Override @Override
public void onReceive(Context context, Intent intent) { public void onReceive(Context context, Intent intent) {
@ -978,6 +986,10 @@ public class PlaybackService extends Service {
if (BuildConfig.DEBUG) if (BuildConfig.DEBUG)
Log.d(TAG, "Headset was unplugged during playback."); Log.d(TAG, "Headset was unplugged during playback.");
pauseIfPauseOnDisconnect(); pauseIfPauseOnDisconnect();
} else if (state == PLUGGED) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Headset was plugged in during playback.");
unpauseIfPauseOnDisconnect();
} }
} else { } else {
Log.e(TAG, "Received invalid ACTION_HEADSET_PLUG intent"); Log.e(TAG, "Received invalid ACTION_HEADSET_PLUG intent");
@ -986,6 +998,21 @@ public class PlaybackService extends Service {
} }
}; };
private BroadcastReceiver bluetoothStateUpdated = new BroadcastReceiver() {
@Override
public void onReceive(Context context, Intent intent) {
if (StringUtils.equals(intent.getAction(), AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED)) {
int state = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_STATE, -1);
int prevState = intent.getIntExtra(AudioManager.EXTRA_SCO_AUDIO_PREVIOUS_STATE, -1);
if (state == AudioManager.SCO_AUDIO_STATE_CONNECTED) {
if (BuildConfig.DEBUG)
Log.d(TAG, "Received bluetooth connection intent");
unpauseIfPauseOnDisconnect();
}
}
}
};
private BroadcastReceiver audioBecomingNoisy = new BroadcastReceiver() { private BroadcastReceiver audioBecomingNoisy = new BroadcastReceiver() {
@Override @Override
@ -1003,6 +1030,9 @@ public class PlaybackService extends Service {
*/ */
private void pauseIfPauseOnDisconnect() { private void pauseIfPauseOnDisconnect() {
if (UserPreferences.isPauseOnHeadsetDisconnect()) { if (UserPreferences.isPauseOnHeadsetDisconnect()) {
if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) {
transientPause = true;
}
if (UserPreferences.isPersistNotify()) { if (UserPreferences.isPersistNotify()) {
mediaPlayer.pause(false, true); mediaPlayer.pause(false, true);
} else { } else {
@ -1011,6 +1041,15 @@ public class PlaybackService extends Service {
} }
} }
private void unpauseIfPauseOnDisconnect() {
if (transientPause) {
transientPause = false;
if (UserPreferences.isPauseOnHeadsetDisconnect() && UserPreferences.isUnpauseOnHeadsetReconnect()) {
mediaPlayer.resume();
}
}
}
private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() { private BroadcastReceiver shutdownReceiver = new BroadcastReceiver() {
@Override @Override

View File

@ -586,6 +586,10 @@ public class PlaybackServiceMediaPlayer {
return mediaType; return mediaType;
} }
public PlayerStatus getPlayerStatus() {
return playerStatus;
}
public boolean isStreaming() { public boolean isStreaming() {
return stream; return stream;
} }

View File

@ -205,6 +205,7 @@
<string name="services_label">Services</string> <string name="services_label">Services</string>
<string name="flattr_label">Flattr</string> <string name="flattr_label">Flattr</string>
<string name="pref_pauseOnHeadsetDisconnect_sum">Pause playback when the headphones are disconnected</string> <string name="pref_pauseOnHeadsetDisconnect_sum">Pause playback when the headphones are disconnected</string>
<string name="pref_unpauseOnHeadsetReconnect_sum">Resume playback when the headphones are reconnected</string>
<string name="pref_followQueue_sum">Jump to next queue item when playback completes</string> <string name="pref_followQueue_sum">Jump to next queue item when playback completes</string>
<string name="playback_pref">Playback</string> <string name="playback_pref">Playback</string>
<string name="network_pref">Network</string> <string name="network_pref">Network</string>
@ -214,6 +215,7 @@
<string name="pref_followQueue_title">Continuous playback</string> <string name="pref_followQueue_title">Continuous playback</string>
<string name="pref_downloadMediaOnWifiOnly_title">WiFi media download</string> <string name="pref_downloadMediaOnWifiOnly_title">WiFi media download</string>
<string name="pref_pauseOnHeadsetDisconnect_title">Headphones disconnect</string> <string name="pref_pauseOnHeadsetDisconnect_title">Headphones disconnect</string>
<string name="pref_unpauseOnHeadsetReconnect_title">Headphones reconnect</string>
<string name="pref_mobileUpdate_title">Mobile updates</string> <string name="pref_mobileUpdate_title">Mobile updates</string>
<string name="pref_mobileUpdate_sum">Allow updates over the mobile data connection</string> <string name="pref_mobileUpdate_sum">Allow updates over the mobile data connection</string>
<string name="refreshing_label">Refreshing</string> <string name="refreshing_label">Refreshing</string>