diff options
-rw-r--r-- | android/src/org/rockbox/Helper/RunForegroundManager.java | 10 | ||||
-rw-r--r-- | apps/hosted/notification.c | 36 |
2 files changed, 19 insertions, 27 deletions
diff --git a/android/src/org/rockbox/Helper/RunForegroundManager.java b/android/src/org/rockbox/Helper/RunForegroundManager.java index 513089ff9f..197c51a567 100644 --- a/android/src/org/rockbox/Helper/RunForegroundManager.java +++ b/android/src/org/rockbox/Helper/RunForegroundManager.java | |||
@@ -5,6 +5,7 @@ import java.lang.reflect.Method; | |||
5 | 5 | ||
6 | import org.rockbox.R; | 6 | import org.rockbox.R; |
7 | import org.rockbox.RockboxActivity; | 7 | import org.rockbox.RockboxActivity; |
8 | import org.rockbox.RockboxWidgetProvider; | ||
8 | 9 | ||
9 | import android.app.Notification; | 10 | import android.app.Notification; |
10 | import android.app.NotificationManager; | 11 | import android.app.NotificationManager; |
@@ -82,12 +83,15 @@ public class RunForegroundManager | |||
82 | api.stopForeground(); | 83 | api.stopForeground(); |
83 | } | 84 | } |
84 | 85 | ||
85 | public void updateNotification(String title, String content, String ticker) | 86 | public void updateNotification(String title, String artist, String album) |
86 | { | 87 | { |
87 | RemoteViews views = mNotification.contentView; | 88 | RemoteViews views = mNotification.contentView; |
88 | views.setTextViewText(R.id.title, title); | 89 | views.setTextViewText(R.id.title, title); |
89 | views.setTextViewText(R.id.content, content); | 90 | views.setTextViewText(R.id.content, artist+"\n"+album); |
90 | mNotification.tickerText = ticker; | 91 | if (artist.equals("")) |
92 | mNotification.tickerText = title; | ||
93 | else | ||
94 | mNotification.tickerText = title+" - "+artist; | ||
91 | mNM.notify(R.string.notification, mNotification); | 95 | mNM.notify(R.string.notification, mNotification); |
92 | } | 96 | } |
93 | 97 | ||
diff --git a/apps/hosted/notification.c b/apps/hosted/notification.c index 13c88eca4b..3c623aad1d 100644 --- a/apps/hosted/notification.c +++ b/apps/hosted/notification.c | |||
@@ -32,7 +32,7 @@ extern jobject RockboxService_instance; | |||
32 | 32 | ||
33 | static jmethodID updateNotification; | 33 | static jmethodID updateNotification; |
34 | static jobject NotificationManager_instance; | 34 | static jobject NotificationManager_instance; |
35 | static jstring headline, content, ticker; | 35 | static jstring title, artist, album; |
36 | 36 | ||
37 | #define NZV(a) (a && a[0]) | 37 | #define NZV(a) (a && a[0]) |
38 | 38 | ||
@@ -45,37 +45,24 @@ static void track_changed_callback(void *param) | |||
45 | if (id3) | 45 | if (id3) |
46 | { | 46 | { |
47 | /* passing NULL to DeleteLocalRef() is OK */ | 47 | /* passing NULL to DeleteLocalRef() is OK */ |
48 | e->DeleteLocalRef(env_ptr, headline); | 48 | e->DeleteLocalRef(env_ptr, title); |
49 | e->DeleteLocalRef(env_ptr, content); | 49 | e->DeleteLocalRef(env_ptr, artist); |
50 | e->DeleteLocalRef(env_ptr, ticker); | 50 | e->DeleteLocalRef(env_ptr, album); |
51 | 51 | ||
52 | char buf[200]; | 52 | char buf[200]; |
53 | const char * title = id3->title; | 53 | const char * ptitle = id3->title; |
54 | if (!title) | 54 | if (!ptitle) |
55 | { /* pass the filename as title if id3 info isn't available */ | 55 | { /* pass the filename as title if id3 info isn't available */ |
56 | title = | 56 | ptitle = |
57 | strip_extension(buf, sizeof(buf), strrchr(id3->path,'/') + 1); | 57 | strip_extension(buf, sizeof(buf), strrchr(id3->path,'/') + 1); |
58 | } | 58 | } |
59 | 59 | ||
60 | /* do text for the notification area in the scrolled-down statusbar */ | 60 | title = e->NewStringUTF(env_ptr, ptitle); |
61 | headline = e->NewStringUTF(env_ptr, title); | 61 | artist = e->NewStringUTF(env_ptr, id3->artist ?: ""); |
62 | album = e->NewStringUTF(env_ptr, id3->album ?: ""); | ||
62 | 63 | ||
63 | /* add a \n so that android does split into two lines */ | ||
64 | snprintf(buf, sizeof(buf), "%s\n%s", id3->artist ?: "", id3->album ?: ""); | ||
65 | content = e->NewStringUTF(env_ptr, buf); | ||
66 | |||
67 | /* now do the text for the notification in the statusbar itself */ | ||
68 | if (NZV(id3->artist)) | ||
69 | { /* title - artist */ | ||
70 | snprintf(buf, sizeof(buf), "%s - %s", title, id3->artist); | ||
71 | ticker = e->NewStringUTF(env_ptr, buf); | ||
72 | } | ||
73 | else | ||
74 | { /* title */ | ||
75 | ticker = e->NewStringUTF(env_ptr, title); | ||
76 | } | ||
77 | e->CallVoidMethod(env_ptr, NotificationManager_instance, | 64 | e->CallVoidMethod(env_ptr, NotificationManager_instance, |
78 | updateNotification, headline, content, ticker); | 65 | updateNotification, title, artist, album); |
79 | } | 66 | } |
80 | } | 67 | } |
81 | 68 | ||
@@ -92,5 +79,6 @@ void notification_init(void) | |||
92 | "(Ljava/lang/String;" | 79 | "(Ljava/lang/String;" |
93 | "Ljava/lang/String;" | 80 | "Ljava/lang/String;" |
94 | "Ljava/lang/String;)V"); | 81 | "Ljava/lang/String;)V"); |
82 | |||
95 | add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback); | 83 | add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback); |
96 | } | 84 | } |