diff options
author | Thomas Martitz <kugel@rockbox.org> | 2010-12-10 18:41:09 +0000 |
---|---|---|
committer | Thomas Martitz <kugel@rockbox.org> | 2010-12-10 18:41:09 +0000 |
commit | f5a461d1820f08c2001256f514a6b92eb78545f6 (patch) | |
tree | 5051cd45d29cc61858f6457e104d8b96bff58871 /apps/hosted | |
parent | c47d81345151166083ab10d6f5d11e56462056d5 (diff) |
Android: Rework notification and change icon sizes to better meet the systems' standard.
The notification now announces the new track on track change, and the the area in the scrolled down notification area shows track infos (title, artist, album).
Someone should check if it looks good on hdpi and ldpi screens as I can't verify it right now (emulator crashes).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@28785 a1c6a512-1295-4272-9138-f99709370657
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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#include <jni.h> +#include <stdio.h> +#include "notification.h" +#include "appevents.h" +#include "metadata.h" +#include "misc.h" + +extern JNIEnv *env_ptr; +extern jclass RockboxService_class; +extern jobject RockboxService_instance; + +static jmethodID updateNotification; +static jobject NotificationManager_instance; +static jstring headline, content, ticker; + +#define NZV(a) (a && a[0]) + +/* + * notify about track change, and show track info */ +static void track_changed_callback(void *param) +{ + struct mp3entry* id3 = (struct mp3entry*)param; + JNIEnv e = *env_ptr; + if (id3) + { + /* passing NULL to DeleteLocalRef() is OK */ + e->DeleteLocalRef(env_ptr, headline); + e->DeleteLocalRef(env_ptr, content); + e->DeleteLocalRef(env_ptr, ticker); + + char buf[200]; + const char * title = id3->title; + if (!title) + { /* pass the filename as title if id3 info isn't available */ + title = + strip_extension(buf, sizeof(buf), strrchr(id3->path,'/') + 1); + } + + /* do text for the notification area in the scrolled-down statusbar */ + headline = e->NewStringUTF(env_ptr, title); + + /* add a \n so that android does split into two lines */ + snprintf(buf, sizeof(buf), "%s\n%s", id3->artist ?: "", id3->album ?: ""); + content = e->NewStringUTF(env_ptr, buf); + + /* now do the text for the notification in the statusbar itself */ + if (NZV(id3->artist)) + { /* title - artist */ + snprintf(buf, sizeof(buf), "%s - %s", title, id3->artist); + ticker = e->NewStringUTF(env_ptr, buf); + } + else + { /* title */ + ticker = e->NewStringUTF(env_ptr, title); + } + e->CallVoidMethod(env_ptr, NotificationManager_instance, + updateNotification, headline, content, ticker); + } +} + +void notification_init(void) +{ + JNIEnv e = *env_ptr; + jfieldID nNM = e->GetFieldID(env_ptr, RockboxService_class, + "fg_runner", "Lorg/rockbox/Helper/RunForegroundManager;"); + NotificationManager_instance = e->GetObjectField(env_ptr, + RockboxService_instance, nNM); + + jclass class = e->GetObjectClass(env_ptr, NotificationManager_instance); + updateNotification = e->GetMethodID(env_ptr, class, "updateNotification", + "(Ljava/lang/String;" + "Ljava/lang/String;" + "Ljava/lang/String;)V"); + add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback); +} 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 @@ +/*************************************************************************** + * __________ __ ___. + * Open \______ \ ____ ____ | | _\_ |__ _______ ___ + * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / + * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < + * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ + * \/ \/ \/ \/ \/ + * $Id$ + * + * Copyright (C) 2010 Thomas Martitz + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * as published by the Free Software Foundation; either version 2 + * of the License, or (at your option) any later version. + * + * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY + * KIND, either express or implied. + * + ****************************************************************************/ + +#ifndef __NOTIFICATION_H__ +#define __NOTIFICATION_H__ + +void notification_init(void); + +#endif |