enable and disable the widget as needed
This commit is contained in:
parent
304c33369c
commit
27e3a9ed2b
|
@ -15,22 +15,33 @@ import de.danoeh.antennapod.service.PlayerWidgetService;
|
||||||
public class PlayerWidget extends AppWidgetProvider {
|
public class PlayerWidget extends AppWidgetProvider {
|
||||||
private static final String TAG = "PlayerWidget";
|
private static final String TAG = "PlayerWidget";
|
||||||
|
|
||||||
|
// static because there should only ever be one widget...
|
||||||
|
// and otherwise it just keeps getting reset when it gets messages
|
||||||
|
private static boolean enabled = false;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onReceive(Context context, Intent intent) {
|
public void onReceive(Context context, Intent intent) {
|
||||||
Log.d(TAG, "onReceive");
|
Log.d(TAG, "onReceive");
|
||||||
super.onReceive(context, intent);
|
super.onReceive(context, intent);
|
||||||
|
if (!enabled) {
|
||||||
|
// do nothing
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// these come from the PlaybackService when things should get updated
|
||||||
if (StringUtils.equals(intent.getAction(), PlaybackService.FORCE_WIDGET_UPDATE)) {
|
if (StringUtils.equals(intent.getAction(), PlaybackService.FORCE_WIDGET_UPDATE)) {
|
||||||
startUpdate(context);
|
startUpdate(context);
|
||||||
} else if (StringUtils.equals(intent.getAction(), PlaybackService.STOP_WIDGET_UPDATE)) {
|
} else if (StringUtils.equals(intent.getAction(), PlaybackService.STOP_WIDGET_UPDATE)) {
|
||||||
stopUpdate(context);
|
stopUpdate(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onEnabled(Context context) {
|
public void onEnabled(Context context) {
|
||||||
super.onEnabled(context);
|
super.onEnabled(context);
|
||||||
Log.d(TAG, "Widget enabled");
|
Log.d(TAG, "Widget enabled");
|
||||||
|
enabled = true;
|
||||||
|
startUpdate(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -43,12 +54,8 @@ public class PlayerWidget extends AppWidgetProvider {
|
||||||
@Override
|
@Override
|
||||||
public void onDisabled(Context context) {
|
public void onDisabled(Context context) {
|
||||||
super.onDisabled(context);
|
super.onDisabled(context);
|
||||||
stopUpdate(context);
|
Log.d(TAG, "Widet disabled");
|
||||||
}
|
enabled = false;
|
||||||
|
|
||||||
@Override
|
|
||||||
public void onDeleted(Context context, int[] appWidgetIds) {
|
|
||||||
super.onDeleted(context, appWidgetIds);
|
|
||||||
stopUpdate(context);
|
stopUpdate(context);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -61,5 +68,4 @@ public class PlayerWidget extends AppWidgetProvider {
|
||||||
Log.d(TAG, "stopUpdate() called with: " + "context = [" + context + "]");
|
Log.d(TAG, "stopUpdate() called with: " + "context = [" + context + "]");
|
||||||
context.stopService(new Intent(context, PlayerWidgetService.class));
|
context.stopService(new Intent(context, PlayerWidgetService.class));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue