Use ShortcutPseudoActivity for widgets.
Android 8 does not allow us to directly start a background service, use the ShortcutPseudoActivity to do it anyway. That's how we roll now.
This commit is contained in:
parent
4b06348059
commit
9fa33f6420
@ -123,21 +123,19 @@ public class FourLongWidget extends AppWidgetProvider {
|
|||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
PendingIntent pendingIntent;
|
PendingIntent pendingIntent;
|
||||||
|
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
||||||
|
|
||||||
ComponentName service = new ComponentName(context, PlaybackService.class);
|
intent = new Intent(context, LibraryActivity.class).setAction(Intent.ACTION_MAIN);
|
||||||
|
|
||||||
intent = new Intent(context, LibraryActivity.class);
|
|
||||||
intent.setAction(Intent.ACTION_MAIN);
|
|
||||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.cover, pendingIntent);
|
views.setOnClickPendingIntent(R.id.cover, pendingIntent);
|
||||||
views.setOnClickPendingIntent(R.id.text_layout, pendingIntent);
|
views.setOnClickPendingIntent(R.id.text_layout, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_TOGGLE_PLAYBACK);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_NEXT_SONG).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_NEXT_SONG);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
||||||
|
|
||||||
manager.updateAppWidget(new ComponentName(context, FourLongWidget.class), views);
|
manager.updateAppWidget(new ComponentName(context, FourLongWidget.class), views);
|
||||||
|
@ -126,21 +126,19 @@ public class FourSquareWidget extends AppWidgetProvider {
|
|||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
PendingIntent pendingIntent;
|
PendingIntent pendingIntent;
|
||||||
|
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
||||||
|
|
||||||
ComponentName service = new ComponentName(context, PlaybackService.class);
|
intent = new Intent(context, LibraryActivity.class).setAction(Intent.ACTION_MAIN);
|
||||||
|
|
||||||
intent = new Intent(context, LibraryActivity.class);
|
|
||||||
intent.setAction(Intent.ACTION_MAIN);
|
|
||||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.title, pendingIntent);
|
views.setOnClickPendingIntent(R.id.title, pendingIntent);
|
||||||
views.setOnClickPendingIntent(R.id.artist, pendingIntent);
|
views.setOnClickPendingIntent(R.id.artist, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_TOGGLE_PLAYBACK);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_NEXT_SONG).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_NEXT_SONG);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
||||||
|
|
||||||
manager.updateAppWidget(new ComponentName(context, FourSquareWidget.class), views);
|
manager.updateAppWidget(new ComponentName(context, FourSquareWidget.class), views);
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
/*
|
/*
|
||||||
|
* Copyright (C) 2017 Adrian Ulrich <adrian@blinkenlights.ch>
|
||||||
* Copyright (C) 2012 Ferenc Nagy <nferenc@nferenc.com>
|
* Copyright (C) 2012 Ferenc Nagy <nferenc@nferenc.com>
|
||||||
* Copyright (C) 2010, 2011 Christopher Eby <kreed@kreed.org>
|
* Copyright (C) 2010, 2011 Christopher Eby <kreed@kreed.org>
|
||||||
*
|
*
|
||||||
@ -127,25 +128,23 @@ public class FourWhiteWidget extends AppWidgetProvider {
|
|||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
PendingIntent pendingIntent;
|
PendingIntent pendingIntent;
|
||||||
|
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
||||||
|
|
||||||
ComponentName service = new ComponentName(context, PlaybackService.class);
|
intent = new Intent(context, LibraryActivity.class).setAction(Intent.ACTION_MAIN);
|
||||||
|
|
||||||
intent = new Intent(context, LibraryActivity.class);
|
|
||||||
intent.setAction(Intent.ACTION_MAIN);
|
|
||||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.cover, pendingIntent);
|
views.setOnClickPendingIntent(R.id.cover, pendingIntent);
|
||||||
views.setOnClickPendingIntent(R.id.text_layout, pendingIntent);
|
views.setOnClickPendingIntent(R.id.text_layout, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_TOGGLE_PLAYBACK);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_NEXT_SONG).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_NEXT_SONG);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_PREVIOUS_SONG).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_PREVIOUS_SONG);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.previous, pendingIntent);
|
views.setOnClickPendingIntent(R.id.previous, pendingIntent);
|
||||||
|
|
||||||
manager.updateAppWidget(new ComponentName(context, FourWhiteWidget.class), views);
|
manager.updateAppWidget(new ComponentName(context, FourWhiteWidget.class), views);
|
||||||
|
@ -97,15 +97,19 @@ public class OneCellWidget extends AppWidgetProvider {
|
|||||||
boolean playing = (state & PlaybackService.FLAG_PLAYING) != 0;
|
boolean playing = (state & PlaybackService.FLAG_PLAYING) != 0;
|
||||||
views.setImageViewResource(R.id.play_pause, playing ? R.drawable.hidden_pause : R.drawable.hidden_play);
|
views.setImageViewResource(R.id.play_pause, playing ? R.drawable.hidden_pause : R.drawable.hidden_play);
|
||||||
|
|
||||||
ComponentName service = new ComponentName(context, PlaybackService.class);
|
|
||||||
|
|
||||||
Intent playPause = new Intent(doubleTap ? PlaybackService.ACTION_TOGGLE_PLAYBACK_DELAYED : PlaybackService.ACTION_TOGGLE_PLAYBACK);
|
Intent intent;
|
||||||
playPause.setComponent(service);
|
PendingIntent pendingIntent;
|
||||||
views.setOnClickPendingIntent(R.id.play_pause, PendingIntent.getService(context, 0, playPause, 0));
|
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
||||||
|
|
||||||
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(doubleTap ? PlaybackService.ACTION_TOGGLE_PLAYBACK_DELAYED : PlaybackService.ACTION_TOGGLE_PLAYBACK);
|
||||||
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
|
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
||||||
|
|
||||||
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(doubleTap ? PlaybackService.ACTION_NEXT_SONG_DELAYED : PlaybackService.ACTION_NEXT_SONG);
|
||||||
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
|
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
||||||
|
|
||||||
Intent next = new Intent(doubleTap ? PlaybackService.ACTION_NEXT_SONG_DELAYED : PlaybackService.ACTION_NEXT_SONG);
|
|
||||||
next.setComponent(service);
|
|
||||||
views.setOnClickPendingIntent(R.id.next, PendingIntent.getService(context, 0, next, 0));
|
|
||||||
|
|
||||||
Bitmap cover = null;
|
Bitmap cover = null;
|
||||||
if ((state & PlaybackService.FLAG_NO_MEDIA) != 0) {
|
if ((state & PlaybackService.FLAG_NO_MEDIA) != 0) {
|
||||||
|
@ -32,7 +32,13 @@ public class ShortcutPseudoActivity extends Activity {
|
|||||||
final String action = getIntent().getAction();
|
final String action = getIntent().getAction();
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case PlaybackService.ACTION_TOGGLE_PLAYBACK:
|
case PlaybackService.ACTION_TOGGLE_PLAYBACK:
|
||||||
|
case PlaybackService.ACTION_TOGGLE_PLAYBACK_DELAYED:
|
||||||
case PlaybackService.ACTION_RANDOM_MIX_AUTOPLAY:
|
case PlaybackService.ACTION_RANDOM_MIX_AUTOPLAY:
|
||||||
|
case PlaybackService.ACTION_NEXT_SONG:
|
||||||
|
case PlaybackService.ACTION_NEXT_SONG_DELAYED:
|
||||||
|
case PlaybackService.ACTION_PREVIOUS_SONG:
|
||||||
|
case PlaybackService.ACTION_CYCLE_SHUFFLE:
|
||||||
|
case PlaybackService.ACTION_CYCLE_REPEAT:
|
||||||
Intent intent = new Intent(this, PlaybackService.class);
|
Intent intent = new Intent(this, PlaybackService.class);
|
||||||
intent.setAction(action);
|
intent.setAction(action);
|
||||||
startService(intent);
|
startService(intent);
|
||||||
|
@ -121,32 +121,30 @@ public class WidgetD extends AppWidgetProvider {
|
|||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
PendingIntent pendingIntent;
|
PendingIntent pendingIntent;
|
||||||
|
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
||||||
|
|
||||||
ComponentName service = new ComponentName(context, PlaybackService.class);
|
intent = new Intent(context, LibraryActivity.class).setAction(Intent.ACTION_MAIN);
|
||||||
|
|
||||||
intent = new Intent(context, LibraryActivity.class);
|
|
||||||
intent.setAction(Intent.ACTION_MAIN);
|
|
||||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.cover, pendingIntent);
|
views.setOnClickPendingIntent(R.id.cover, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_TOGGLE_PLAYBACK);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_NEXT_SONG).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_NEXT_SONG);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_PREVIOUS_SONG).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_PREVIOUS_SONG);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.previous, pendingIntent);
|
views.setOnClickPendingIntent(R.id.previous, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_CYCLE_SHUFFLE).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_CYCLE_SHUFFLE);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.shuffle, pendingIntent);
|
views.setOnClickPendingIntent(R.id.shuffle, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_CYCLE_REPEAT).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_CYCLE_REPEAT);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.end_action, pendingIntent);
|
views.setOnClickPendingIntent(R.id.end_action, pendingIntent);
|
||||||
|
|
||||||
manager.updateAppWidget(new ComponentName(context, WidgetD.class), views);
|
manager.updateAppWidget(new ComponentName(context, WidgetD.class), views);
|
||||||
|
@ -111,33 +111,31 @@ public class WidgetE extends AppWidgetProvider {
|
|||||||
|
|
||||||
Intent intent;
|
Intent intent;
|
||||||
PendingIntent pendingIntent;
|
PendingIntent pendingIntent;
|
||||||
|
int flags = Intent.FLAG_ACTIVITY_NEW_TASK | Intent.FLAG_ACTIVITY_CLEAR_TASK | Intent.FLAG_ACTIVITY_TASK_ON_HOME;
|
||||||
|
|
||||||
ComponentName service = new ComponentName(context, PlaybackService.class);
|
intent = new Intent(context, LibraryActivity.class).setAction(Intent.ACTION_MAIN);
|
||||||
|
|
||||||
intent = new Intent(context, LibraryActivity.class);
|
|
||||||
intent.setAction(Intent.ACTION_MAIN);
|
|
||||||
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.title, pendingIntent);
|
views.setOnClickPendingIntent(R.id.title, pendingIntent);
|
||||||
views.setOnClickPendingIntent(R.id.artist, pendingIntent);
|
views.setOnClickPendingIntent(R.id.artist, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_TOGGLE_PLAYBACK).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_TOGGLE_PLAYBACK);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
views.setOnClickPendingIntent(R.id.play_pause, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_NEXT_SONG).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_NEXT_SONG);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
views.setOnClickPendingIntent(R.id.next, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_PREVIOUS_SONG).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_PREVIOUS_SONG);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.previous, pendingIntent);
|
views.setOnClickPendingIntent(R.id.previous, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_CYCLE_SHUFFLE).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_CYCLE_SHUFFLE);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.shuffle, pendingIntent);
|
views.setOnClickPendingIntent(R.id.shuffle, pendingIntent);
|
||||||
|
|
||||||
intent = new Intent(PlaybackService.ACTION_CYCLE_REPEAT).setComponent(service);
|
intent = new Intent(context, ShortcutPseudoActivity.class).setFlags(flags).setAction(PlaybackService.ACTION_CYCLE_REPEAT);
|
||||||
pendingIntent = PendingIntent.getService(context, 0, intent, 0);
|
pendingIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||||
views.setOnClickPendingIntent(R.id.end_action, pendingIntent);
|
views.setOnClickPendingIntent(R.id.end_action, pendingIntent);
|
||||||
|
|
||||||
manager.updateAppWidget(new ComponentName(context, WidgetE.class), views);
|
manager.updateAppWidget(new ComponentName(context, WidgetE.class), views);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user