reduce code duplication between widget styles
This commit is contained in:
parent
abcb807518
commit
08034e0696
5 changed files with 44 additions and 88 deletions
|
|
@ -390,11 +390,11 @@ public final class PreferenceUtil {
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long getImageCacheSize() {
|
public final long getImageCacheSize() {
|
||||||
return Integer.parseInt(mPreferences.getString(IMAGE_CACHE_SIZE, "400000000"));
|
return Long.parseLong(mPreferences.getString(IMAGE_CACHE_SIZE, "400000000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public final long getMediaCacheSize() {
|
public final long getMediaCacheSize() {
|
||||||
return Integer.parseInt(mPreferences.getString(MEDIA_CACHE_SIZE, "400000000"));
|
return Long.parseLong(mPreferences.getString(MEDIA_CACHE_SIZE, "400000000"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<CategoryInfo> getCategories() {
|
public List<CategoryInfo> getCategories() {
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import com.dkanada.gramophone.util.ImageUtil;
|
||||||
import com.dkanada.gramophone.util.Util;
|
import com.dkanada.gramophone.util.Util;
|
||||||
|
|
||||||
public class AppWidgetAlbum extends BaseAppWidget {
|
public class AppWidgetAlbum extends BaseAppWidget {
|
||||||
public static final String NAME = "app_widget_album";
|
public static final String NAME = "widget.album";
|
||||||
|
|
||||||
private static AppWidgetAlbum mInstance;
|
private static AppWidgetAlbum mInstance;
|
||||||
private Target<Bitmap> target;
|
private Target<Bitmap> target;
|
||||||
|
|
@ -54,7 +54,7 @@ public class AppWidgetAlbum extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
|
protected void reset(final Context context, final int[] appWidgetIds) {
|
||||||
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_album);
|
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_album);
|
||||||
|
|
||||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
|
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
|
||||||
|
|
@ -63,12 +63,12 @@ public class AppWidgetAlbum extends BaseAppWidget {
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false))));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false))));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false))));
|
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getPrimaryTextColor(context, false))));
|
||||||
|
|
||||||
linkButtons(context, appWidgetView);
|
linkButtons(context, appWidgetView, R.id.clickable_area);
|
||||||
pushUpdate(context, appWidgetIds, appWidgetView);
|
pushUpdate(context, appWidgetIds, appWidgetView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
|
public void updateMeta(final MusicService service, final int[] appWidgetIds) {
|
||||||
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_album);
|
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_album);
|
||||||
|
|
||||||
final boolean isPlaying = service.isPlaying();
|
final boolean isPlaying = service.isPlaying();
|
||||||
|
|
@ -88,7 +88,7 @@ public class AppWidgetAlbum extends BaseAppWidget {
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false))));
|
appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false))));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false))));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getPrimaryTextColor(service, false))));
|
||||||
|
|
||||||
linkButtons(service, appWidgetView);
|
linkButtons(service, appWidgetView, R.id.clickable_area);
|
||||||
|
|
||||||
Point p = Util.getScreenSize(service);
|
Point p = Util.getScreenSize(service);
|
||||||
imageSize = Math.min(p.x, p.y);
|
imageSize = Math.min(p.x, p.y);
|
||||||
|
|
@ -133,25 +133,4 @@ public class AppWidgetAlbum extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void linkButtons(final Context context, final RemoteViews views) {
|
|
||||||
Intent action;
|
|
||||||
PendingIntent pendingIntent;
|
|
||||||
|
|
||||||
final ComponentName serviceName = new ComponentName(context, MusicService.class);
|
|
||||||
|
|
||||||
action = new Intent(context, MainActivity.class);
|
|
||||||
action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
pendingIntent = PendingIntent.getActivity(context, 0, action, 0);
|
|
||||||
views.setOnClickPendingIntent(R.id.clickable_area, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_REWIND, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_prev, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_TOGGLE, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_SKIP, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_next, pendingIntent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import com.dkanada.gramophone.activities.MainActivity;
|
||||||
import com.dkanada.gramophone.util.ImageUtil;
|
import com.dkanada.gramophone.util.ImageUtil;
|
||||||
|
|
||||||
public class AppWidgetCard extends BaseAppWidget {
|
public class AppWidgetCard extends BaseAppWidget {
|
||||||
public static final String NAME = "app_widget_card";
|
public static final String NAME = "widget.card";
|
||||||
|
|
||||||
private static AppWidgetCard mInstance;
|
private static AppWidgetCard mInstance;
|
||||||
private Target<BitmapPaletteWrapper> target;
|
private Target<BitmapPaletteWrapper> target;
|
||||||
|
|
@ -52,7 +52,7 @@ public class AppWidgetCard extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
|
protected void reset(final Context context, final int[] appWidgetIds) {
|
||||||
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_card);
|
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_card);
|
||||||
|
|
||||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
|
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
|
||||||
|
|
@ -61,12 +61,12 @@ public class AppWidgetCard extends BaseAppWidget {
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
|
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
|
||||||
|
|
||||||
linkButtons(context, appWidgetView);
|
linkButtons(context, appWidgetView, R.id.image, R.id.media_titles);
|
||||||
pushUpdate(context, appWidgetIds, appWidgetView);
|
pushUpdate(context, appWidgetIds, appWidgetView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
|
public void updateMeta(final MusicService service, final int[] appWidgetIds) {
|
||||||
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_card);
|
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_card);
|
||||||
|
|
||||||
final boolean isPlaying = service.isPlaying();
|
final boolean isPlaying = service.isPlaying();
|
||||||
|
|
@ -86,7 +86,7 @@ public class AppWidgetCard extends BaseAppWidget {
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
|
appWidgetView.setImageViewBitmap(R.id.button_next, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(service, true))));
|
||||||
|
|
||||||
linkButtons(service, appWidgetView);
|
linkButtons(service, appWidgetView, R.id.image, R.id.media_titles);
|
||||||
|
|
||||||
imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_card_image_size);
|
imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_card_image_size);
|
||||||
cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius) / 2;
|
cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius) / 2;
|
||||||
|
|
@ -137,26 +137,4 @@ public class AppWidgetCard extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void linkButtons(final Context context, final RemoteViews views) {
|
|
||||||
Intent action;
|
|
||||||
PendingIntent pendingIntent;
|
|
||||||
|
|
||||||
final ComponentName serviceName = new ComponentName(context, MusicService.class);
|
|
||||||
|
|
||||||
action = new Intent(context, MainActivity.class);
|
|
||||||
action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
pendingIntent = PendingIntent.getActivity(context, 0, action, 0);
|
|
||||||
views.setOnClickPendingIntent(R.id.image, pendingIntent);
|
|
||||||
views.setOnClickPendingIntent(R.id.media_titles, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_REWIND, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_prev, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_TOGGLE, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_SKIP, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_next, pendingIntent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -30,7 +30,7 @@ import com.dkanada.gramophone.activities.MainActivity;
|
||||||
import com.dkanada.gramophone.util.ImageUtil;
|
import com.dkanada.gramophone.util.ImageUtil;
|
||||||
|
|
||||||
public class AppWidgetClassic extends BaseAppWidget {
|
public class AppWidgetClassic extends BaseAppWidget {
|
||||||
public static final String NAME = "app_widget_classic";
|
public static final String NAME = "widget.classic";
|
||||||
|
|
||||||
private static AppWidgetClassic mInstance;
|
private static AppWidgetClassic mInstance;
|
||||||
private Target<BitmapPaletteWrapper> target;
|
private Target<BitmapPaletteWrapper> target;
|
||||||
|
|
@ -52,7 +52,7 @@ public class AppWidgetClassic extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void defaultAppWidget(final Context context, final int[] appWidgetIds) {
|
protected void reset(final Context context, final int[] appWidgetIds) {
|
||||||
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_classic);
|
final RemoteViews appWidgetView = new RemoteViews(context.getPackageName(), R.layout.app_widget_classic);
|
||||||
|
|
||||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
|
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
|
||||||
|
|
@ -61,12 +61,12 @@ public class AppWidgetClassic extends BaseAppWidget {
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
|
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, ImageUtil.createBitmap(ImageUtil.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true))));
|
||||||
|
|
||||||
linkButtons(context, appWidgetView);
|
linkButtons(context, appWidgetView, R.id.image, R.id.media_titles);
|
||||||
pushUpdate(context, appWidgetIds, appWidgetView);
|
pushUpdate(context, appWidgetIds, appWidgetView);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void performUpdate(final MusicService service, final int[] appWidgetIds) {
|
public void updateMeta(final MusicService service, final int[] appWidgetIds) {
|
||||||
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_classic);
|
final RemoteViews appWidgetView = new RemoteViews(service.getPackageName(), R.layout.app_widget_classic);
|
||||||
|
|
||||||
final boolean isPlaying = service.isPlaying();
|
final boolean isPlaying = service.isPlaying();
|
||||||
|
|
@ -80,7 +80,7 @@ public class AppWidgetClassic extends BaseAppWidget {
|
||||||
appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
|
appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
|
||||||
}
|
}
|
||||||
|
|
||||||
linkButtons(service, appWidgetView);
|
linkButtons(service, appWidgetView, R.id.image, R.id.media_titles);
|
||||||
|
|
||||||
imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_classic_image_size);
|
imageSize = service.getResources().getDimensionPixelSize(R.dimen.app_widget_classic_image_size);
|
||||||
cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);
|
cardRadius = service.getResources().getDimension(R.dimen.app_widget_card_radius);
|
||||||
|
|
@ -131,26 +131,4 @@ public class AppWidgetClassic extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private void linkButtons(final Context context, final RemoteViews views) {
|
|
||||||
Intent action;
|
|
||||||
PendingIntent pendingIntent;
|
|
||||||
|
|
||||||
final ComponentName serviceName = new ComponentName(context, MusicService.class);
|
|
||||||
|
|
||||||
action = new Intent(context, MainActivity.class);
|
|
||||||
action.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TOP);
|
|
||||||
pendingIntent = PendingIntent.getActivity(context, 0, action, 0);
|
|
||||||
views.setOnClickPendingIntent(R.id.image, pendingIntent);
|
|
||||||
views.setOnClickPendingIntent(R.id.media_titles, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_REWIND, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_prev, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_TOGGLE, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, pendingIntent);
|
|
||||||
|
|
||||||
pendingIntent = buildPendingIntent(context, MusicService.ACTION_SKIP, serviceName);
|
|
||||||
views.setOnClickPendingIntent(R.id.button_next, pendingIntent);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,6 +22,7 @@ import android.widget.RemoteViews;
|
||||||
import androidx.core.content.res.ResourcesCompat;
|
import androidx.core.content.res.ResourcesCompat;
|
||||||
|
|
||||||
import com.dkanada.gramophone.R;
|
import com.dkanada.gramophone.R;
|
||||||
|
import com.dkanada.gramophone.activities.MainActivity;
|
||||||
import com.dkanada.gramophone.model.Song;
|
import com.dkanada.gramophone.model.Song;
|
||||||
import com.dkanada.gramophone.service.MusicService;
|
import com.dkanada.gramophone.service.MusicService;
|
||||||
import com.dkanada.gramophone.util.MusicUtil;
|
import com.dkanada.gramophone.util.MusicUtil;
|
||||||
|
|
@ -37,7 +38,7 @@ public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
@Override
|
@Override
|
||||||
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
|
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager, final int[] appWidgetIds) {
|
||||||
Log.d(NAME, String.format("onUpdate: %s", Arrays.toString(appWidgetIds)));
|
Log.d(NAME, String.format("onUpdate: %s", Arrays.toString(appWidgetIds)));
|
||||||
defaultAppWidget(context, appWidgetIds);
|
reset(context, appWidgetIds);
|
||||||
|
|
||||||
final Intent updateIntent = new Intent(MusicService.INTENT_EXTRA_WIDGET_UPDATE);
|
final Intent updateIntent = new Intent(MusicService.INTENT_EXTRA_WIDGET_UPDATE);
|
||||||
|
|
||||||
|
|
@ -48,6 +49,10 @@ public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
context.sendBroadcast(updateIntent);
|
context.sendBroadcast(updateIntent);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
abstract protected void reset(final Context context, final int[] appWidgetIds);
|
||||||
|
|
||||||
|
abstract protected void updateMeta(final MusicService service, final int[] appWidgetIds);
|
||||||
|
|
||||||
public void notifyChange(final MusicService service, final String what, int[] appWidgetIds) {
|
public void notifyChange(final MusicService service, final String what, int[] appWidgetIds) {
|
||||||
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(service);
|
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(service);
|
||||||
final ComponentName componentName = new ComponentName(service, getClass());
|
final ComponentName componentName = new ComponentName(service, getClass());
|
||||||
|
|
@ -59,7 +64,7 @@ public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
|
|
||||||
Song song = service.getCurrentSong();
|
Song song = service.getCurrentSong();
|
||||||
if (song != null && (what.equals(MusicService.STATE_CHANGED) || what.equals(MusicService.META_CHANGED))) {
|
if (song != null && (what.equals(MusicService.STATE_CHANGED) || what.equals(MusicService.META_CHANGED))) {
|
||||||
performUpdate(service, appWidgetIds);
|
updateMeta(service, appWidgetIds);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -73,6 +78,26 @@ public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void linkButtons(Context context, RemoteViews views, Integer... clickableViews) {
|
||||||
|
ComponentName serviceName = new ComponentName(context, MusicService.class);
|
||||||
|
|
||||||
|
Intent action = new Intent(context, MainActivity.class);
|
||||||
|
PendingIntent open = PendingIntent.getActivity(context, 0, action, 0);
|
||||||
|
|
||||||
|
for (int id : clickableViews) {
|
||||||
|
views.setOnClickPendingIntent(id, open);
|
||||||
|
}
|
||||||
|
|
||||||
|
PendingIntent previous = buildPendingIntent(context, MusicService.ACTION_REWIND, serviceName);
|
||||||
|
views.setOnClickPendingIntent(R.id.button_prev, previous);
|
||||||
|
|
||||||
|
PendingIntent toggle = buildPendingIntent(context, MusicService.ACTION_TOGGLE, serviceName);
|
||||||
|
views.setOnClickPendingIntent(R.id.button_toggle_play_pause, toggle);
|
||||||
|
|
||||||
|
PendingIntent next = buildPendingIntent(context, MusicService.ACTION_SKIP, serviceName);
|
||||||
|
views.setOnClickPendingIntent(R.id.button_next, next);
|
||||||
|
}
|
||||||
|
|
||||||
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
|
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
|
||||||
Intent intent = new Intent(action);
|
Intent intent = new Intent(action);
|
||||||
|
|
||||||
|
|
@ -128,10 +153,6 @@ public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
return path;
|
return path;
|
||||||
}
|
}
|
||||||
|
|
||||||
abstract protected void defaultAppWidget(final Context context, final int[] appWidgetIds);
|
|
||||||
|
|
||||||
abstract protected void performUpdate(final MusicService service, final int[] appWidgetIds);
|
|
||||||
|
|
||||||
protected Drawable getAlbumArtDrawable(final Resources resources, final Bitmap bitmap) {
|
protected Drawable getAlbumArtDrawable(final Resources resources, final Bitmap bitmap) {
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
return ResourcesCompat.getDrawable(resources, R.drawable.default_album_art, null);
|
return ResourcesCompat.getDrawable(resources, R.drawable.default_album_art, null);
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue