diff options
Diffstat (limited to 'apps/hosted')
-rw-r--r-- | apps/hosted/notification.c | 96 | ||||
-rw-r--r-- | apps/hosted/notification.h | 27 |
2 files changed, 123 insertions, 0 deletions
diff --git a/apps/hosted/notification.c b/apps/hosted/notification.c new file mode 100644 index 0000000000..13c88eca4b --- /dev/null +++ b/apps/hosted/notification.c | |||
@@ -0,0 +1,96 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Thomas Martitz | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #include <jni.h> | ||
23 | #include <stdio.h> | ||
24 | #include "notification.h" | ||
25 | #include "appevents.h" | ||
26 | #include "metadata.h" | ||
27 | #include "misc.h" | ||
28 | |||
29 | extern JNIEnv *env_ptr; | ||
30 | extern jclass RockboxService_class; | ||
31 | extern jobject RockboxService_instance; | ||
32 | |||
33 | static jmethodID updateNotification; | ||
34 | static jobject NotificationManager_instance; | ||
35 | static jstring headline, content, ticker; | ||
36 | |||
37 | #define NZV(a) (a && a[0]) | ||
38 | |||
39 | /* | ||
40 | * notify about track change, and show track info */ | ||
41 | static void track_changed_callback(void *param) | ||
42 | { | ||
43 | struct mp3entry* id3 = (struct mp3entry*)param; | ||
44 | JNIEnv e = *env_ptr; | ||
45 | if (id3) | ||
46 | { | ||
47 | /* passing NULL to DeleteLocalRef() is OK */ | ||
48 | e->DeleteLocalRef(env_ptr, headline); | ||
49 | e->DeleteLocalRef(env_ptr, content); | ||
50 | e->DeleteLocalRef(env_ptr, ticker); | ||
51 | |||
52 | char buf[200]; | ||
53 | const char * title = id3->title; | ||
54 | if (!title) | ||
55 | { /* pass the filename as title if id3 info isn't available */ | ||
56 | title = | ||
57 | strip_extension(buf, sizeof(buf), strrchr(id3->path,'/') + 1); | ||
58 | } | ||
59 | |||
60 | /* do text for the notification area in the scrolled-down statusbar */ | ||
61 | headline = e->NewStringUTF(env_ptr, title); | ||
62 | |||
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, | ||
78 | updateNotification, headline, content, ticker); | ||
79 | } | ||
80 | } | ||
81 | |||
82 | void notification_init(void) | ||
83 | { | ||
84 | JNIEnv e = *env_ptr; | ||
85 | jfieldID nNM = e->GetFieldID(env_ptr, RockboxService_class, | ||
86 | "fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;"); | ||
87 | NotificationManager_instance = e->GetObjectField(env_ptr, | ||
88 | RockboxService_instance, nNM); | ||
89 | |||
90 | jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance); | ||
91 | updateNotification = e->GetMethodID(env_ptr, class, "updateNotification", | ||
92 | "(Ljava/lang/String;" | ||
93 | "Ljava/lang/String;" | ||
94 | "Ljava/lang/String;)V"); | ||
95 | add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback); | ||
96 | } | ||
diff --git a/apps/hosted/notification.h b/apps/hosted/notification.h new file mode 100644 index 0000000000..d182c7f8e7 --- /dev/null +++ b/apps/hosted/notification.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2010 Thomas Martitz | ||
11 | * | ||
12 | * This program is free software; you can redistribute it and/or | ||
13 | * modify it under the terms of the GNU General Public License | ||
14 | * as published by the Free Software Foundation; either version 2 | ||
15 | * of the License, or (at your option) any later version. | ||
16 | * | ||
17 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
18 | * KIND, either express or implied. | ||
19 | * | ||
20 | ****************************************************************************/ | ||
21 | |||
22 | #ifndef __NOTIFICATION_H__ | ||
23 | #define __NOTIFICATION_H__ | ||
24 | |||
25 | void notification_init(void); | ||
26 | |||
27 | #endif | ||