summaryrefslogtreecommitdiffstats
path: root/android
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2010-08-04 14:34:26 +0000
committerThomas Martitz <kugel@rockbox.org>2010-08-04 14:34:26 +0000
commit546cd485040e215797fc39508159fa9526b07a27 (patch)
tree88de742451faf833f5148bb9c55a4a6ae0998718 /android
parent04dc00b7caa9f505ed3dd55fe5922910d004fa80 (diff)
downloadrockbox-546cd485040e215797fc39508159fa9526b07a27.tar.gz
rockbox-546cd485040e215797fc39508159fa9526b07a27.tar.bz2
rockbox-546cd485040e215797fc39508159fa9526b07a27.zip
Show/hide notification area icon when starting/stopping playback.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@27694 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'android')
-rw-r--r--android/src/org/rockbox/RockboxPCM.java12
-rw-r--r--android/src/org/rockbox/RockboxService.java47
2 files changed, 43 insertions, 16 deletions
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);
+ }
}
}