Merge branch 'develop' of git://github.com/scarito/AntennaPod into scarito-develop
This commit is contained in:
commit
520e0ae8db
|
@ -41,6 +41,7 @@ public class PlaybackTest extends ActivityInstrumentationTestCase2<MainActivity>
|
|||
adapter.open();
|
||||
adapter.close();
|
||||
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();
|
||||
}
|
||||
|
||||
|
|
|
@ -29,6 +29,13 @@
|
|||
android:key="prefPauseOnHeadsetDisconnect"
|
||||
android:summary="@string/pref_pauseOnHeadsetDisconnect_sum"
|
||||
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
|
||||
android:defaultValue="false"
|
||||
android:enabled="true"
|
||||
|
|
|
@ -38,6 +38,7 @@ public class UserPreferences implements
|
|||
private static final String TAG = "UserPreferences";
|
||||
|
||||
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_DOWNLOAD_MEDIA_ON_WIFI_ONLY = "prefDownloadMediaOnWifiOnly";
|
||||
public static final String PREF_UPDATE_INTERVAL = "prefAutoUpdateIntervall";
|
||||
|
@ -69,6 +70,7 @@ public class UserPreferences implements
|
|||
|
||||
// Preferences
|
||||
private boolean pauseOnHeadsetDisconnect;
|
||||
private boolean unpauseOnHeadsetReconnect;
|
||||
private boolean followQueue;
|
||||
private boolean downloadMediaOnWifiOnly;
|
||||
private long updateInterval;
|
||||
|
@ -121,6 +123,8 @@ public class UserPreferences implements
|
|||
R.integer.episode_cache_size_unlimited);
|
||||
pauseOnHeadsetDisconnect = sp.getBoolean(
|
||||
PREF_PAUSE_ON_HEADSET_DISCONNECT, true);
|
||||
unpauseOnHeadsetReconnect = sp.getBoolean(
|
||||
PREF_UNPAUSE_ON_HEADSET_RECONNECT, true);
|
||||
followQueue = sp.getBoolean(PREF_FOLLOW_QUEUE, false);
|
||||
downloadMediaOnWifiOnly = sp.getBoolean(
|
||||
PREF_DOWNLOAD_MEDIA_ON_WIFI_ONLY, true);
|
||||
|
@ -221,6 +225,11 @@ public class UserPreferences implements
|
|||
return instance.pauseOnHeadsetDisconnect;
|
||||
}
|
||||
|
||||
public static boolean isUnpauseOnHeadsetReconnect() {
|
||||
instanceAvailable();
|
||||
return instance.unpauseOnHeadsetReconnect;
|
||||
}
|
||||
|
||||
public static boolean isFollowQueue() {
|
||||
instanceAvailable();
|
||||
return instance.followQueue;
|
||||
|
@ -388,6 +397,8 @@ public class UserPreferences implements
|
|||
seekDeltaSecs = Integer.valueOf(sp.getString(PREF_SEEK_DELTA_SECS, "30"));
|
||||
} else if (key.equals(PREF_PAUSE_ON_HEADSET_DISCONNECT)) {
|
||||
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)) {
|
||||
autoFlattrPlayedDurationThreshold = sp.getFloat(PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD,
|
||||
PREF_AUTO_FLATTR_PLAYED_DURATION_THRESHOLD_DEFAULT);
|
||||
|
|
|
@ -144,6 +144,10 @@ public class PlaybackService extends Service {
|
|||
* Is true if service has received a valid start command.
|
||||
*/
|
||||
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;
|
||||
|
||||
|
@ -206,6 +210,8 @@ public class PlaybackService extends Service {
|
|||
Intent.ACTION_HEADSET_PLUG));
|
||||
registerReceiver(shutdownReceiver, new IntentFilter(
|
||||
ACTION_SHUTDOWN_PLAYBACK_SERVICE));
|
||||
registerReceiver(bluetoothStateUpdated, new IntentFilter(
|
||||
AudioManager.ACTION_SCO_AUDIO_STATE_UPDATED));
|
||||
registerReceiver(audioBecomingNoisy, new IntentFilter(
|
||||
AudioManager.ACTION_AUDIO_BECOMING_NOISY));
|
||||
registerReceiver(skipCurrentEpisodeReceiver, new IntentFilter(
|
||||
|
@ -228,6 +234,7 @@ public class PlaybackService extends Service {
|
|||
|
||||
unregisterReceiver(headsetDisconnected);
|
||||
unregisterReceiver(shutdownReceiver);
|
||||
unregisterReceiver(bluetoothStateUpdated);
|
||||
unregisterReceiver(audioBecomingNoisy);
|
||||
unregisterReceiver(skipCurrentEpisodeReceiver);
|
||||
mediaPlayer.shutdown();
|
||||
|
@ -966,6 +973,7 @@ public class PlaybackService extends Service {
|
|||
private BroadcastReceiver headsetDisconnected = new BroadcastReceiver() {
|
||||
private static final String TAG = "headsetDisconnected";
|
||||
private static final int UNPLUGGED = 0;
|
||||
private static final int PLUGGED = 1;
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
|
@ -978,6 +986,10 @@ public class PlaybackService extends Service {
|
|||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "Headset was unplugged during playback.");
|
||||
pauseIfPauseOnDisconnect();
|
||||
} else if (state == PLUGGED) {
|
||||
if (BuildConfig.DEBUG)
|
||||
Log.d(TAG, "Headset was plugged in during playback.");
|
||||
unpauseIfPauseOnDisconnect();
|
||||
}
|
||||
} else {
|
||||
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() {
|
||||
|
||||
@Override
|
||||
|
@ -1003,6 +1030,9 @@ public class PlaybackService extends Service {
|
|||
*/
|
||||
private void pauseIfPauseOnDisconnect() {
|
||||
if (UserPreferences.isPauseOnHeadsetDisconnect()) {
|
||||
if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) {
|
||||
transientPause = true;
|
||||
}
|
||||
if (UserPreferences.isPersistNotify()) {
|
||||
mediaPlayer.pause(false, true);
|
||||
} 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() {
|
||||
|
||||
@Override
|
||||
|
|
|
@ -586,6 +586,10 @@ public class PlaybackServiceMediaPlayer {
|
|||
return mediaType;
|
||||
}
|
||||
|
||||
public PlayerStatus getPlayerStatus() {
|
||||
return playerStatus;
|
||||
}
|
||||
|
||||
public boolean isStreaming() {
|
||||
return stream;
|
||||
}
|
||||
|
|
|
@ -205,6 +205,7 @@
|
|||
<string name="services_label">Services</string>
|
||||
<string name="flattr_label">Flattr</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="playback_pref">Playback</string>
|
||||
<string name="network_pref">Network</string>
|
||||
|
@ -214,6 +215,7 @@
|
|||
<string name="pref_followQueue_title">Continuous playback</string>
|
||||
<string name="pref_downloadMediaOnWifiOnly_title">WiFi media download</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_sum">Allow updates over the mobile data connection</string>
|
||||
<string name="refreshing_label">Refreshing</string>
|
||||
|
|
Loading…
Reference in New Issue