From 95e24dd7a54256e8df56e347c0f43133087a1df2 Mon Sep 17 00:00:00 2001 From: Thomas Martitz Date: Wed, 23 Feb 2011 01:10:54 +0000 Subject: Android: * Re-create RockboxFramebuffer instance with every time there's a new Activity. * Also, allow Rockbox to be started via multimedia buttons, immediately starting playback if wanted. We don't need to keep the fb instance around when it backround, and it makes us less depending on it and the activity (less race conditions). And this is how you usually do it in Android apps. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29384 a1c6a512-1295-4272-9138-f99709370657 --- android/src/org/rockbox/Helper/MediaButtonReceiver.java | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) (limited to 'android/src/org/rockbox/Helper') diff --git a/android/src/org/rockbox/Helper/MediaButtonReceiver.java b/android/src/org/rockbox/Helper/MediaButtonReceiver.java index 3749cec32a..a57bdd4831 100644 --- a/android/src/org/rockbox/Helper/MediaButtonReceiver.java +++ b/android/src/org/rockbox/Helper/MediaButtonReceiver.java @@ -22,9 +22,8 @@ package org.rockbox.Helper; import java.lang.reflect.Method; - +import org.rockbox.RockboxFramebuffer; import org.rockbox.RockboxService; - import android.content.BroadcastReceiver; import android.content.ComponentName; import android.content.Context; @@ -73,7 +72,12 @@ public class MediaButtonReceiver /* helper class for the manifest */ public static class MediaReceiver extends BroadcastReceiver - { + { + private void startService(Context c, Intent baseIntent) + { + baseIntent.setClass(c, RockboxService.class); + c.startService(baseIntent); + } @Override public void onReceive(Context context, Intent intent) { @@ -81,8 +85,11 @@ public class MediaButtonReceiver { KeyEvent key = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT); if (key.getAction() == KeyEvent.ACTION_UP) - { /* pass the pressed key to Rockbox */ - if (RockboxService.get_instance().get_fb().dispatchKeyEvent(key)) + { /* pass the pressed key to Rockbox, starting it if needed */ + RockboxService s = RockboxService.get_instance(); + if (s == null || !s.isRockboxRunning()) + startService(context, intent); + else if (RockboxFramebuffer.buttonHandler(key.getKeyCode(), false)) abortBroadcast(); } } -- cgit