From 546cd485040e215797fc39508159fa9526b07a27 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Wed, 4 Aug 2010 14:34:26 +0000 Subject: Show/hide notification area icon when starting/stopping playback. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27694 a1c6a512-1295-4272-9138-f99709370657 --- android/src/org/rockbox/RockboxPCM.java | 12 ++++++-- android/src/org/rockbox/RockboxService.java | 47 +++++++++++++++++++++-------- 2 files changed, 43 insertions(+), 16 deletions(-) (limited to 'android') diff --git a/android/src/org/rockbox/RockboxPCM.java b/android/src/org/rockbox/RockboxPCM.java index f098df6991..f2568d8406 100644 --- a/android/src/org/rockbox/RockboxPCM.java +++ b/android/src/org/rockbox/RockboxPCM.java @@ -56,9 +56,7 @@ public class RockboxPCM extends AudioTrack LOG("setNotificationMarkerPosition Error"); setPlaybackPositionUpdateListener(new PCMListener(buf_len*2)); } - } - - + } int bytes2frames(int bytes) { /* 1 sample is 2 bytes, 2 samples are 1 frame */ @@ -83,11 +81,19 @@ public class RockboxPCM extends AudioTrack LOG("Writing silence"); /* fill with silence */ write(raw_data, 0, raw_data.length); + RockboxService.startForeground(); } play(); } LOG("play_pause() return"); } + + @Override + public void stop() throws IllegalStateException + { + super.stop(); + RockboxService.stopForeground(); + } @SuppressWarnings("unused") private void set_volume(int volume) diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java index 5c74d19ebf..216cd12e77 100644 --- a/android/src/org/rockbox/RockboxService.java +++ b/android/src/org/rockbox/RockboxService.java @@ -19,12 +19,16 @@ import android.util.Log; public class RockboxService extends Service { + /* this Service is really a singleton class */ public static RockboxFramebuffer fb = null; + private static RockboxService instance; + private Notification notification; @Override public void onCreate() { mNM = (NotificationManager)getSystemService(NOTIFICATION_SERVICE); startservice(); + instance = this; } private void do_start(Intent intent) @@ -47,7 +51,7 @@ public class RockboxService extends Service { do_start(intent); /* Display a notification about us starting. We put an icon in the status bar. */ - showNotification(); + create_notification(); return START_STICKY; } @@ -143,12 +147,14 @@ public class RockboxService extends Service /* heavily based on the example found on * http://developer.android.com/reference/android/app/Service.html */ - public void showNotification() { + + private void create_notification() + { // In this sample, we'll use the same text for the ticker and the expanded notification CharSequence text = getText(R.string.notification); // Set the icon, scrolling text and timestamp - Notification notification = new Notification(R.drawable.rb, text, + notification = new Notification(R.drawable.rb, text, System.currentTimeMillis()); // The PendingIntent to launch our activity if the user selects this notification @@ -158,16 +164,31 @@ public class RockboxService extends Service // Set the info for the views that show in the notification panel. notification.setLatestEventInfo(this, getText(R.string.notification), text, contentIntent); + } - // Send the notification. - // We use a layout id because it is a unique number. We use it later to cancel. - mNM.notify(R.string.notification, notification); - - /* - * this call makes the service run as foreground, which - * provides enough cpu time to do music decoding in the - * background - */ - startForeground(R.string.notification, notification); + public static void startForeground() + { + if (instance != null) + { + // Send the notification. + // We use a layout id because it is a unique number. We use it later to cancel. + instance.mNM.notify(R.string.notification, instance.notification); + + /* + * this call makes the service run as foreground, which + * provides enough cpu time to do music decoding in the + * background + */ + instance.startForeground(R.string.notification, instance.notification); + } + } + + public static void stopForeground() + { + if (instance.notification != null) + { + instance.stopForeground(true); + instance.mNM.cancel(R.string.notification); + } } } -- cgit v1.2.3