From 01c3f757a15679b18c3e5bf66074a877e6ed40cb Mon Sep 17 00:00:00 2001 From: orionlee Date: Fri, 9 Sep 2016 09:00:36 -0700 Subject: Issue #2105 : support optional rewind in lockscreen (by using skipToPrevious button) --- .../core/service/playback/PlaybackService.java | 25 ++++++++++++++++++++-- 1 file changed, 23 insertions(+), 2 deletions(-) (limited to 'core/src/main/java/de') 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 04b5b676d..d840c9fad 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 @@ -996,13 +996,34 @@ public class PlaybackService extends MediaBrowserServiceCompat { state = PlaybackStateCompat.STATE_NONE; } sessionState.setState(state, mediaPlayer.getPosition(), mediaPlayer.getPlaybackSpeed()); - sessionState.setActions(PlaybackStateCompat.ACTION_PLAY_PAUSE + long capabilities = PlaybackStateCompat.ACTION_PLAY_PAUSE | PlaybackStateCompat.ACTION_REWIND | PlaybackStateCompat.ACTION_FAST_FORWARD - | PlaybackStateCompat.ACTION_SKIP_TO_NEXT); + | PlaybackStateCompat.ACTION_SKIP_TO_NEXT; + + if (useSkipToPreviousForRewindInLockscreen()) { + // Workaround to fool Android so that Lockscreen will expose a skip-to-previous button, + // which will be used for rewind. + // + // @see #sessionCallback in the backing callback, skipToPrevious implementation + // is actually the same as rewind. So no new inconsistency is created. + capabilities = capabilities | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; + } + + sessionState.setActions(capabilities); mediaSession.setPlaybackState(sessionState.build()); } + private static boolean useSkipToPreviousForRewindInLockscreen() { + // showRewindOnCompactNotification() corresponds to the "Set Lockscreen Buttons" + // Settings in UI. + // Hence, from user perspective, he/she is setting the buttons for Loackscreen + // + // OPEN: it might contain other logic, e.g., the woakround might be applicable + // only to prev-Androidv5 devices. + return UserPreferences.showRewindOnCompactNotification(); + } + /** * Used by updateMediaSessionMetadata to load notification data in another thread. */ -- cgit v1.2.3 From 209058b3a7be15d8b3837ace29822eeb6d52960d Mon Sep 17 00:00:00 2001 From: orionlee Date: Sat, 10 Sep 2016 12:04:01 -0700 Subject: Make it explicit the lockscreen workaround is only relevant to pre Lollipop devices. --- .../antennapod/core/service/playback/PlaybackService.java | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'core/src/main/java/de') 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 d840c9fad..eca3d1bb9 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 @@ -1004,9 +1004,14 @@ public class PlaybackService extends MediaBrowserServiceCompat { if (useSkipToPreviousForRewindInLockscreen()) { // Workaround to fool Android so that Lockscreen will expose a skip-to-previous button, // which will be used for rewind. + // The workaround is used for pre Lollipop (Androidv5) devices. + // For Androidv5+, lockscreen widges are really notifications (compact), + // with an independent codepath // // @see #sessionCallback in the backing callback, skipToPrevious implementation - // is actually the same as rewind. So no new inconsistency is created. + // is actually the same as rewind. So no new inconsistency is created. + // @see #setupNotification() for the method to create Androidv5+ lockscreen UI + // with notification (compact) capabilities = capabilities | PlaybackStateCompat.ACTION_SKIP_TO_PREVIOUS; } @@ -1017,11 +1022,9 @@ public class PlaybackService extends MediaBrowserServiceCompat { private static boolean useSkipToPreviousForRewindInLockscreen() { // showRewindOnCompactNotification() corresponds to the "Set Lockscreen Buttons" // Settings in UI. - // Hence, from user perspective, he/she is setting the buttons for Loackscreen - // - // OPEN: it might contain other logic, e.g., the woakround might be applicable - // only to prev-Androidv5 devices. - return UserPreferences.showRewindOnCompactNotification(); + // Hence, from user perspective, he/she is setting the buttons for Lockscreen + return ( UserPreferences.showRewindOnCompactNotification() && + (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) ); } /** -- cgit v1.2.3