diff options
author | Tom Hennen <tom.hennen@gmail.com> | 2015-10-31 11:33:10 -0400 |
---|---|---|
committer | Tom Hennen <tom.hennen@gmail.com> | 2015-10-31 11:33:10 -0400 |
commit | 3cc5eee0ff2d5eb650a71c78235229422322a3a6 (patch) | |
tree | b32434645711b09be9b6ce85adcd0a0df1e74b29 | |
parent | fe0bc61c7e46560ea982337c6537336dfb29a253 (diff) | |
download | AntennaPod-3cc5eee0ff2d5eb650a71c78235229422322a3a6.zip |
Have a different option for bluetooth reconnect.
Vibrate when starting playback due to bluetooth reconnect.
fixes AntennaPod/AntennaPod#1305
5 files changed, 44 insertions, 7 deletions
diff --git a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java index 8de4ba3c8..fabc399ba 100644 --- a/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java +++ b/app/src/androidTest/java/de/test/antennapod/ui/PreferencesTest.java @@ -125,6 +125,18 @@ public class PreferencesTest extends ActivityInstrumentationTestCase2<Preference assertTrue(solo.waitForCondition(() -> unpauseOnHeadsetReconnect == UserPreferences.isUnpauseOnHeadsetReconnect(), Timeout.getLargeTimeout())); } + public void testBluetoothReconnect() { + if(UserPreferences.isPauseOnHeadsetDisconnect() == false) { + solo.clickOnText(solo.getString(R.string.pref_pauseOnHeadsetDisconnect_title)); + assertTrue(solo.waitForCondition(() -> UserPreferences.isPauseOnHeadsetDisconnect(), Timeout.getLargeTimeout())); + } + final boolean unpauseOnBluetoothReconnect = UserPreferences.isUnpauseOnBluetoothReconnect(); + solo.clickOnText(solo.getString(R.string.pref_unpauseOnBluetoothReconnect_title)); + assertTrue(solo.waitForCondition(() -> unpauseOnBluetoothReconnect != UserPreferences.isUnpauseOnBluetoothReconnect(), Timeout.getLargeTimeout())); + solo.clickOnText(solo.getString(R.string.pref_unpauseOnBluetoothReconnect_title)); + assertTrue(solo.waitForCondition(() -> unpauseOnBluetoothReconnect == UserPreferences.isUnpauseOnBluetoothReconnect(), Timeout.getLargeTimeout())); + } + public void testContinuousPlayback() { final boolean continuousPlayback = UserPreferences.isFollowQueue(); solo.clickOnText(solo.getString(R.string.pref_followQueue_title)); diff --git a/app/src/main/res/xml/preferences.xml b/app/src/main/res/xml/preferences.xml index 8d507663a..bc020fb36 100644 --- a/app/src/main/res/xml/preferences.xml +++ b/app/src/main/res/xml/preferences.xml @@ -73,7 +73,7 @@ android:defaultValue="true" android:enabled="true" android:key="prefPauseOnHeadsetDisconnect" - android:summary="@string/pref_pauseOnHeadsetDisconnect_sum" + android:summary="@string/pref_pauseOnDisconnect_sum" android:title="@string/pref_pauseOnHeadsetDisconnect_title"/> <CheckBoxPreference android:defaultValue="true" @@ -83,6 +83,13 @@ android:summary="@string/pref_unpauseOnHeadsetReconnect_sum" android:title="@string/pref_unpauseOnHeadsetReconnect_title"/> <CheckBoxPreference + android:defaultValue="false" + android:enabled="true" + android:dependency="prefPauseOnHeadsetDisconnect" + android:key="prefUnpauseOnBluetoothReconnect" + android:summary="@string/pref_unpauseOnBluetoothReconnect_sum" + android:title="@string/pref_unpauseOnBluetoothReconnect_title"/> + <CheckBoxPreference android:defaultValue="true" android:enabled="true" android:key="prefFollowQueue" diff --git a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java index 006c48b26..84e349535 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java +++ b/core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java @@ -60,6 +60,7 @@ public class UserPreferences { // Playback 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_UNPAUSE_ON_BLUETOOTH_RECONNECT = "prefUnpauseOnBluetoothReconnect"; public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue"; public static final String PREF_SKIP_KEEPS_EPISODE = "prefSkipKeepsEpisode"; public static final String PREF_AUTO_DELETE = "prefAutoDelete"; @@ -221,6 +222,10 @@ public class UserPreferences { return prefs.getBoolean(PREF_UNPAUSE_ON_HEADSET_RECONNECT, true); } + public static boolean isUnpauseOnBluetoothReconnect() { + return prefs.getBoolean(PREF_UNPAUSE_ON_BLUETOOTH_RECONNECT, false); + } + public static boolean isFollowQueue() { return prefs.getBoolean(PREF_FOLLOW_QUEUE, true); diff --git a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java index 5cef2fe79..ab78387a2 100644 --- a/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java +++ b/core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java @@ -18,6 +18,7 @@ import android.media.MediaPlayer; import android.os.Binder; import android.os.Build; import android.os.IBinder; +import android.os.Vibrator; import android.preference.PreferenceManager; import android.support.v4.app.NotificationCompat; import android.util.Log; @@ -531,7 +532,7 @@ public class PlaybackService extends Service { @Override public boolean onMediaPlayerError(Object inObj, int what, int extra) { - final String TAG = "PlaybackService.onErrorListener"; + final String TAG = "PlaybackSvc.onErrorLtsn"; Log.w(TAG, "An error has occured: " + what + " " + extra); if (mediaPlayer.getPlayerStatus() == PlayerStatus.PLAYING) { mediaPlayer.pause(true, false); @@ -1022,7 +1023,7 @@ public class PlaybackService extends Service { pauseIfPauseOnDisconnect(); } else if (state == PLUGGED) { Log.d(TAG, "Headset was plugged in during playback."); - unpauseIfPauseOnDisconnect(); + unpauseIfPauseOnDisconnect(false); } } else { Log.e(TAG, "Received invalid ACTION_HEADSET_PLUG intent"); @@ -1038,7 +1039,7 @@ public class PlaybackService extends Service { int state = intent.getIntExtra(BluetoothA2dp.EXTRA_STATE, -1); if (state == BluetoothA2dp.STATE_CONNECTED) { Log.d(TAG, "Received bluetooth connection intent"); - unpauseIfPauseOnDisconnect(); + unpauseIfPauseOnDisconnect(true); } } } @@ -1071,10 +1072,20 @@ public class PlaybackService extends Service { } } - private void unpauseIfPauseOnDisconnect() { + /** + * @param bluetooth true if the event for unpausing came from bluetooth + */ + private void unpauseIfPauseOnDisconnect(boolean bluetooth) { if (transientPause) { transientPause = false; - if (UserPreferences.isPauseOnHeadsetDisconnect() && UserPreferences.isUnpauseOnHeadsetReconnect()) { + if (!bluetooth && UserPreferences.isUnpauseOnHeadsetReconnect()) { + mediaPlayer.resume(); + } else if (bluetooth && UserPreferences.isUnpauseOnBluetoothReconnect()){ + // let the user know we've started playback again... + Vibrator v = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE); + if(v != null) { + v.vibrate(500); + } mediaPlayer.resume(); } } diff --git a/core/src/main/res/values/strings.xml b/core/src/main/res/values/strings.xml index f50f271ed..0a8e95639 100644 --- a/core/src/main/res/values/strings.xml +++ b/core/src/main/res/values/strings.xml @@ -276,8 +276,9 @@ <string name="flattr_label">Flattr</string> <string name="pref_episode_cleanup_title">Episode Cleanup</string> <string name="pref_episode_cleanup_summary">Episodes that aren\'t in the queue and aren\'t favorites should be eligible for removal if space is needed</string> - <string name="pref_pauseOnHeadsetDisconnect_sum">Pause playback when the headphones are disconnected</string> + <string name="pref_pauseOnDisconnect_sum">Pause playback when the headphones or Bluetooth are disconnected</string> <string name="pref_unpauseOnHeadsetReconnect_sum">Resume playback when the headphones are reconnected</string> + <string name="pref_unpauseOnBluetoothReconnect_sum">Resume playback when bluetooth reconnects</string> <string name="pref_followQueue_sum">Jump to next queue item when playback completes</string> <string name="pref_auto_delete_sum">Delete episode when playback completes</string> <string name="pref_auto_delete_title">Auto Delete</string> @@ -298,6 +299,7 @@ <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_unpauseOnBluetoothReconnect_title">Bluetooth 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> |