1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
diff --git a/android/src/org/rockbox/RockboxFramebuffer.java b/android/src/org/rockbox/RockboxFramebuffer.java
index 037fd2d..7a61c30 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 37d540c..4950404 100644
--- a/android/src/org/rockbox/RockboxService.java
+++ b/android/src/org/rockbox/RockboxService.java
@@ -110,28 +110,16 @@ public class RockboxService extends Service
         if (!rockbox_running)
             startservice();

-        if (intent != null && intent.getAction() != null)
+        if (intent != null && fb != null)
         {
-            Log.d("RockboxService", intent.getAction());
-            if (intent.getAction().equals("org.rockbox.PlayPause"))
+            String act = intent.getAction(); 
+            Log.d("RockboxService", act != null ? act : "MAIN");
+            if (act != null && act.equalsIgnoreCase(Intent.ACTION_MEDIA_BUTTON))
             {
-                if (fb != null)
-                    fb.onKeyUp(KeyEvent.KEYCODE_MEDIA_PLAY_PAUSE, null);
-            }
-            else if (intent.getAction().equals("org.rockbox.Prev"))
-            {
-                if (fb != null)
-                    fb.onKeyUp(KeyEvent.KEYCODE_MEDIA_PREVIOUS, null);
-            }
-            else if (intent.getAction().equals("org.rockbox.Next"))
-            {
-                if (fb != null)
-                    fb.onKeyUp(KeyEvent.KEYCODE_MEDIA_NEXT, null);
-            }
-            else if (intent.getAction().equals("org.rockbox.Stop"))
-            {
-                if (fb != null)
-                    fb.onKeyUp(KeyEvent.KEYCODE_MEDIA_STOP, null);
+                LOG("foo");
+                KeyEvent ev = intent.getParcelableExtra(Intent.EXTRA_KEY_EVENT);
+                LOG("play pressed" + ev.getKeyCode());
+                fb.onKeyUp(ev.getKeyCode(), ev);
             }
         }

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..8ad19ac 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);
@@ -104,38 +117,38 @@ public class RockboxWidgetProvider extends AppWidgetProvider

         RockboxWidgetConfigure.WidgetPref state = RockboxWidgetConfigure.loadWidgetPref(context, appWidgetId);

-        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);
-        }
-        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);
-        }
-        else
-            views.setViewVisibility(R.id.playPause, View.GONE);
-
+//        if (state.enablePrev)
+//        {
+//            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)
+//        {
+//            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,25 @@ public class RockboxWidgetProvider extends AppWidgetProvider
         }

         appWidgetManager.updateAppWidget(appWidgetId, views);
-     }
+    }
+     
+    private static 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;
+            this.keycode = keycode;
+        }
+        
+        public PendingIntent getPendingIntent()
+        {
+            putExtra(EXTRA_KEY_EVENT, new KeyEvent(KeyEvent.ACTION_UP,
+                    keycode));
+            return PendingIntent.getService(mContext, 0, this, 0);
+        }
+    }
 }