diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
index a17bc90..669c964 100644
--- a/android/src/org/rockbox/RockboxFramebuffer.java
+++ b/android/src/org/rockbox/RockboxFramebuffer.java
@@ -132,6 +132,7 @@ public class RockboxFramebuffer extends SurfaceView

public boolean onKeyUp(int keyCode, KeyEvent event)
{
+ LOG("play pressed " + event.getKeyCode());
return buttonHandler(keyCode, false);
}

diff --git a/android/src/org/rockbox/RockboxService.java b/android/src/org/rockbox/RockboxService.java
index 4f0caa7..ba35e73 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -129,17 +129,9 @@ public class RockboxService extends Service

if (intent.getAction().equals(Intent.ACTION_MEDIA_BUTTON))
{
- KeyEvent kev = (KeyEvent)intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
+ KeyEvent kev = 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);
}

/* (Re-)attach the media button receiver, in case it has been lost */
diff --git a/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java b/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java
index 82adb97..fdea9b4 100644
--- a/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java
+++ b/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java
@@ -81,7 +81,7 @@ public class RockboxWidgetConfigure extends Activity
saveWidgetPref(context, mAppWidgetId, state);

AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
- RockboxWidgetProvider.updateAppWidget(context, appWidgetManager, mAppWidgetId, null);
+ RockboxWidgetProvider.getInstance().updateAppWidget(context, appWidgetManager, mAppWidgetId, null);

Intent result = new Intent();
result.putExtra(AppWidgetManager.EXTRA_APPWIDGET_ID, mAppWidgetId);
diff --git a/android/src/org/rockbox/widgets/RockboxWidgetProvider.java b/android/src/org/rockbox/widgets/RockboxWidgetProvider.java
index 756d9f9..5b83c37 100644
--- a/android/src/org/rockbox/widgets/RockboxWidgetProvider.java
+++ b/android/src/org/rockbox/widgets/RockboxWidgetProvider.java
@@ -34,6 +34,7 @@ import android.content.Context;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.net.Uri;
+import android.os.SystemClock;
import android.util.Log;
import android.view.View;
import android.view.KeyEvent;
@@ -43,6 +44,12 @@ import java.util.ArrayList;

public class RockboxWidgetProvider extends AppWidgetProvider
{
+ static RockboxWidgetProvider mInstance;
+ public RockboxWidgetProvider()
+ {
+ super();
+ mInstance = this;
+ }
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds)
{
@@ -54,6 +61,11 @@ public class RockboxWidgetProvider extends AppWidgetProvider

}
}
+
+ public static RockboxWidgetProvider getInstance()
+ {
+ return mInstance;
+ }

@Override
public void onDeleted(Context context, int[] appWidgetIds)
@@ -92,10 +104,11 @@ public class RockboxWidgetProvider extends AppWidgetProvider
}
}

- public static void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Intent args)
+ public void updateAppWidget(Context context, AppWidgetManager appWidgetManager, int appWidgetId, Intent args)
{
AppWidgetProviderInfo provider = appWidgetManager.getAppWidgetInfo(appWidgetId);
RemoteViews views = null;
+ RockboxMediaIntent mintent;
views = new RemoteViews(context.getPackageName(), provider.initialLayout);

Intent intent = new Intent(context, RockboxActivity.class);
@@ -106,36 +119,36 @@ public class RockboxWidgetProvider extends AppWidgetProvider

if (state.enablePrev)
{
- intent = new Intent("org.rockbox.Prev", Uri.EMPTY, context, RockboxService.class);
- pendingIntent = PendingIntent.getService(context, 0, intent, 0);
- views.setOnClickPendingIntent(R.id.prev, pendingIntent);
+ mintent = new RockboxMediaIntent(context,
+ KeyEvent.KEYCODE_MEDIA_PREVIOUS);
+ views.setOnClickPendingIntent(R.id.prev, mintent.getPendingIntent());
}
else
views.setViewVisibility(R.id.prev, View.GONE);

if (state.enablePlayPause)
{
- intent = new Intent("org.rockbox.PlayPause", Uri.EMPTY, context, RockboxService.class);
- pendingIntent = PendingIntent.getService(context, 0, intent, 0);
- views.setOnClickPendingIntent(R.id.playPause, pendingIntent);
+ RockboxMediaIntent nintent = new RockboxMediaIntent(context,
+ KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE);
+ views.setOnClickPendingIntent(R.id.playPause, nintent.getPendingIntent());
}
else
views.setViewVisibility(R.id.playPause, View.GONE);

if (state.enableNext)
{
- intent = new Intent("org.rockbox.Next", Uri.EMPTY, context, RockboxService.class);
- pendingIntent = PendingIntent.getService(context, 0, intent, 0);
- views.setOnClickPendingIntent(R.id.next, pendingIntent);
+ mintent = new RockboxMediaIntent(context,
+ KeyEvent.KEYCODE_MEDIA_NEXT);
+ views.setOnClickPendingIntent(R.id.next, mintent.getPendingIntent());
}
else
views.setViewVisibility(R.id.next, View.GONE);

if (state.enableStop)
{
- intent = new Intent("org.rockbox.Stop", Uri.EMPTY, context, RockboxService.class);
- pendingIntent = PendingIntent.getService(context, 0, intent, 0);
- views.setOnClickPendingIntent(R.id.stop, pendingIntent);
+ mintent = new RockboxMediaIntent(context,
+ KeyEvent.KEYCODE_MEDIA_STOP);
+ views.setOnClickPendingIntent(R.id.stop, mintent.getPendingIntent());
}
else
views.setViewVisibility(R.id.stop, View.GONE);
@@ -166,6 +179,26 @@ public class RockboxWidgetProvider extends AppWidgetProvider
}

appWidgetManager.updateAppWidget(appWidgetId, views);
- }
+ }
+
+ private class RockboxMediaIntent extends Intent
+ {
+ Context mContext;
+ int keycode;
+ public RockboxMediaIntent(Context c, int keycode)
+ {
+ super(ACTION_MEDIA_BUTTON, Uri.EMPTY, c, RockboxService.class);
+ mContext = c;
+ putExtra(EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
+ keycode));
+ this.keycode = keycode;
+ }
+
+ public PendingIntent getPendingIntent()
+ {
+ // Use keycode as request to code to prevent successive PendingIntents from overwritting one another. This seems hackish but at least it works.
+ return PendingIntent.getService(mContext, keycode, this, 0);
+ }
+ }
}