diff options
author | Scott Jackson <daneren2005@gmail.com> | 2013-01-07 20:08:47 -0800 |
---|---|---|
committer | Scott Jackson <daneren2005@gmail.com> | 2013-01-07 20:08:47 -0800 |
commit | e74bc4ac24266250eee67249057b401646ddfb4f (patch) | |
tree | 0feed03846248ce75f8da2206181ed17955b03a8 | |
parent | 3f5a1d0c2707f8318e42bc109b7d5df2e8c401eb (diff) | |
download | dsub-e74bc4ac24266250eee67249057b401646ddfb4f.tar.gz dsub-e74bc4ac24266250eee67249057b401646ddfb4f.tar.bz2 dsub-e74bc4ac24266250eee67249057b401646ddfb4f.zip |
Closes #79 Expandable Notifications
-rw-r--r-- | subsonic-android/AndroidManifest.xml | 2 | ||||
-rw-r--r-- | subsonic-android/project.properties | 2 | ||||
-rw-r--r-- | subsonic-android/res/layout/notification_expanded.xml | 100 | ||||
-rw-r--r-- | subsonic-android/src/github/daneren2005/dsub/util/Util.java | 93 |
4 files changed, 153 insertions, 44 deletions
diff --git a/subsonic-android/AndroidManifest.xml b/subsonic-android/AndroidManifest.xml index 4f45d23e..9561fae6 100644 --- a/subsonic-android/AndroidManifest.xml +++ b/subsonic-android/AndroidManifest.xml @@ -15,7 +15,7 @@ <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.BLUETOOTH" />
- <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="15"/>
+ <uses-sdk android:minSdkVersion="7" android:targetSdkVersion="16"/>
<supports-screens android:anyDensity="true" android:xlargeScreens="true" android:largeScreens="true" android:normalScreens="true" android:smallScreens="true"/>
diff --git a/subsonic-android/project.properties b/subsonic-android/project.properties index 0b3adc12..9b3b31a8 100644 --- a/subsonic-android/project.properties +++ b/subsonic-android/project.properties @@ -8,5 +8,5 @@ # project structure. # Project target. -target=android-15 +target=android-16 android.library.reference.1=../../ActionBarSherlock diff --git a/subsonic-android/res/layout/notification_expanded.xml b/subsonic-android/res/layout/notification_expanded.xml new file mode 100644 index 00000000..70e7269c --- /dev/null +++ b/subsonic-android/res/layout/notification_expanded.xml @@ -0,0 +1,100 @@ +<?xml version="1.0" encoding="utf-8"?> +<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" + android:id="@+id/statusbar" + android:layout_width="fill_parent" + android:layout_height="fill_parent" + android:orientation="horizontal" > + + <ImageView + android:id="@+id/notification_image" + android:layout_width="128dp" + android:layout_height="128dp" + android:gravity="center" /> + + <LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_weight="0.0" + android:orientation="vertical" + android:paddingLeft="11.0dip" > + + <TextView + android:id="@+id/notification_title" + style="@android:style/TextAppearance.StatusBar.EventContent.Title" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:ellipsize="marquee" + android:focusable="true" + android:singleLine="true" /> + + <TextView + android:id="@+id/notification_artist" + style="@android:style/TextAppearance.StatusBar.EventContent" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:ellipsize="end" + android:scrollHorizontally="true" + android:singleLine="true" /> + + <TextView + android:id="@+id/notification_album" + style="@android:style/TextAppearance.StatusBar.EventContent" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="left" + android:ellipsize="end" + android:scrollHorizontally="true" + android:singleLine="true" /> + + <TextView + android:id="@+id/textView1" + android:layout_width="wrap_content" + android:layout_height="fill_parent" /> + + <LinearLayout + xmlns:android="http://schemas.android.com/apk/res/android" + android:layout_width="fill_parent" + android:layout_height="wrap_content" + android:layout_gravity="center|fill" + android:gravity="center_horizontal" + android:orientation="horizontal" > + + <ImageButton + android:id="@+id/control_previous" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_weight="0.0" + android:background="@drawable/btn_bg" + android:scaleType="fitXY" + android:src="@drawable/notification_prev" /> + + <ImageButton + android:id="@+id/control_pause" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_marginLeft="10dp" + android:layout_marginRight="10dp" + android:layout_weight="0.0" + android:background="@drawable/btn_bg" + android:scaleType="fitXY" + android:src="@drawable/notification_pause" /> + + <ImageButton + android:id="@+id/control_next" + android:layout_width="wrap_content" + android:layout_height="wrap_content" + android:layout_gravity="center" + android:layout_weight="0.0" + android:background="@drawable/btn_bg" + android:scaleType="fitXY" + android:src="@drawable/notification_next" /> + </LinearLayout> + + </LinearLayout> + +</LinearLayout> 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) { |