aboutsummaryrefslogtreecommitdiff
path: root/app/src/main
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2016-06-23 17:43:15 -0700
committerScott Jackson <daneren2005@gmail.com>2016-06-23 17:43:15 -0700
commit031417c0b9fec1e177ce8e8d2304a4c094e635f4 (patch)
tree2caea307d2caa345b435cc688a4c497e85207458 /app/src/main
parent8c29aa1f88041e4d90edecddd8dbb72254bfa79d (diff)
downloaddsub-031417c0b9fec1e177ce8e8d2304a4c094e635f4.tar.gz
dsub-031417c0b9fec1e177ce8e8d2304a4c094e635f4.tar.bz2
dsub-031417c0b9fec1e177ce8e8d2304a4c094e635f4.zip
Override MediaSession's handling of KeyEvents to get custom logic (ie: double press to skip)
Diffstat (limited to 'app/src/main')
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadService.java5
-rw-r--r--app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java2
-rw-r--r--app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java16
3 files changed, 22 insertions, 1 deletions
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
index eb55ba93..3d3a23b8 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadService.java
@@ -87,6 +87,7 @@ import android.support.v7.media.MediaRouteSelector;
import android.support.v7.media.MediaRouter;
import android.util.Log;
import android.support.v4.util.LruCache;
+import android.view.KeyEvent;
/**
* @author Sindre Mehus
@@ -2663,6 +2664,10 @@ public class DownloadService extends Service {
wakeLock.acquire(ms);
}
+ public void handleKeyEvent(KeyEvent keyEvent) {
+ lifecycleSupport.handleKeyEvent(keyEvent);
+ }
+
public void addOnSongChangedListener(OnSongChangedListener listener) {
addOnSongChangedListener(listener, false);
}
diff --git a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index 5e9e04fc..f8272356 100644
--- a/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/app/src/main/java/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -386,7 +386,7 @@ public class DownloadServiceLifecycleSupport {
return lastChange;
}
- private void handleKeyEvent(KeyEvent event) {
+ public void handleKeyEvent(KeyEvent event) {
if(event.getAction() == KeyEvent.ACTION_DOWN && event.getRepeatCount() > 0) {
switch (event.getKeyCode()) {
case RemoteControlClient.FLAG_KEY_MEDIA_PREVIOUS:
diff --git a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
index d97a859b..df468155 100644
--- a/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
+++ b/app/src/main/java/github/daneren2005/dsub/util/compat/RemoteControlClientLP.java
@@ -34,7 +34,10 @@ import android.media.session.PlaybackState;
import android.os.Build;
import android.os.Bundle;
import android.provider.MediaStore;
+import android.support.annotation.NonNull;
import android.support.v7.media.MediaRouter;
+import android.util.Log;
+import android.view.KeyEvent;
import java.io.Serializable;
import java.util.ArrayList;
@@ -580,5 +583,18 @@ public class RemoteControlClientLP extends RemoteControlClientBase {
downloadService.toggleStarred();
}
}
+
+ @Override
+ public boolean onMediaButtonEvent(@NonNull Intent mediaButtonIntent) {
+ if (getMediaSession() != null && Intent.ACTION_MEDIA_BUTTON.equals(mediaButtonIntent.getAction())) {
+ KeyEvent keyEvent = mediaButtonIntent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
+ if (keyEvent != null) {
+ downloadService.handleKeyEvent(keyEvent);
+ return true;
+ }
+ }
+
+ return super.onMediaButtonEvent(mediaButtonIntent);
+ }
}
}