Minor refactoring of widget code
This commit is contained in:
parent
0377e43475
commit
5d94555afe
8 changed files with 121 additions and 153 deletions
|
|
@ -18,6 +18,7 @@ import com.bumptech.glide.request.target.SimpleTarget;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
import com.kabouzeid.gramophone.appwidgets.base.BaseAppWidget;
|
||||||
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.service.MusicService;
|
import com.kabouzeid.gramophone.service.MusicService;
|
||||||
|
|
@ -69,7 +70,7 @@ public class AppWidgetBig extends BaseAppWidget {
|
||||||
} else {
|
} else {
|
||||||
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
|
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
|
||||||
appWidgetView.setTextViewText(R.id.title, song.title);
|
appWidgetView.setTextViewText(R.id.title, song.title);
|
||||||
appWidgetView.setTextViewText(R.id.text, song.artistName + " • " +song.albumName);
|
appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set correct drawable for pause state
|
// Set correct drawable for pause state
|
||||||
|
|
@ -109,7 +110,6 @@ public class AppWidgetBig extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(@Nullable Bitmap bitmap) {
|
private void update(@Nullable Bitmap bitmap) {
|
||||||
appWidgetView.setViewVisibility(R.id.image, View.VISIBLE);
|
|
||||||
if (bitmap == null) {
|
if (bitmap == null) {
|
||||||
appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
|
appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import com.bumptech.glide.request.target.SimpleTarget;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
import com.kabouzeid.gramophone.appwidgets.base.BaseAppWidget;
|
||||||
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
||||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
|
@ -49,7 +50,7 @@ public class AppWidgetCard extends BaseAppWidget {
|
||||||
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);
|
||||||
appWidgetView.setViewVisibility(R.id.image, View.INVISIBLE);
|
appWidgetView.setImageViewResource(R.id.image, R.drawable.default_album_art);
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_next_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_skip_previous_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(context, R.drawable.ic_play_arrow_white_24dp, MaterialValueHelper.getSecondaryTextColor(context, true)), 1f));
|
||||||
|
|
@ -71,16 +72,9 @@ public class AppWidgetCard extends BaseAppWidget {
|
||||||
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
if (TextUtils.isEmpty(song.title) && TextUtils.isEmpty(song.artistName)) {
|
||||||
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
|
appWidgetView.setViewVisibility(R.id.media_titles, View.INVISIBLE);
|
||||||
} else {
|
} else {
|
||||||
if (TextUtils.isEmpty(song.artistName) || TextUtils.isEmpty(song.albumName)) {
|
|
||||||
appWidgetView.setTextViewText(R.id.text_separator, "");
|
|
||||||
} else {
|
|
||||||
appWidgetView.setTextViewText(R.id.text_separator, "•");
|
|
||||||
}
|
|
||||||
|
|
||||||
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
|
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
|
||||||
appWidgetView.setTextViewText(R.id.title, song.title);
|
appWidgetView.setTextViewText(R.id.title, song.title);
|
||||||
appWidgetView.setTextViewText(R.id.artist, song.artistName);
|
appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
|
||||||
appWidgetView.setTextViewText(R.id.album, song.albumName);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Set correct drawable for pause state
|
// Set correct drawable for pause state
|
||||||
|
|
@ -124,8 +118,6 @@ public class AppWidgetCard extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(@Nullable Bitmap bitmap, int color) {
|
private void update(@Nullable Bitmap bitmap, int color) {
|
||||||
appWidgetView.setViewVisibility(R.id.image, View.VISIBLE);
|
|
||||||
|
|
||||||
// Set correct drawable for pause state
|
// Set correct drawable for pause state
|
||||||
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
|
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, color), 1f));
|
||||||
|
|
@ -134,15 +126,9 @@ public class AppWidgetCard extends BaseAppWidget {
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color), 1f));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color), 1f));
|
||||||
|
|
||||||
Drawable image;
|
final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
|
||||||
|
final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, cardRadius, 0);
|
||||||
if (bitmap == null) {
|
appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);
|
||||||
image = service.getResources().getDrawable(R.drawable.default_album_art);
|
|
||||||
} else {
|
|
||||||
image = new BitmapDrawable(bitmap);
|
|
||||||
}
|
|
||||||
|
|
||||||
appWidgetView.setImageViewBitmap(R.id.image, createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, cardRadius, 0));
|
|
||||||
|
|
||||||
pushUpdate(service, appWidgetIds, appWidgetView);
|
pushUpdate(service, appWidgetIds, appWidgetView);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import com.bumptech.glide.request.target.SimpleTarget;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
import com.kabouzeid.gramophone.appwidgets.base.BaseAppWidget;
|
||||||
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
||||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
|
@ -73,7 +74,7 @@ public class AppWidgetClassic extends BaseAppWidget {
|
||||||
} else {
|
} else {
|
||||||
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
|
appWidgetView.setViewVisibility(R.id.media_titles, View.VISIBLE);
|
||||||
appWidgetView.setTextViewText(R.id.title, song.title);
|
appWidgetView.setTextViewText(R.id.title, song.title);
|
||||||
appWidgetView.setTextViewText(R.id.text, song.artistName + " • " +song.albumName);
|
appWidgetView.setTextViewText(R.id.text, getSongArtistAndAlbum(song));
|
||||||
}
|
}
|
||||||
|
|
||||||
// Link actions buttons to intents
|
// Link actions buttons to intents
|
||||||
|
|
@ -110,8 +111,6 @@ public class AppWidgetClassic extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(@Nullable Bitmap bitmap, int color) {
|
private void update(@Nullable Bitmap bitmap, int color) {
|
||||||
appWidgetView.setViewVisibility(R.id.image, View.VISIBLE);
|
|
||||||
|
|
||||||
// Set correct drawable for pause state
|
// Set correct drawable for pause state
|
||||||
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
|
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, color), 1f));
|
||||||
|
|
@ -120,13 +119,9 @@ public class AppWidgetClassic extends BaseAppWidget {
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color), 1f));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color), 1f));
|
||||||
|
|
||||||
Drawable image;
|
final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
|
||||||
if (bitmap == null) {
|
final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, cardRadius, 0);
|
||||||
image = service.getResources().getDrawable(R.drawable.default_album_art);
|
appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);
|
||||||
} else {
|
|
||||||
image = new BitmapDrawable(bitmap);
|
|
||||||
}
|
|
||||||
appWidgetView.setImageViewBitmap(R.id.image, createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, cardRadius, 0));
|
|
||||||
|
|
||||||
pushUpdate(appContext, appWidgetIds, appWidgetView);
|
pushUpdate(appContext, appWidgetIds, appWidgetView);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,6 +19,7 @@ import com.bumptech.glide.request.target.SimpleTarget;
|
||||||
import com.bumptech.glide.request.target.Target;
|
import com.bumptech.glide.request.target.Target;
|
||||||
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
import com.kabouzeid.appthemehelper.util.MaterialValueHelper;
|
||||||
import com.kabouzeid.gramophone.R;
|
import com.kabouzeid.gramophone.R;
|
||||||
|
import com.kabouzeid.gramophone.appwidgets.base.BaseAppWidget;
|
||||||
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
import com.kabouzeid.gramophone.glide.SongGlideRequest;
|
||||||
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
import com.kabouzeid.gramophone.glide.palette.BitmapPaletteWrapper;
|
||||||
import com.kabouzeid.gramophone.model.Song;
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
|
|
@ -116,8 +117,6 @@ public class AppWidgetSmall extends BaseAppWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
private void update(@Nullable Bitmap bitmap, int color) {
|
private void update(@Nullable Bitmap bitmap, int color) {
|
||||||
appWidgetView.setViewVisibility(R.id.image, View.VISIBLE);
|
|
||||||
|
|
||||||
// Set correct drawable for pause state
|
// Set correct drawable for pause state
|
||||||
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
|
int playPauseRes = isPlaying ? R.drawable.ic_pause_white_24dp : R.drawable.ic_play_arrow_white_24dp;
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_toggle_play_pause, createBitmap(Util.getTintedVectorDrawable(service, playPauseRes, color), 1f));
|
||||||
|
|
@ -126,13 +125,9 @@ public class AppWidgetSmall extends BaseAppWidget {
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_next, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_next_white_24dp, color), 1f));
|
||||||
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color), 1f));
|
appWidgetView.setImageViewBitmap(R.id.button_prev, createBitmap(Util.getTintedVectorDrawable(service, R.drawable.ic_skip_previous_white_24dp, color), 1f));
|
||||||
|
|
||||||
Drawable image;
|
final Drawable image = getAlbumArtDrawable(service.getResources(), bitmap);
|
||||||
if (bitmap == null) {
|
final Bitmap roundedBitmap = createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, 0, 0);
|
||||||
image = service.getResources().getDrawable(R.drawable.default_album_art);
|
appWidgetView.setImageViewBitmap(R.id.image, roundedBitmap);
|
||||||
} else {
|
|
||||||
image = new BitmapDrawable(bitmap);
|
|
||||||
}
|
|
||||||
appWidgetView.setImageViewBitmap(R.id.image, createRoundedBitmap(image, imageSize, imageSize, cardRadius, 0, 0, 0));
|
|
||||||
|
|
||||||
pushUpdate(appContext, appWidgetIds, appWidgetView);
|
pushUpdate(appContext, appWidgetIds, appWidgetView);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -8,9 +8,6 @@ import android.content.Intent;
|
||||||
|
|
||||||
import com.kabouzeid.gramophone.service.MusicService;
|
import com.kabouzeid.gramophone.service.MusicService;
|
||||||
|
|
||||||
/**
|
|
||||||
* @author Eugene Cheung (arkon)
|
|
||||||
*/
|
|
||||||
public class BootReceiver extends BroadcastReceiver {
|
public class BootReceiver extends BroadcastReceiver {
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
package com.kabouzeid.gramophone.appwidgets;
|
package com.kabouzeid.gramophone.appwidgets.base;
|
||||||
|
|
||||||
import android.app.PendingIntent;
|
import android.app.PendingIntent;
|
||||||
import android.appwidget.AppWidgetManager;
|
import android.appwidget.AppWidgetManager;
|
||||||
|
|
@ -6,20 +6,77 @@ import android.appwidget.AppWidgetProvider;
|
||||||
import android.content.ComponentName;
|
import android.content.ComponentName;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
import android.content.Intent;
|
import android.content.Intent;
|
||||||
|
import android.content.res.Resources;
|
||||||
import android.graphics.Bitmap;
|
import android.graphics.Bitmap;
|
||||||
import android.graphics.BitmapShader;
|
import android.graphics.BitmapShader;
|
||||||
import android.graphics.Canvas;
|
import android.graphics.Canvas;
|
||||||
import android.graphics.Paint;
|
import android.graphics.Paint;
|
||||||
import android.graphics.Path;
|
import android.graphics.Path;
|
||||||
import android.graphics.RectF;
|
import android.graphics.RectF;
|
||||||
|
import android.graphics.drawable.BitmapDrawable;
|
||||||
import android.graphics.drawable.Drawable;
|
import android.graphics.drawable.Drawable;
|
||||||
|
import android.text.TextUtils;
|
||||||
import android.widget.RemoteViews;
|
import android.widget.RemoteViews;
|
||||||
|
|
||||||
|
import com.kabouzeid.gramophone.R;
|
||||||
|
import com.kabouzeid.gramophone.model.Song;
|
||||||
import com.kabouzeid.gramophone.service.MusicService;
|
import com.kabouzeid.gramophone.service.MusicService;
|
||||||
|
|
||||||
public abstract class BaseAppWidget extends AppWidgetProvider {
|
public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
public static final String NAME = "app_widget";
|
public static final String NAME = "app_widget";
|
||||||
|
|
||||||
|
/**
|
||||||
|
* {@inheritDoc}
|
||||||
|
*/
|
||||||
|
@Override
|
||||||
|
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager,
|
||||||
|
final int[] appWidgetIds) {
|
||||||
|
defaultAppWidget(context, appWidgetIds);
|
||||||
|
final Intent updateIntent = new Intent(MusicService.APP_WIDGET_UPDATE);
|
||||||
|
updateIntent.putExtra(MusicService.EXTRA_APP_WIDGET_NAME, NAME);
|
||||||
|
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
|
||||||
|
updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
|
||||||
|
context.sendBroadcast(updateIntent);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handle a change notification coming over from
|
||||||
|
* {@link MusicService}
|
||||||
|
*/
|
||||||
|
public void notifyChange(final MusicService service, final String what) {
|
||||||
|
if (hasInstances(service)) {
|
||||||
|
if (MusicService.META_CHANGED.equals(what) || MusicService.PLAY_STATE_CHANGED.equals(what)) {
|
||||||
|
performUpdate(service, null);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void pushUpdate(final Context context, final int[] appWidgetIds, final RemoteViews views) {
|
||||||
|
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
|
if (appWidgetIds != null) {
|
||||||
|
appWidgetManager.updateAppWidget(appWidgetIds, views);
|
||||||
|
} else {
|
||||||
|
appWidgetManager.updateAppWidget(new ComponentName(context, getClass()), views);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Check against {@link AppWidgetManager} if there are any instances of this
|
||||||
|
* widget.
|
||||||
|
*/
|
||||||
|
protected boolean hasInstances(final Context context) {
|
||||||
|
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
||||||
|
final int[] mAppWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context,
|
||||||
|
getClass()));
|
||||||
|
return mAppWidgetIds.length > 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
|
||||||
|
Intent intent = new Intent(action);
|
||||||
|
intent.setComponent(serviceName);
|
||||||
|
return PendingIntent.getService(context, 0, intent, 0);
|
||||||
|
}
|
||||||
|
|
||||||
protected static Bitmap createBitmap(Drawable drawable, float sizeMultiplier) {
|
protected static Bitmap createBitmap(Drawable drawable, float sizeMultiplier) {
|
||||||
Bitmap bitmap = Bitmap.createBitmap((int) (drawable.getIntrinsicWidth() * sizeMultiplier), (int) (drawable.getIntrinsicHeight() * sizeMultiplier), Bitmap.Config.ARGB_8888);
|
Bitmap bitmap = Bitmap.createBitmap((int) (drawable.getIntrinsicWidth() * sizeMultiplier), (int) (drawable.getIntrinsicHeight() * sizeMultiplier), Bitmap.Config.ARGB_8888);
|
||||||
Canvas c = new Canvas(bitmap);
|
Canvas c = new Canvas(bitmap);
|
||||||
|
|
@ -72,55 +129,23 @@ public abstract class BaseAppWidget extends AppWidgetProvider {
|
||||||
|
|
||||||
abstract public void performUpdate(final MusicService service, final int[] appWidgetIds);
|
abstract public void performUpdate(final MusicService service, final int[] appWidgetIds);
|
||||||
|
|
||||||
/**
|
protected Drawable getAlbumArtDrawable(final Resources resources, final Bitmap bitmap) {
|
||||||
* {@inheritDoc}
|
Drawable image;
|
||||||
*/
|
if (bitmap == null) {
|
||||||
@Override
|
image = resources.getDrawable(R.drawable.default_album_art);
|
||||||
public void onUpdate(final Context context, final AppWidgetManager appWidgetManager,
|
|
||||||
final int[] appWidgetIds) {
|
|
||||||
defaultAppWidget(context, appWidgetIds);
|
|
||||||
final Intent updateIntent = new Intent(MusicService.APP_WIDGET_UPDATE);
|
|
||||||
updateIntent.putExtra(MusicService.EXTRA_APP_WIDGET_NAME, NAME);
|
|
||||||
updateIntent.putExtra(AppWidgetManager.EXTRA_APPWIDGET_IDS, appWidgetIds);
|
|
||||||
updateIntent.addFlags(Intent.FLAG_RECEIVER_REGISTERED_ONLY);
|
|
||||||
context.sendBroadcast(updateIntent);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Handle a change notification coming over from
|
|
||||||
* {@link MusicService}
|
|
||||||
*/
|
|
||||||
public void notifyChange(final MusicService service, final String what) {
|
|
||||||
if (hasInstances(service)) {
|
|
||||||
if (MusicService.META_CHANGED.equals(what) || MusicService.PLAY_STATE_CHANGED.equals(what)) {
|
|
||||||
performUpdate(service, null);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void pushUpdate(final Context context, final int[] appWidgetIds, final RemoteViews views) {
|
|
||||||
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
|
||||||
if (appWidgetIds != null) {
|
|
||||||
appWidgetManager.updateAppWidget(appWidgetIds, views);
|
|
||||||
} else {
|
} else {
|
||||||
appWidgetManager.updateAppWidget(new ComponentName(context, getClass()), views);
|
image = new BitmapDrawable(resources, bitmap);
|
||||||
}
|
}
|
||||||
|
return image;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
protected String getSongArtistAndAlbum(final Song song) {
|
||||||
* Check against {@link AppWidgetManager} if there are any instances of this
|
final StringBuilder builder = new StringBuilder();
|
||||||
* widget.
|
builder.append(song.artistName);
|
||||||
*/
|
if (!TextUtils.isEmpty(song.artistName) && !TextUtils.isEmpty(song.albumName)) {
|
||||||
protected boolean hasInstances(final Context context) {
|
builder.append(" • ");
|
||||||
final AppWidgetManager appWidgetManager = AppWidgetManager.getInstance(context);
|
|
||||||
final int[] mAppWidgetIds = appWidgetManager.getAppWidgetIds(new ComponentName(context,
|
|
||||||
getClass()));
|
|
||||||
return mAppWidgetIds.length > 0;
|
|
||||||
}
|
}
|
||||||
|
builder.append(song.albumName);
|
||||||
protected PendingIntent buildPendingIntent(Context context, final String action, final ComponentName serviceName) {
|
return builder.toString();
|
||||||
Intent intent = new Intent(action);
|
|
||||||
intent.setComponent(serviceName);
|
|
||||||
return PendingIntent.getService(context, 0, intent, 0);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -8,77 +8,47 @@
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="center"
|
android:layout_gravity="center"
|
||||||
android:orientation="horizontal"
|
android:background="@drawable/card"
|
||||||
android:background="@drawable/card">
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<ImageView
|
<ImageView
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
android:layout_width="@dimen/app_widget_card_image_size"
|
android:layout_width="@dimen/app_widget_card_image_size"
|
||||||
android:layout_height="@dimen/app_widget_card_image_size"
|
android:layout_height="@dimen/app_widget_card_image_size"
|
||||||
android:scaleType="centerInside"
|
android:scaleType="centerInside"
|
||||||
tools:src="@drawable/default_album_art"
|
tools:ignore="ContentDescription"
|
||||||
tools:ignore="ContentDescription"/>
|
tools:src="@drawable/default_album_art" />
|
||||||
|
|
||||||
<LinearLayout
|
<LinearLayout
|
||||||
android:id="@+id/media_titles"
|
android:id="@+id/media_titles"
|
||||||
android:layout_width="0dp"
|
android:layout_width="0dp"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:layout_weight="1"
|
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_marginRight="8dp"
|
android:layout_marginRight="8dp"
|
||||||
android:orientation="vertical"
|
android:layout_weight="1"
|
||||||
android:gravity="center">
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
|
android:singleLine="true"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
||||||
android:textColor="@color/ate_primary_text_light"
|
android:textColor="@color/ate_primary_text_light"
|
||||||
android:singleLine="true"
|
|
||||||
tools:text="Title" />
|
tools:text="Title" />
|
||||||
|
|
||||||
<LinearLayout
|
<TextView
|
||||||
|
android:id="@+id/text"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginTop="4dp"
|
android:layout_marginTop="4dp"
|
||||||
android:orientation="horizontal">
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/artist"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
android:gravity="center_vertical"
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
|
||||||
android:textColor="@color/ate_secondary_text_light"
|
|
||||||
android:singleLine="true"
|
android:singleLine="true"
|
||||||
tools:text="Artist"/>
|
android:textAppearance="@style/TextAppearance.AppCompat.Caption"
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/text_separator"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:paddingLeft="4dp"
|
|
||||||
android:paddingRight="4dp"
|
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
|
||||||
android:textColor="@color/ate_secondary_text_light"
|
android:textColor="@color/ate_secondary_text_light"
|
||||||
android:singleLine="true"
|
tools:text="Text" />
|
||||||
tools:ignore="HardcodedText"
|
|
||||||
tools:text="•"/>
|
|
||||||
|
|
||||||
<TextView
|
|
||||||
android:id="@+id/album"
|
|
||||||
android:layout_width="wrap_content"
|
|
||||||
android:layout_height="wrap_content"
|
|
||||||
android:gravity="center_vertical"
|
|
||||||
android:textAppearance="@style/TextAppearance.AppCompat.Body1"
|
|
||||||
android:textColor="@color/ate_secondary_text_light"
|
|
||||||
android:singleLine="true"
|
|
||||||
tools:text="Album"/>
|
|
||||||
|
|
||||||
</LinearLayout>
|
|
||||||
|
|
||||||
</LinearLayout>
|
</LinearLayout>
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -12,8 +12,8 @@
|
||||||
android:id="@+id/image"
|
android:id="@+id/image"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:scaleType="centerCrop"
|
|
||||||
android:adjustViewBounds="true"
|
android:adjustViewBounds="true"
|
||||||
|
android:scaleType="centerCrop"
|
||||||
tools:ignore="ContentDescription"
|
tools:ignore="ContentDescription"
|
||||||
tools:src="@drawable/default_album_art" />
|
tools:src="@drawable/default_album_art" />
|
||||||
|
|
||||||
|
|
@ -25,13 +25,13 @@
|
||||||
android:id="@+id/media_actions"
|
android:id="@+id/media_actions"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom"
|
|
||||||
android:layoutDirection="ltr"
|
|
||||||
android:orientation="horizontal"
|
|
||||||
android:layout_marginBottom="8dp"
|
|
||||||
android:layout_alignParentBottom="true"
|
android:layout_alignParentBottom="true"
|
||||||
android:layout_alignParentLeft="true"
|
android:layout_alignParentLeft="true"
|
||||||
android:layout_alignParentStart="true">
|
android:layout_alignParentStart="true"
|
||||||
|
android:layout_gravity="bottom"
|
||||||
|
android:layout_marginBottom="8dp"
|
||||||
|
android:layoutDirection="ltr"
|
||||||
|
android:orientation="horizontal">
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/button_prev"
|
android:id="@+id/button_prev"
|
||||||
|
|
@ -68,10 +68,10 @@
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_above="@+id/media_actions"
|
android:layout_above="@+id/media_actions"
|
||||||
android:layout_alignParentTop="true"
|
android:layout_alignParentTop="true"
|
||||||
android:orientation="vertical"
|
|
||||||
android:gravity="center"
|
|
||||||
android:layout_marginLeft="8dp"
|
android:layout_marginLeft="8dp"
|
||||||
android:layout_marginRight="8dp">
|
android:layout_marginRight="8dp"
|
||||||
|
android:gravity="center"
|
||||||
|
android:orientation="vertical">
|
||||||
|
|
||||||
<TextView
|
<TextView
|
||||||
android:id="@+id/title"
|
android:id="@+id/title"
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue