summaryrefslogtreecommitdiff
path: root/core/src/main/java/de/danoeh
diff options
context:
space:
mode:
authorTim Schumacher <tim@timakro.de>2021-02-03 12:50:01 +0100
committerGitHub <noreply@github.com>2021-02-03 12:50:01 +0100
commit1297a168507d691a29092c89f46000736a753a04 (patch)
tree13576e693ea67242d90c1c73abbd51c153e19243 /core/src/main/java/de/danoeh
parent4ff6ff4fb73614de6498f9562bbbf392f69a6fae (diff)
downloadAntennaPod-1297a168507d691a29092c89f46000736a753a04.zip
Allow remapping hardware buttons (#4881)
Diffstat (limited to 'core/src/main/java/de/danoeh')
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/preferences/UserPreferences.java15
-rw-r--r--core/src/main/java/de/danoeh/antennapod/core/service/playback/PlaybackService.java37
2 files changed, 24 insertions, 28 deletions
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 ed9c519a6..3d8d1b6bc 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
@@ -6,6 +6,7 @@ import android.content.res.Configuration;
import android.os.Build;
import android.text.TextUtils;
import android.util.Log;
+import android.view.KeyEvent;
import androidx.annotation.IntRange;
import androidx.annotation.NonNull;
@@ -76,8 +77,8 @@ public class UserPreferences {
public static final String PREF_PAUSE_ON_HEADSET_DISCONNECT = "prefPauseOnHeadsetDisconnect";
public static final String PREF_UNPAUSE_ON_HEADSET_RECONNECT = "prefUnpauseOnHeadsetReconnect";
private static final String PREF_UNPAUSE_ON_BLUETOOTH_RECONNECT = "prefUnpauseOnBluetoothReconnect";
- private static final String PREF_HARDWARE_FOWARD_BUTTON_SKIPS = "prefHardwareForwardButtonSkips";
- private static final String PREF_HARDWARE_PREVIOUS_BUTTON_RESTARTS = "prefHardwarePreviousButtonRestarts";
+ public static final String PREF_HARDWARE_FORWARD_BUTTON = "prefHardwareForwardButton";
+ public static final String PREF_HARDWARE_PREVIOUS_BUTTON = "prefHardwarePreviousButton";
public static final String PREF_FOLLOW_QUEUE = "prefFollowQueue";
public static final String PREF_SKIP_KEEPS_EPISODE = "prefSkipKeepsEpisode";
private static final String PREF_FAVORITE_KEEPS_EPISODE = "prefFavoriteKeepsEpisode";
@@ -373,12 +374,14 @@ public class UserPreferences {
return prefs.getBoolean(PREF_UNPAUSE_ON_BLUETOOTH_RECONNECT, false);
}
- public static boolean shouldHardwareButtonSkip() {
- return prefs.getBoolean(PREF_HARDWARE_FOWARD_BUTTON_SKIPS, false);
+ public static int getHardwareForwardButton() {
+ return Integer.parseInt(prefs.getString(PREF_HARDWARE_FORWARD_BUTTON,
+ String.valueOf(KeyEvent.KEYCODE_MEDIA_FAST_FORWARD)));
}
- public static boolean shouldHardwarePreviousButtonRestart() {
- return prefs.getBoolean(PREF_HARDWARE_PREVIOUS_BUTTON_RESTARTS, false);
+ public static int getHardwarePreviousButton() {
+ return Integer.parseInt(prefs.getString(PREF_HARDWARE_PREVIOUS_BUTTON,
+ String.valueOf(KeyEvent.KEYCODE_MEDIA_REWIND)));
}
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 495ac40c7..c635243c7 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
@@ -668,18 +668,14 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
return false;
case KeyEvent.KEYCODE_MEDIA_NEXT:
- if (getStatus() != PlayerStatus.PLAYING && getStatus() != PlayerStatus.PAUSED) {
- return false;
- } else if (notificationButton || UserPreferences.shouldHardwareButtonSkip()) {
- // assume the skip command comes from a notification or the lockscreen
- // a >| skip button should actually skip
+ if (!notificationButton) {
+ // Handle remapped button as notification button which is not remapped again.
+ return handleKeycode(UserPreferences.getHardwareForwardButton(), true);
+ } else if (getStatus() == PlayerStatus.PLAYING || getStatus() == PlayerStatus.PAUSED) {
mediaPlayer.skip();
- } else {
- // assume skip command comes from a (bluetooth) media button
- // user actually wants to fast-forward
- seekDelta(UserPreferences.getFastForwardSecs() * 1000);
+ return true;
}
- return true;
+ return false;
case KeyEvent.KEYCODE_MEDIA_FAST_FORWARD:
if (getStatus() == PlayerStatus.PLAYING || getStatus() == PlayerStatus.PAUSED) {
mediaPlayer.seekDelta(UserPreferences.getFastForwardSecs() * 1000);
@@ -687,23 +683,20 @@ public class PlaybackService extends MediaBrowserServiceCompat {
}
return false;
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
- if (getStatus() != PlayerStatus.PLAYING && getStatus() != PlayerStatus.PAUSED) {
- return false;
- } else if (UserPreferences.shouldHardwarePreviousButtonRestart()) {
- // user wants to restart current episode
+ if (!notificationButton) {
+ // Handle remapped button as notification button which is not remapped again.
+ return handleKeycode(UserPreferences.getHardwarePreviousButton(), true);
+ } else if (getStatus() == PlayerStatus.PLAYING || getStatus() == PlayerStatus.PAUSED) {
mediaPlayer.seekTo(0);
- } else {
- // user wants to rewind current episode
- mediaPlayer.seekDelta(-UserPreferences.getRewindSecs() * 1000);
+ return true;
}
- return true;
+ return false;
case KeyEvent.KEYCODE_MEDIA_REWIND:
if (getStatus() == PlayerStatus.PLAYING || getStatus() == PlayerStatus.PAUSED) {
mediaPlayer.seekDelta(-UserPreferences.getRewindSecs() * 1000);
- } else {
- return false;
+ return true;
}
- return true;
+ return false;
case KeyEvent.KEYCODE_MEDIA_STOP:
if (status == PlayerStatus.PLAYING) {
mediaPlayer.pause(true, true);
@@ -1911,7 +1904,7 @@ public class PlaybackService extends MediaBrowserServiceCompat {
Log.d(TAG, "onSkipToNext()");
UiModeManager uiModeManager = (UiModeManager) getApplicationContext()
.getSystemService(Context.UI_MODE_SERVICE);
- if (UserPreferences.shouldHardwareButtonSkip()
+ if (UserPreferences.getHardwareForwardButton() == KeyEvent.KEYCODE_MEDIA_NEXT
|| uiModeManager.getCurrentModeType() == Configuration.UI_MODE_TYPE_CAR) {
mediaPlayer.skip();
} else {