aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-03-19 21:16:11 -0700
committerScott Jackson <daneren2005@gmail.com>2013-03-19 21:16:11 -0700
commitc94e04c28be0a1bbc422a7eb6981b4ee27b22de0 (patch)
tree628a5c9fee7927db107c7ca3808a1312739ac046 /subsonic-android
parentbbc1312f861a6bc7d8099ac76cf0f77b5354fbb3 (diff)
downloaddsub-c94e04c28be0a1bbc422a7eb6981b4ee27b22de0.tar.gz
dsub-c94e04c28be0a1bbc422a7eb6981b4ee27b22de0.tar.bz2
dsub-c94e04c28be0a1bbc422a7eb6981b4ee27b22de0.zip
Added persistent notification
Diffstat (limited to 'subsonic-android')
-rw-r--r--subsonic-android/res/drawable/notification_stop.pngbin0 -> 338 bytes
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java37
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java2
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java32
5 files changed, 52 insertions, 21 deletions
diff --git a/subsonic-android/res/drawable/notification_stop.png b/subsonic-android/res/drawable/notification_stop.png
new file mode 100644
index 00000000..ab98e188
--- /dev/null
+++ b/subsonic-android/res/drawable/notification_stop.png
Binary files differ
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
index 889d7d2b..6286f906 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadService.java
@@ -86,6 +86,8 @@ public interface DownloadService {
void next();
void pause();
+
+ void stop();
void start();
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
index 4e7bbbb0..a88b44c3 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceImpl.java
@@ -501,12 +501,6 @@ public class DownloadServiceImpl extends Service implements DownloadService {
} else {
Util.broadcastNewTrackInfo(this, null);
}
-
- if (currentPlaying != null && showNotification) {
- Util.showPlayingNotification(this, this, handler, currentPlaying.getSong());
- } else {
- Util.hidePlayingNotification(this, this, handler);
- }
}
synchronized void setNextPlaying() {
@@ -716,6 +710,24 @@ public class DownloadServiceImpl extends Service implements DownloadService {
handleError(x);
}
}
+
+ @Override
+ public synchronized void stop() {
+ try {
+ if (playerState == STARTED) {
+ if (jukeboxEnabled) {
+ jukeboxService.stop();
+ } else {
+ mediaPlayer.pause();
+ }
+ setPlayerState(STOPPED);
+ } else if(playerState == PAUSED) {
+ setPlayerState(STOPPED);
+ }
+ } catch(Exception x) {
+ handleError(x);
+ }
+ }
@Override
public synchronized void start() {
@@ -793,8 +805,9 @@ public class DownloadServiceImpl extends Service implements DownloadService {
lifecycleSupport.serializeDownloadQueue();
}
- boolean show = this.playerState == PAUSED && playerState == PlayerState.STARTED;
- boolean hide = this.playerState == STARTED && playerState == PlayerState.PAUSED;
+ boolean show = playerState == PlayerState.STARTED;
+ boolean pause = this.playerState == STARTED && playerState == PlayerState.PAUSED;
+ boolean hide = playerState == PlayerState.STOPPED;
Util.broadcastPlaybackStatusChange(this, playerState);
this.playerState = playerState;
@@ -805,9 +818,11 @@ public class DownloadServiceImpl extends Service implements DownloadService {
if (show) {
Util.showPlayingNotification(this, this, handler, currentPlaying.getSong());
- } else if (hide) {
- Util.hidePlayingNotification(this, this, handler);
- }
+ } else if (pause) {
+ Util.showPlayingNotification(this, this, handler, currentPlaying.getSong());
+ } else if(hide) {
+ Util.hidePlayingNotification(this, this, handler);
+ }
mRemoteControl.setPlaybackState(playerState.getRemoteControlClientPlayState());
if (playerState == STARTED) {
diff --git a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
index 765e216b..de3c7d39 100644
--- a/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
+++ b/subsonic-android/src/github/daneren2005/dsub/service/DownloadServiceLifecycleSupport.java
@@ -233,7 +233,7 @@ public class DownloadServiceLifecycleSupport {
break;
case RemoteControlClient.FLAG_KEY_MEDIA_STOP:
case KeyEvent.KEYCODE_MEDIA_STOP:
- downloadService.reset();
+ downloadService.stop();
break;
case RemoteControlClient.FLAG_KEY_MEDIA_PLAY:
case KeyEvent.KEYCODE_MEDIA_PLAY:
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index bbbb0573..cf475a70 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -649,14 +649,15 @@ public final class Util {
final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis());
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
+ boolean playing = downloadService.getPlayerState() == PlayerState.STARTED;
if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN){
- RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
- setupViews(expandedContentView,context,song);
+ RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
+ setupViews(expandedContentView,context,song, playing);
notification.bigContentView = expandedContentView;
}
RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
- setupViews(smallContentView, context, song);
+ setupViews(smallContentView, context, song, playing);
notification.contentView = smallContentView;
Intent notificationIntent = new Intent(context, DownloadActivity.class);
@@ -674,7 +675,7 @@ public final class Util {
DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true);
}
- private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song){
+ private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song, boolean playing){
// Use the same text for the ticker and the expanded notification
String title = song.getTitle();
@@ -708,14 +709,27 @@ public final class Util {
if (colors.getSecond() != null) {
rv.setTextColor(R.id.notification_artist, colors.getSecond());
}
+
+ if(!playing) {
+ rv.setImageViewResource(R.id.control_pause, R.drawable.notification_play);
+ rv.setImageViewResource(R.id.control_previous, R.drawable.notification_stop);
+ }
// Create actions for media buttons
PendingIntent pendingIntent;
- Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS");
- prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
- prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
- pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
- rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
+ if(playing) {
+ Intent prevIntent = new Intent("KEYCODE_MEDIA_PREVIOUS");
+ prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
+ prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PREVIOUS));
+ pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
+ rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
+ } else {
+ Intent prevIntent = new Intent("KEYCODE_MEDIA_STOP");
+ prevIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));
+ prevIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_STOP));
+ pendingIntent = PendingIntent.getService(context, 0, prevIntent, 0);
+ rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
+ }
Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class));