New colors

This commit is contained in:
Karim Abou Zeid 2015-03-30 21:42:54 +02:00
commit 696299b960
32 changed files with 116 additions and 164 deletions

View file

@ -0,0 +1,82 @@
package com.kabouzeid.gramophone.appwidget;
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;
import com.kabouzeid.gramophone.R;
import com.kabouzeid.gramophone.service.MusicService;
import com.kabouzeid.gramophone.ui.activities.MusicControllerActivity;
/**
* Implementation of App Widget functionality.
*/
public class MusicPlayerWidget extends AppWidgetProvider {
private static MusicPlayerWidget instance;
public static synchronized MusicPlayerWidget getInstance() {
if (instance == null) {
instance = new MusicPlayerWidget();
}
return instance;
}
@Override
public void onUpdate(Context context, AppWidgetManager appWidgetManager, int[] appWidgetIds) {
RemoteViews views = new RemoteViews(context.getPackageName(), R.layout.music_player_widget);
appWidgetManager.updateAppWidget(appWidgetIds, views);
}
@Override
public void onEnabled(Context context) {
// Enter relevant functionality for when the first widget is created
}
@Override
public void onDisabled(Context context) {
// Enter relevant functionality for when the last widget is disabled
}
private void linkButtons(final Context context, final RemoteViews views) {
views.setOnClickPendingIntent(R.id.album_art, retrievePlaybackActions(context, 0));
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, retrievePlaybackActions(context, 1));
views.setOnClickPendingIntent(R.id.button_next, retrievePlaybackActions(context, 2));
views.setOnClickPendingIntent(R.id.button_prev, retrievePlaybackActions(context, 3));
}
private PendingIntent retrievePlaybackActions(final Context context, final int which) {
Intent action;
PendingIntent pendingIntent;
final ComponentName serviceName = new ComponentName(context, MusicService.class);
switch (which) {
case 0:
action = new Intent(context, MusicControllerActivity.class);
pendingIntent = PendingIntent.getActivity(context, 0, action, 0);
return pendingIntent;
case 1:
action = new Intent(MusicService.ACTION_TOGGLE_PLAYBACK);
action.setComponent(serviceName);
pendingIntent = PendingIntent.getService(context, 1, action, 0);
return pendingIntent;
case 2:
action = new Intent(MusicService.ACTION_SKIP);
action.setComponent(serviceName);
pendingIntent = PendingIntent.getService(context, 2, action, 0);
return pendingIntent;
case 3:
action = new Intent(MusicService.ACTION_REWIND);
action.setComponent(serviceName);
pendingIntent = PendingIntent.getService(context, 3, action, 0);
return pendingIntent;
}
return null;
}
}