diff options
author | owner <owner@DeeDee-Laptop> | 2012-07-11 21:50:39 -0700 |
---|---|---|
committer | owner <owner@DeeDee-Laptop> | 2012-07-11 21:50:39 -0700 |
commit | d0cfa561bc65b917bdfb480adf689c05a4a71510 (patch) | |
tree | 727a01789e9ebd787953b87845d0c9513952e5c5 /subsonic-android/src | |
parent | d1efd47f41c09668c1311e50a3dff2d35189606b (diff) | |
download | dsub-d0cfa561bc65b917bdfb480adf689c05a4a71510.tar.gz dsub-d0cfa561bc65b917bdfb480adf689c05a4a71510.tar.bz2 dsub-d0cfa561bc65b917bdfb480adf689c05a4a71510.zip |
Added prev/pause/next buttons to notification bar
Diffstat (limited to 'subsonic-android/src')
-rw-r--r-- | subsonic-android/src/github/daneren2005/subphonic/util/Util.java | 51 |
1 files changed, 37 insertions, 14 deletions
diff --git a/subsonic-android/src/github/daneren2005/subphonic/util/Util.java b/subsonic-android/src/github/daneren2005/subphonic/util/Util.java index c8711a77..468cbbdf 100644 --- a/subsonic-android/src/github/daneren2005/subphonic/util/Util.java +++ b/subsonic-android/src/github/daneren2005/subphonic/util/Util.java @@ -41,6 +41,7 @@ import android.os.Handler; import android.util.Log; import android.view.Gravity; import android.view.ViewGroup; +import android.view.KeyEvent; import android.widget.LinearLayout; import android.widget.RemoteViews; import android.widget.TextView; @@ -570,7 +571,8 @@ public final class Util { // Use the same text for the ticker and the expanded notification String title = song.getTitle(); - String text = song.getArtist(); + String arist = song.getArtist(); + String album = song.getAlbum(); // Set the icon, scrolling text and timestamp final Notification notification = new Notification(R.drawable.stat_notify_playing, title, System.currentTimeMillis()); @@ -579,23 +581,24 @@ public final class Util { RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification); // Set the album art. - try { - int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); + try { + int size = context.getResources().getDrawable(R.drawable.unknown_album).getIntrinsicHeight(); Bitmap bitmap = FileUtil.getAlbumArtBitmap(context, song, size); - if (bitmap == null) { - // set default album art - contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); - } else { - contentView.setImageViewBitmap(R.id.notification_image, bitmap); - } - } catch (Exception x) { - Log.w(TAG, "Failed to get notification cover art", x); - contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); - } + if (bitmap == null) { + // set default album art + contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); + } else { + contentView.setImageViewBitmap(R.id.notification_image, bitmap); + } + } catch (Exception x) { + Log.w(TAG, "Failed to get notification cover art", x); + contentView.setImageViewResource(R.id.notification_image, R.drawable.unknown_album); + } // set the text for the notifications contentView.setTextViewText(R.id.notification_title, title); - contentView.setTextViewText(R.id.notification_artist, text); + contentView.setTextViewText(R.id.notification_artist, arist); + contentView.setTextViewText(R.id.notification_album, album); Pair<Integer, Integer> colors = getNotificationTextColors(context); if (colors.getFirst() != null) { @@ -609,6 +612,26 @@ public final class Util { Intent notificationIntent = new Intent(context, DownloadActivity.class); notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0); + + // Create actions for media buttons + PendingIntent pendingIntent; + Intent prevIntent = new Intent("1"); + 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); + contentView.setOnClickPendingIntent(R.id.control_previous, pendingIntent); + + Intent pauseIntent = new Intent("2"); + pauseIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); + pauseIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE)); + pendingIntent = PendingIntent.getService(context, 0, pauseIntent, 0); + contentView.setOnClickPendingIntent(R.id.control_pause, pendingIntent); + + Intent nextIntent = new Intent("3"); + nextIntent.setComponent(new ComponentName(context, DownloadServiceImpl.class)); + nextIntent.putExtra(Intent.EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_DOWN, KeyEvent.KEYCODE_MEDIA_NEXT)); + pendingIntent = PendingIntent.getService(context, 0, nextIntent, 0); + contentView.setOnClickPendingIntent(R.id.control_next, pendingIntent); // Send the notification and put the service in the foreground. handler.post(new Runnable() { |