summaryrefslogtreecommitdiff
path: root/android/src/org/rockbox/widgets
diff options
context:
space:
mode:
authorThomas Martitz <kugel@rockbox.org>2011-02-26 19:54:03 +0000
committerThomas Martitz <kugel@rockbox.org>2011-02-26 19:54:03 +0000
commiteb016648045abdb80ee4e98cde405eb0c62b724c (patch)
tree3b14be88d4201b1de382e5cb481745429b95455e /android/src/org/rockbox/widgets
parent75aa83526f4410eaddafc0c9188b9d885d05302f (diff)
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
Diffstat (limited to 'android/src/org/rockbox/widgets')
-rw-r--r--android/src/org/rockbox/widgets/RockboxWidgetConfigure.java3
-rw-r--r--android/src/org/rockbox/widgets/RockboxWidgetProvider.java77
2 files changed, 55 insertions, 25 deletions
diff --git a/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java b/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java
index 82adb97126..6ce2050780 100644
--- a/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java
+++ b/android/src/org/rockbox/widgets/RockboxWidgetConfigure.java
@@ -29,7 +29,6 @@ import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.os.Bundle;
-import android.util.Log;
import android.view.View;
import android.widget.CheckBox;
@@ -81,7 +80,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 756d9f9a13..867088f601 100644
--- a/android/src/org/rockbox/widgets/RockboxWidgetProvider.java
+++ b/android/src/org/rockbox/widgets/RockboxWidgetProvider.java
@@ -24,7 +24,6 @@ package org.rockbox.widgets;
import org.rockbox.R;
import org.rockbox.RockboxActivity;
import org.rockbox.RockboxService;
-
import android.app.PendingIntent;
import android.appwidget.AppWidgetManager;
import android.appwidget.AppWidgetProvider;
@@ -32,17 +31,19 @@ import android.appwidget.AppWidgetProviderInfo;
import android.content.ComponentName;
import android.content.Context;
import android.content.Intent;
-import android.content.pm.PackageManager;
import android.net.Uri;
-import android.util.Log;
-import android.view.View;
import android.view.KeyEvent;
+import android.view.View;
import android.widget.RemoteViews;
-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 +55,12 @@ public class RockboxWidgetProvider extends AppWidgetProvider
}
}
+
+ public static RockboxWidgetProvider getInstance()
+ {
+ /* no new instance here, instanced by android */
+ return mInstance;
+ }
@Override
public void onDeleted(Context context, int[] appWidgetIds)
@@ -74,9 +81,9 @@ public class RockboxWidgetProvider extends AppWidgetProvider
public void onReceive(Context context, Intent intent)
{
String action = intent.getAction();
- if (intent.getAction().equals("org.rockbox.TrackUpdateInfo") ||
- intent.getAction().equals("org.rockbox.TrackFinish") ||
- intent.getAction().equals("org.rockbox.UpdateState"))
+ if (action.equals("org.rockbox.TrackUpdateInfo") ||
+ action.equals("org.rockbox.TrackFinish") ||
+ action.equals("org.rockbox.UpdateState"))
{
AppWidgetManager gm = AppWidgetManager.getInstance(context);
int[] appWidgetIds = gm.getAppWidgetIds(new ComponentName(context, this.getClass()));
@@ -92,7 +99,7 @@ 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;
@@ -104,38 +111,42 @@ public class RockboxWidgetProvider extends AppWidgetProvider
RockboxWidgetConfigure.WidgetPref state = RockboxWidgetConfigure.loadWidgetPref(context, appWidgetId);
+ /* enable/disable PREV */
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);
+ views.setOnClickPendingIntent(R.id.prev,
+ RockboxMediaIntent.newPendingIntent(context,
+ KeyEvent.KEYCODE_MEDIA_PREVIOUS));
}
else
views.setViewVisibility(R.id.prev, View.GONE);
+ /* enable/disable PLAY/PAUSE */
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);
+ views.setOnClickPendingIntent(R.id.playPause,
+ RockboxMediaIntent.newPendingIntent(context,
+ KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE));
}
else
views.setViewVisibility(R.id.playPause, View.GONE);
+ /* enable/disable NEXT */
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);
+ views.setOnClickPendingIntent(R.id.next,
+ RockboxMediaIntent.newPendingIntent(context,
+ KeyEvent.KEYCODE_MEDIA_NEXT));
}
else
views.setViewVisibility(R.id.next, View.GONE);
+ /* enable/disable STOP */
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);
+ views.setOnClickPendingIntent(R.id.stop,
+ RockboxMediaIntent.newPendingIntent(context,
+ KeyEvent.KEYCODE_MEDIA_STOP));
}
else
views.setViewVisibility(R.id.stop, View.GONE);
@@ -166,6 +177,26 @@ public class RockboxWidgetProvider extends AppWidgetProvider
}
appWidgetManager.updateAppWidget(appWidgetId, views);
- }
+ }
+
+ private static class RockboxMediaIntent extends Intent
+ {
+ private RockboxMediaIntent(Context c, int keycode)
+ {
+ super(ACTION_MEDIA_BUTTON, Uri.EMPTY, c, RockboxService.class);
+ putExtra(EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
+ keycode));
+ }
+
+ public static PendingIntent newPendingIntent(Context c, int keycode)
+ {
+ /* Use keycode as request to code to prevent successive
+ * PendingIntents from overwritting one another.
+ * This seems hackish but at least it works.
+ * see: http://code.google.com/p/android/issues/detail?id=863
+ */
+ return PendingIntent.getService(c, keycode, new RockboxMediaIntent(c, keycode), 0);
+ }
+ }
}