aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorowner <owner@DeeDee-Laptop>2012-07-11 21:50:39 -0700
committerowner <owner@DeeDee-Laptop>2012-07-11 21:50:39 -0700
commitd0cfa561bc65b917bdfb480adf689c05a4a71510 (patch)
tree727a01789e9ebd787953b87845d0c9513952e5c5
parentd1efd47f41c09668c1311e50a3dff2d35189606b (diff)
downloaddsub-d0cfa561bc65b917bdfb480adf689c05a4a71510.tar.gz
dsub-d0cfa561bc65b917bdfb480adf689c05a4a71510.tar.bz2
dsub-d0cfa561bc65b917bdfb480adf689c05a4a71510.zip
Added prev/pause/next buttons to notification bar
-rw-r--r--subsonic-android/res/drawable/notification_next.pngbin0 -> 941 bytes
-rw-r--r--subsonic-android/res/drawable/notification_pause.pngbin0 -> 233 bytes
-rw-r--r--subsonic-android/res/drawable/notification_prev.pngbin0 -> 957 bytes
-rw-r--r--subsonic-android/res/layout/notification.xml124
-rw-r--r--subsonic-android/src/github/daneren2005/subphonic/util/Util.java51
5 files changed, 131 insertions, 44 deletions
diff --git a/subsonic-android/res/drawable/notification_next.png b/subsonic-android/res/drawable/notification_next.png
new file mode 100644
index 00000000..5835f654
--- /dev/null
+++ b/subsonic-android/res/drawable/notification_next.png
Binary files differ
diff --git a/subsonic-android/res/drawable/notification_pause.png b/subsonic-android/res/drawable/notification_pause.png
new file mode 100644
index 00000000..3324f88f
--- /dev/null
+++ b/subsonic-android/res/drawable/notification_pause.png
Binary files differ
diff --git a/subsonic-android/res/drawable/notification_prev.png b/subsonic-android/res/drawable/notification_prev.png
new file mode 100644
index 00000000..73fb16f2
--- /dev/null
+++ b/subsonic-android/res/drawable/notification_prev.png
Binary files differ
diff --git a/subsonic-android/res/layout/notification.xml b/subsonic-android/res/layout/notification.xml
index c2edfb9b..a234f71e 100644
--- a/subsonic-android/res/layout/notification.xml
+++ b/subsonic-android/res/layout/notification.xml
@@ -1,31 +1,95 @@
<?xml version="1.0" encoding="utf-8"?>
-<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
- android:layout_width="fill_parent"
- android:layout_height="fill_parent"
- android:padding="3dp">
- <ImageView
- android:id="@+id/notification_image"
- android:layout_width="wrap_content"
- android:layout_height="fill_parent"
- android:layout_marginRight="10dp"
- android:layout_marginLeft="5dp"/>
- <TextView
- android:id="@+id/notification_title"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:textSize="16sp"
- android:textStyle="bold"
- android:textColor="@color/notificationTitle"
- android:singleLine="true"
- android:layout_toRightOf="@id/notification_image"
- android:layout_alignParentTop="true"/>
- <TextView
- android:id="@+id/notification_artist"
- android:layout_height="wrap_content"
- android:layout_width="fill_parent"
- android:textSize="15sp"
- android:textColor="@color/notificationArtist"
- android:singleLine="true"
- android:layout_toRightOf="@id/notification_image"
- android:layout_below="@id/notification_title"/>
-</RelativeLayout>
+<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="vertical" >
+
+ <LinearLayout
+ xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:orientation="horizontal" >
+
+ <ImageView
+ android:id="@+id/notification_image"
+ android:layout_width="64.0dip"
+ android:layout_height="64.0dip"
+ android:layout_weight="0.0"
+ android:gravity="center" />
+
+ <LinearLayout
+ android:layout_width="0.0dp"
+ android:layout_height="wrap_content"
+ android:layout_gravity="center_vertical"
+ android:layout_weight="1.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" />
+ </LinearLayout>
+
+ <ImageButton
+ android:id="@+id/control_previous"
+ android:src="@drawable/notification_prev"
+ android:background="@android:color/transparent"
+ android:layout_width="40dip"
+ android:layout_height="40dip"
+ android:layout_gravity="center|right"
+ android:layout_marginRight="5dip"
+ android:layout_marginTop="2dip"
+ android:layout_weight="0.0"/>
+
+ <ImageButton
+ android:id="@+id/control_pause"
+ android:src="@drawable/notification_pause"
+ android:background="@android:color/transparent"
+ android:layout_width="40dip"
+ android:layout_height="40dip"
+ android:layout_gravity="center|right"
+ android:layout_marginRight="5dip"
+ android:layout_marginTop="2dip"
+ android:layout_weight="0.0"/>
+
+ <ImageButton
+ android:id="@+id/control_next"
+ android:src="@drawable/notification_next"
+ android:background="@android:color/transparent"
+ android:layout_width="40dip"
+ android:layout_height="40dip"
+ android:layout_gravity="center|right"
+ android:layout_marginRight="5dip"
+ android:layout_marginTop="2dip"
+ android:layout_weight="0.0"/>
+
+ </LinearLayout>
+
+</LinearLayout>
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() {