aboutsummaryrefslogtreecommitdiff
path: root/subsonic-android/src/github/daneren2005
diff options
context:
space:
mode:
authorScott Jackson <daneren2005@gmail.com>2013-01-07 20:08:47 -0800
committerScott Jackson <daneren2005@gmail.com>2013-01-07 20:08:47 -0800
commite74bc4ac24266250eee67249057b401646ddfb4f (patch)
tree0feed03846248ce75f8da2206181ed17955b03a8 /subsonic-android/src/github/daneren2005
parent3f5a1d0c2707f8318e42bc109b7d5df2e8c401eb (diff)
downloaddsub-e74bc4ac24266250eee67249057b401646ddfb4f.tar.gz
dsub-e74bc4ac24266250eee67249057b401646ddfb4f.tar.bz2
dsub-e74bc4ac24266250eee67249057b401646ddfb4f.zip
Closes #79 Expandable Notifications
Diffstat (limited to 'subsonic-android/src/github/daneren2005')
-rw-r--r--subsonic-android/src/github/daneren2005/dsub/util/Util.java93
1 files changed, 51 insertions, 42 deletions
diff --git a/subsonic-android/src/github/daneren2005/dsub/util/Util.java b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
index 015cffe9..09aa570c 100644
--- a/subsonic-android/src/github/daneren2005/dsub/util/Util.java
+++ b/subsonic-android/src/github/daneren2005/dsub/util/Util.java
@@ -614,51 +614,71 @@ public final class Util {
.show();
}
- public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) {
+ public static void showPlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler, MusicDirectory.Entry song) {
- // Use the same text for the ticker and the expanded notification
- String title = song.getTitle();
- 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());
+ final Notification notification = new Notification(R.drawable.stat_notify_playing, song.getTitle(), System.currentTimeMillis());
notification.flags |= Notification.FLAG_NO_CLEAR | Notification.FLAG_ONGOING_EVENT;
- RemoteViews contentView = new RemoteViews(context.getPackageName(), R.layout.notification);
+ if (Build.VERSION.SDK_INT>= Build.VERSION_CODES.JELLY_BEAN){
+ RemoteViews expandedContentView = new RemoteViews(context.getPackageName(), R.layout.notification_expanded);
+ setupViews(expandedContentView,context,song);
+ notification.bigContentView = expandedContentView;
+ }
+
+ RemoteViews smallContentView = new RemoteViews(context.getPackageName(), R.layout.notification);
+ setupViews(smallContentView, context, song);
+ notification.contentView = smallContentView;
+
+ Intent notificationIntent = new Intent(context, DownloadActivity.class);
+ notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
+
+ // Send the notification and put the service in the foreground.
+ handler.post(new Runnable() {
+ @Override
+ public void run() {
+ downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification);
+ }
+ });
- // Set the album art.
+ // Update widget
+ DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true);
+ }
+
+ private static void setupViews(RemoteViews rv, Context context, MusicDirectory.Entry song){
+
+ // Use the same text for the ticker and the expanded notification
+ String title = song.getTitle();
+ String arist = song.getArtist();
+ String album = song.getAlbum();
+
+ // Set the album art.
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);
+ // set default album art
+ rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
} else {
- contentView.setImageViewBitmap(R.id.notification_image, bitmap);
+ rv.setImageViewBitmap(R.id.notification_image, bitmap);
}
- } catch (Exception x) {
+ } 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, arist);
- contentView.setTextViewText(R.id.notification_album, album);
-
+ rv.setImageViewResource(R.id.notification_image, R.drawable.unknown_album);
+ }
+
+ // set the text for the notifications
+ rv.setTextViewText(R.id.notification_title, title);
+ rv.setTextViewText(R.id.notification_artist, arist);
+ rv.setTextViewText(R.id.notification_album, album);
+
Pair<Integer, Integer> colors = getNotificationTextColors(context);
if (colors.getFirst() != null) {
- contentView.setTextColor(R.id.notification_title, colors.getFirst());
+ rv.setTextColor(R.id.notification_title, colors.getFirst());
}
if (colors.getSecond() != null) {
- contentView.setTextColor(R.id.notification_artist, colors.getSecond());
+ rv.setTextColor(R.id.notification_artist, colors.getSecond());
}
-
- notification.contentView = contentView;
-
- Intent notificationIntent = new Intent(context, DownloadActivity.class);
- notification.contentIntent = PendingIntent.getActivity(context, 0, notificationIntent, 0);
// Create actions for media buttons
PendingIntent pendingIntent;
@@ -666,30 +686,19 @@ public final class Util {
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);
+ rv.setOnClickPendingIntent(R.id.control_previous, pendingIntent);
Intent pauseIntent = new Intent("KEYCODE_MEDIA_PLAY_PAUSE");
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);
+ rv.setOnClickPendingIntent(R.id.control_pause, pendingIntent);
Intent nextIntent = new Intent("KEYCODE_MEDIA_NEXT");
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() {
- @Override
- public void run() {
- downloadService.startForeground(Constants.NOTIFICATION_ID_PLAYING, notification);
- }
- });
-
- // Update widget
- DSubWidgetProvider.getInstance().notifyChange(context, downloadService, true);
+ rv.setOnClickPendingIntent(R.id.control_next, pendingIntent);
}
public static void hidePlayingNotification(final Context context, final DownloadServiceImpl downloadService, Handler handler) {