1
0
Fork 0
forked from len0rd/rockbox

Android: Simplify media button intent generation in the widget and cleanup RockboxService accordingly.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@29404 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Thomas Martitz 2011-02-26 19:54:03 +00:00
parent 75aa83526f
commit eb01664804
4 changed files with 69 additions and 52 deletions

View file

@ -105,8 +105,8 @@ public class RockboxService extends Service
private void do_start(Intent intent)
{
LOG("Start Service");
if (intent != null && intent.hasExtra("callback"))
LOG("Start RockboxService (Intent: " + intent.getAction() + ")");
if (intent.hasExtra("callback"))
resultReceiver = (ResultReceiver) intent.getParcelableExtra("callback");
if (!rockbox_running)
@ -114,32 +114,18 @@ public class RockboxService extends Service
if (resultReceiver != null)
resultReceiver.send(RESULT_LIB_LOADED, null);
if (intent != null && intent.getAction() != null)
{
if (!rockbox_running)
{ /* give it a bit of time so we can register button presses
* sleeping longer doesn't work here, apparently Android
* surpresses long sleeps during intent handling */
try {
Thread.sleep(50);
}
catch (InterruptedException e) { }
}
if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON))
{
/* give it a bit of time so we can register button presses
* sleeping longer doesn't work here, apparently Android
* surpresses long sleeps during intent handling */
try {
Thread.sleep(50);
} catch (InterruptedException e) { }
if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON))
{
KeyEvent kev = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
RockboxFramebuffer.buttonHandler(kev.getKeyCode(), kev.getAction() == KeyEvent.ACTION_DOWN);
}
else if (intent.getAction().equals("org.rockbox.PlayPause"))
RockboxFramebuffer.buttonHandler(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, false);
else if (intent.getAction().equals("org.rockbox.Prev"))
RockboxFramebuffer.buttonHandler(KeyEvent.KEYCODE_MEDIA_PREVIOUS, false);
else if (intent.getAction().equals("org.rockbox.Next"))
RockboxFramebuffer.buttonHandler(KeyEvent.KEYCODE_MEDIA_NEXT, false);
else if (intent.getAction().equals("org.rockbox.Stop"))
RockboxFramebuffer.buttonHandler(KeyEvent.KEYCODE_MEDIA_STOP, false);
KeyEvent kev = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
RockboxFramebuffer.buttonHandler(kev.getKeyCode(),
kev.getAction() == KeyEvent.ACTION_DOWN);
}
/* (Re-)attach the media button receiver, in case it has been lost */