summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xandroid/installApk.sh2
-rw-r--r--android/res/drawable-hdpi/notification.pngbin0 -> 1013 bytes
-rw-r--r--android/res/drawable-hdpi/notification_small.pngbin0 -> 1011 bytes
-rw-r--r--android/res/drawable-ldpi/notification.pngbin0 -> 549 bytes
-rw-r--r--android/res/drawable-ldpi/notification_small.pngbin0 -> 533 bytes
-rw-r--r--android/res/drawable-mdpi/launcher.pngbin1855 -> 886 bytes
-rw-r--r--android/res/drawable-mdpi/notification.pngbin0 -> 675 bytes
-rw-r--r--android/res/drawable-mdpi/notification_small.pngbin0 -> 628 bytes
-rw-r--r--android/res/layout/statusbar.xml53
-rw-r--r--android/src/org/rockbox/Helper/RunForegroundManager.java41
-rw-r--r--android/src/org/rockbox/RockboxService.java11
-rw-r--r--apps/SOURCES1
-rw-r--r--apps/apps.make3
-rw-r--r--apps/gui/wps.c2
-rw-r--r--apps/hosted/notification.c96
-rw-r--r--apps/hosted/notification.h27
-rw-r--r--apps/main.c10
17 files changed, 222 insertions, 24 deletions
diff --git a/android/installApk.sh b/android/installApk.sh
index 2cb98a1c01..2c82b115c6 100755
--- a/android/installApk.sh
+++ b/android/installApk.sh
@@ -2,4 +2,4 @@
ADB="$ANDROID_SDK_PATH/tools/adb"
$ADB install -r rockbox.apk
-echo 'am start -W -a android.intent.action.MAIN -n org.rockbox/.RockboxActivity; exit' | $ADB shell
+echo 'am start -a android.intent.action.MAIN -n org.rockbox/.RockboxActivity; exit' | $ADB shell
diff --git a/android/res/drawable-hdpi/notification.png b/android/res/drawable-hdpi/notification.png
new file mode 100644
index 0000000000..a6e212d431
--- /dev/null
+++ b/android/res/drawable-hdpi/notification.png
Binary files differ
diff --git a/android/res/drawable-hdpi/notification_small.png b/android/res/drawable-hdpi/notification_small.png
new file mode 100644
index 0000000000..e8b27ee965
--- /dev/null
+++ b/android/res/drawable-hdpi/notification_small.png
Binary files differ
diff --git a/android/res/drawable-ldpi/notification.png b/android/res/drawable-ldpi/notification.png
new file mode 100644
index 0000000000..432f33f77d
--- /dev/null
+++ b/android/res/drawable-ldpi/notification.png
Binary files differ
diff --git a/android/res/drawable-ldpi/notification_small.png b/android/res/drawable-ldpi/notification_small.png
new file mode 100644
index 0000000000..0b36529e56
--- /dev/null
+++ b/android/res/drawable-ldpi/notification_small.png
Binary files differ
diff --git a/android/res/drawable-mdpi/launcher.png b/android/res/drawable-mdpi/launcher.png
index 8999c4e543..089ebaec76 100644
--- a/android/res/drawable-mdpi/launcher.png
+++ b/android/res/drawable-mdpi/launcher.png
Binary files differ
diff --git a/android/res/drawable-mdpi/notification.png b/android/res/drawable-mdpi/notification.png
new file mode 100644
index 0000000000..c37989366a
--- /dev/null
+++ b/android/res/drawable-mdpi/notification.png
Binary files differ
diff --git a/android/res/drawable-mdpi/notification_small.png b/android/res/drawable-mdpi/notification_small.png
new file mode 100644
index 0000000000..8a1f9faaad
--- /dev/null
+++ b/android/res/drawable-mdpi/notification_small.png
Binary files differ
diff --git a/android/res/layout/statusbar.xml b/android/res/layout/statusbar.xml
new file mode 100644
index 0000000000..c795008225
--- /dev/null
+++ b/android/res/layout/statusbar.xml
@@ -0,0 +1,53 @@
+<?xml version="1.0" encoding="ISO-8859-1"?>
+<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
+ android:layout_width="fill_parent"
+ android:layout_height="fill_parent"
+ android:paddingLeft="6dp"
+ android:paddingRight="6dp"
+ android:paddingTop="0dp"
+ android:paddingBottom="0dp"
+ android:orientation="horizontal">
+
+ <LinearLayout android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="vertical">
+ <LinearLayout android:layout_width="match_parent"
+ android:layout_height="wrap_content"
+ android:orientation="horizontal">
+
+ <ImageView android:src="@drawable/notification_small"
+ android:gravity="center"
+ android:paddingTop="2dp"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content">
+ </ImageView>
+
+ <TextView android:id="@+id/title"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:focusable="true"
+ android:ellipsize="end"
+ android:textStyle="bold"
+ android:singleLine="true"
+ android:textAppearance="?android:attr/textAppearanceMediumInverse"
+ android:gravity="center"
+ android:paddingTop="0dp"
+ android:paddingLeft="6dp" />
+ </LinearLayout>
+
+ <LinearLayout android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:paddingLeft="3dp"
+ android:orientation="vertical">
+ <TextView android:id="@+id/content"
+ android:layout_gravity="left"
+ android:scrollHorizontally="true"
+ android:maxLines="2"
+ android:ellipsize="end"
+ android:layout_width="wrap_content"
+ android:layout_height="wrap_content"
+ android:textAppearance="?android:attr/textAppearanceSmallInverse"
+ />
+ </LinearLayout>
+ </LinearLayout>
+</LinearLayout>
diff --git a/android/src/org/rockbox/Helper/RunForegroundManager.java b/android/src/org/rockbox/Helper/RunForegroundManager.java
index eb6e4c96ef..513089ff9f 100644
--- a/android/src/org/rockbox/Helper/RunForegroundManager.java
+++ b/android/src/org/rockbox/Helper/RunForegroundManager.java
@@ -12,6 +12,7 @@ import android.app.PendingIntent;
import android.app.Service;
import android.content.Intent;
import android.util.Log;
+import android.widget.RemoteViews;
public class RunForegroundManager
{
@@ -25,34 +26,32 @@ public class RunForegroundManager
public RunForegroundManager(Service service) throws Exception
{
+ mCurrentService = service;
mNM = (NotificationManager)
service.getSystemService(Service.NOTIFICATION_SERVICE);
- /* For now we'll use the same text for the ticker and the
- * expanded notification */
- CharSequence text = service.getText(R.string.notification);
- /* Set the icon, scrolling text and timestamp */
- mNotification = new Notification(R.drawable.icon, text,
- System.currentTimeMillis());
-
- /* The PendingIntent to launch our activity if the user selects
- * this notification */
+ RemoteViews views = new RemoteViews(service.getPackageName(), R.layout.statusbar);
+ /* create Intent for clicking on the expanded notifcation area */
Intent intent = new Intent(service, RockboxActivity.class);
- PendingIntent contentIntent =
- PendingIntent.getActivity(service, 0, intent, 0);
+ intent = intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
+
+ mNotification = new Notification();
+ mNotification.tickerText = service.getString(R.string.notification);
+ mNotification.icon = R.drawable.notification;
+ mNotification.contentView = views;
+ mNotification.flags |= Notification.FLAG_ONGOING_EVENT;
+ mNotification.contentIntent = PendingIntent.getActivity(service, 0, intent, 0);
- /* Set the info for the views that show in the notification panel. */
- mNotification.setLatestEventInfo(service,
- service.getText(R.string.notification), text, contentIntent);
-
try {
api = new newForegroundApi(R.string.notification, mNotification);
} catch (NoSuchMethodException e) {
/* Fall back on the old API */
api = new oldForegroundApi();
}
- mCurrentService = service;
}
-
+ private void LOG(CharSequence text)
+ {
+ Log.d("Rockbox", (String)text);
+ }
private void LOG(CharSequence text, Throwable tr)
{
Log.d("Rockbox", (String)text, tr);
@@ -83,6 +82,14 @@ public class RunForegroundManager
api.stopForeground();
}
+ public void updateNotification(String title, String content, String ticker)
+ {
+ RemoteViews views = mNotification.contentView;
+ views.setTextViewText(R.id.title, title);
+ views.setTextViewText(R.id.content, content);
+ mNotification.tickerText = ticker;
+ mNM.notify(R.string.notification, mNotification);
+ }
private interface IRunForeground
{
diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 033ece320c..23086eae29 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -117,10 +117,13 @@ public class RockboxService extends Service
/* Display a notification about us starting.
* We put an icon in the status bar. */
- try {
- fg_runner = new RunForegroundManager(this);
- } catch (Exception e) {
- e.printStackTrace();
+ if (fg_runner == null)
+ {
+ try {
+ fg_runner = new RunForegroundManager(this);
+ } catch (Exception e) {
+ e.printStackTrace();
+ }
}
}
diff --git a/apps/SOURCES b/apps/SOURCES
index 8aa469fa4d..4755ad42c3 100644
--- a/apps/SOURCES
+++ b/apps/SOURCES
@@ -91,6 +91,7 @@ gui/statusbar-skinned.c
#endif
#if (CONFIG_PLATFORM&PLATFORM_ANDROID)
hosted/yesno.c
+hosted/notification.c
#else
gui/yesno.c
#endif
diff --git a/apps/apps.make b/apps/apps.make
index 6afcd12b5c..a430288870 100644
--- a/apps/apps.make
+++ b/apps/apps.make
@@ -8,6 +8,9 @@
#
INCLUDES += -I$(APPSDIR) $(patsubst %,-I$(APPSDIR)/%,$(subst :, ,$(APPEXTRA)))
+ifdef APP_TYPE
+ INCLUDES += -I$(APPSDIR)/hosted
+endif
SRC += $(call preprocess, $(APPSDIR)/SOURCES)
# apps/features.txt is a file that (is preprocessed and) lists named features
diff --git a/apps/gui/wps.c b/apps/gui/wps.c
index 7d633ad4e8..717a58aa8e 100644
--- a/apps/gui/wps.c
+++ b/apps/gui/wps.c
@@ -1189,6 +1189,8 @@ static void wps_state_init(void)
/* add the WPS track event callbacks */
add_event(PLAYBACK_EVENT_TRACK_CHANGE, false, track_changed_callback);
add_event(PLAYBACK_EVENT_NEXTTRACKID3_AVAILABLE, false, nextid3available_callback);
+ extern void notification_init(void);
+ notification_init();
}
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
diff --git a/apps/main.c b/apps/main.c
index 7af4cca37e..dd1f60a849 100644
--- a/apps/main.c
+++ b/apps/main.c
@@ -76,6 +76,9 @@
#include "skin_engine/skin_engine.h"
#include "statusbar-skinned.h"
#include "bootchart.h"
+#if defined(APPLICATION) && (CONFIG_PLATFORM & PLATFORM_ANDROID)
+#include "notification.h"
+#endif
#ifdef IPOD_ACCESSORY_PROTOCOL
#include "iap.h"
@@ -333,11 +336,11 @@ static void init_tagcache(void)
static void init(void)
{
+ system_init();
+ kernel_init();
#ifdef APPLICATION
paths_init();
#endif
- system_init();
- kernel_init();
buffer_init();
enable_irq();
lcd_init();
@@ -351,6 +354,9 @@ static void init(void)
#if (CONFIG_PLATFORM & PLATFORM_SDL)
sim_tasks_init();
#endif
+#if (CONFIG_PLATFORM & PLATFORM_ANDROID)
+ notification_init();
+#endif
lang_init(core_language_builtin, language_strings,
LANG_LAST_INDEX_IN_ARRAY);
#ifdef DEBUG