From f5a461d1820f08c2001256f514a6b92eb78545f6 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Fri, 10 Dec 2010 18:41:09 +0000 Subject: 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 --- android/installApk.sh | 2 +- android/res/drawable-hdpi/notification.png | Bin 0 -> 1013 bytes android/res/drawable-hdpi/notification_small.png | Bin 0 -> 1011 bytes android/res/drawable-ldpi/notification.png | Bin 0 -> 549 bytes android/res/drawable-ldpi/notification_small.png | Bin 0 -> 533 bytes android/res/drawable-mdpi/launcher.png | Bin 1855 -> 886 bytes android/res/drawable-mdpi/notification.png | Bin 0 -> 675 bytes android/res/drawable-mdpi/notification_small.png | Bin 0 -> 628 bytes android/res/layout/statusbar.xml | 53 +++++++++++++++++++++ .../org/rockbox/Helper/RunForegroundManager.java | 41 +++++++++------- android/src/org/rockbox/RockboxService.java | 11 +++-- 11 files changed, 85 insertions(+), 22 deletions(-) create mode 100644 android/res/drawable-hdpi/notification.png create mode 100644 android/res/drawable-hdpi/notification_small.png create mode 100644 android/res/drawable-ldpi/notification.png create mode 100644 android/res/drawable-ldpi/notification_small.png create mode 100644 android/res/drawable-mdpi/notification.png create mode 100644 android/res/drawable-mdpi/notification_small.png create mode 100644 android/res/layout/statusbar.xml (limited to 'android') diff --git a/android/installApk.sh b/android/installApk.sh index 2cb98a1..2c82b11 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 0000000..a6e212d Binary files /dev/null and b/android/res/drawable-hdpi/notification.png differ diff --git a/android/res/drawable-hdpi/notification_small.png b/android/res/drawable-hdpi/notification_small.png new file mode 100644 index 0000000..e8b27ee Binary files /dev/null and b/android/res/drawable-hdpi/notification_small.png differ diff --git a/android/res/drawable-ldpi/notification.png b/android/res/drawable-ldpi/notification.png new file mode 100644 index 0000000..432f33f Binary files /dev/null and b/android/res/drawable-ldpi/notification.png differ diff --git a/android/res/drawable-ldpi/notification_small.png b/android/res/drawable-ldpi/notification_small.png new file mode 100644 index 0000000..0b36529 Binary files /dev/null and b/android/res/drawable-ldpi/notification_small.png differ diff --git a/android/res/drawable-mdpi/launcher.png b/android/res/drawable-mdpi/launcher.png index 8999c4e..089ebae 100644 Binary files a/android/res/drawable-mdpi/launcher.png and b/android/res/drawable-mdpi/launcher.png differ diff --git a/android/res/drawable-mdpi/notification.png b/android/res/drawable-mdpi/notification.png new file mode 100644 index 0000000..c379893 Binary files /dev/null and b/android/res/drawable-mdpi/notification.png differ diff --git a/android/res/drawable-mdpi/notification_small.png b/android/res/drawable-mdpi/notification_small.png new file mode 100644 index 0000000..8a1f9fa Binary files /dev/null and b/android/res/drawable-mdpi/notification_small.png differ diff --git a/android/res/layout/statusbar.xml b/android/res/layout/statusbar.xml new file mode 100644 index 0000000..c795008 --- /dev/null +++ b/android/res/layout/statusbar.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + + + + + + diff --git a/android/src/org/rockbox/Helper/RunForegroundManager.java b/android/src/org/rockbox/Helper/RunForegroundManager.java index eb6e4c9..513089f 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 033ece3..23086ea 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(); + } } } -- cgit v1.1