setup the button click listeners
This commit is contained in:
parent
a4e491e59a
commit
d1a3bcb84b
3 changed files with 67 additions and 8 deletions
|
@ -24,7 +24,7 @@
|
|||
|
||||
<service android:name="musicplayer.simplemobiletools.com.MusicService"/>
|
||||
|
||||
<receiver android:name=".MyAppWidgetProvider">
|
||||
<receiver android:name=".MyWidgetProvider">
|
||||
<intent-filter>
|
||||
<action android:name="android.appwidget.action.APPWIDGET_UPDATE"/>
|
||||
</intent-filter>
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package musicplayer.simplemobiletools.com;
|
||||
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
|
||||
public class MyAppWidgetProvider extends AppWidgetProvider {
|
||||
|
||||
}
|
|
@ -0,0 +1,66 @@
|
|||
package musicplayer.simplemobiletools.com;
|
||||
|
||||
import android.app.PendingIntent;
|
||||
import android.appwidget.AppWidgetManager;
|
||||
import android.appwidget.AppWidgetProvider;
|
||||
import android.content.ComponentName;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
public class MyWidgetProvider extends AppWidgetProvider {
|
||||
private static final String PREVIOUS = "previous";
|
||||
private static final String PLAYPAUSE = "playpause";
|
||||
private static final String NEXT = "next";
|
||||
private static final String STOP = "stop";
|
||||
|
||||
private int[] widgetIds;
|
||||
private static RemoteViews remoteViews;
|
||||
private static AppWidgetManager widgetManager;
|
||||
private static Context cxt;
|
||||
private static Intent intent;
|
||||
|
||||
@Override
|
||||
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
|
||||
initVariables(context);
|
||||
cxt = context;
|
||||
|
||||
intent = new Intent(context, MyWidgetProvider.class);
|
||||
setupIntent(PREVIOUS, R.id.previousBtn);
|
||||
setupIntent(PLAYPAUSE, R.id.playPauseBtn);
|
||||
setupIntent(NEXT, R.id.nextBtn);
|
||||
setupIntent(STOP, R.id.stopBtn);
|
||||
|
||||
appWidgetManager.updateAppWidget(appWidgetIds, remoteViews);
|
||||
}
|
||||
|
||||
private void setupIntent(String action, int id) {
|
||||
intent.setAction(action);
|
||||
PendingIntent pendingIntent = PendingIntent.getBroadcast(cxt, 0, intent, 0);
|
||||
remoteViews.setOnClickPendingIntent(id, pendingIntent);
|
||||
}
|
||||
|
||||
private void initVariables(Context context) {
|
||||
final ComponentName component = new ComponentName(context, MyWidgetProvider.class);
|
||||
remoteViews = new RemoteViews(context.getPackageName(), R.layout.widget);
|
||||
widgetManager = AppWidgetManager.getInstance(context);
|
||||
widgetIds = widgetManager.getAppWidgetIds(component);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onReceive(Context context, Intent intent) {
|
||||
final String action = intent.getAction();
|
||||
switch (action) {
|
||||
case PREVIOUS:
|
||||
break;
|
||||
case PLAYPAUSE:
|
||||
break;
|
||||
case NEXT:
|
||||
break;
|
||||
case STOP:
|
||||
break;
|
||||
default:
|
||||
super.onReceive(context, intent);
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue