Add a new action for notification click: skip to next song
This commit is contained in:
parent
332d585961
commit
2a1361b626
@ -27,6 +27,11 @@
|
||||
<item>Show When Playing</item>
|
||||
<item>Always Show</item>
|
||||
</string-array>
|
||||
<string-array name="notification_action_entries">
|
||||
<item>Open Main Activity</item>
|
||||
<item>Open Mini Player</item>
|
||||
<item>Skip To Next Song</item>
|
||||
</string-array>
|
||||
<string-array name="entry_values">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
|
@ -100,10 +100,10 @@
|
||||
<string name="headset_pause_summary">Pause when the headphones are unplugged.</string>
|
||||
|
||||
<string name="pref_notifications">Notifications</string>
|
||||
<string name="mini_player_title">Use Mini Player</string>
|
||||
<string name="mini_player_summary">Launch a pop-up music control dialog when the notification is pressed</string>
|
||||
<string name="notification_mode_title">Notification Mode</string>
|
||||
<string name="notification_mode_summary">When to show the notification</string>
|
||||
<string name="notification_action_title">Notification Action</string>
|
||||
<string name="notification_action_summary">What to do when the notification is pressed</string>
|
||||
|
||||
<string name="pref_song_selector">Song Selector</string>
|
||||
<string name="selector_on_startup_title">Open on Startup</string>
|
||||
|
@ -48,11 +48,13 @@
|
||||
android:entries="@array/notification_mode_entries"
|
||||
android:entryValues="@array/entry_values"
|
||||
android:defaultValue="1" />
|
||||
<CheckBoxPreference
|
||||
android:key="remote_player"
|
||||
android:title="@string/mini_player_title"
|
||||
android:summary="@string/mini_player_summary"
|
||||
android:defaultValue="true" />
|
||||
<ListPreference
|
||||
android:key="notification_action"
|
||||
android:title="@string/notification_action_title"
|
||||
android:summary="@string/notification_action_summary"
|
||||
android:entries="@array/notification_action_entries"
|
||||
android:entryValues="@array/entry_values"
|
||||
android:defaultValue="0" />
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory android:title="@string/pref_song_selector">
|
||||
<CheckBoxPreference
|
||||
|
@ -131,7 +131,6 @@ public class MediaButtonHandler implements Handler.Callback {
|
||||
Context context = ContextApplication.getContext();
|
||||
Intent intent = new Intent(context, PlaybackService.class);
|
||||
intent.setAction(action);
|
||||
intent.putExtra("autoplay", true);
|
||||
context.startService(intent);
|
||||
}
|
||||
|
||||
@ -160,7 +159,7 @@ public class MediaButtonHandler implements Handler.Callback {
|
||||
if (mHandler.hasMessages(MSG_SINGLE_PRESS_TIMEOUT)) {
|
||||
// double click
|
||||
mHandler.removeMessages(MSG_SINGLE_PRESS_TIMEOUT);
|
||||
act(PlaybackService.ACTION_NEXT_SONG);
|
||||
act(PlaybackService.ACTION_NEXT_SONG_AUTOPLAY);
|
||||
} else {
|
||||
mHandler.sendEmptyMessageDelayed(MSG_SINGLE_PRESS_TIMEOUT, DOUBLE_CLICK_DELAY);
|
||||
}
|
||||
@ -168,11 +167,11 @@ public class MediaButtonHandler implements Handler.Callback {
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_NEXT:
|
||||
if (action == KeyEvent.ACTION_DOWN)
|
||||
act(PlaybackService.ACTION_NEXT_SONG);
|
||||
act(PlaybackService.ACTION_NEXT_SONG_AUTOPLAY);
|
||||
break;
|
||||
case KeyEvent.KEYCODE_MEDIA_PREVIOUS:
|
||||
if (action == KeyEvent.ACTION_DOWN)
|
||||
act(PlaybackService.ACTION_PREVIOUS_SONG);
|
||||
act(PlaybackService.ACTION_PREVIOUS_SONG_AUTOPLAY);
|
||||
break;
|
||||
default:
|
||||
return false;
|
||||
|
@ -79,10 +79,24 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
* instead.
|
||||
*/
|
||||
public static final String ACTION_NEXT_SONG_DELAYED = "org.kreed.vanilla.action.NEXT_SONG_DELAYED";
|
||||
/**
|
||||
* Action for startService: advance to the next song.
|
||||
*
|
||||
* Like ACTION_NEXT_SONG, but starts playing automatically if paused
|
||||
* when this is called.
|
||||
*/
|
||||
public static final String ACTION_NEXT_SONG_AUTOPLAY = "org.kreed.vanilla.action.NEXT_SONG_AUTOPLAY";
|
||||
/**
|
||||
* Action for startService: go back to the previous song.
|
||||
*/
|
||||
public static final String ACTION_PREVIOUS_SONG = "org.kreed.vanilla.action.PREVIOUS_SONG";
|
||||
/**
|
||||
* Action for startService: go back to the previous song.
|
||||
*
|
||||
* Like ACTION_PREVIOUS_SONG, but starts playing automatically if paused
|
||||
* when this is called.
|
||||
*/
|
||||
public static final String ACTION_PREVIOUS_SONG_AUTOPLAY = "org.kreed.vanilla.action.PREVIOUS_SONG_AUTOPLAY";
|
||||
/**
|
||||
* Intent action that may be invoked through startService.
|
||||
*
|
||||
@ -233,6 +247,8 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
// feedback.
|
||||
broadcastReplaceSong(0, getSong(+1));
|
||||
go(1, false);
|
||||
} else if (ACTION_NEXT_SONG_AUTOPLAY.equals(action)) {
|
||||
go(1, true);
|
||||
} else if (ACTION_NEXT_SONG_DELAYED.equals(action)) {
|
||||
if (mHandler.hasMessages(CALL_GO, Integer.valueOf(1))) {
|
||||
mHandler.removeMessages(CALL_GO, Integer.valueOf(1));
|
||||
@ -242,6 +258,8 @@ public final class PlaybackService extends Service implements Handler.Callback,
|
||||
}
|
||||
} else if (ACTION_PREVIOUS_SONG.equals(action)) {
|
||||
go(-1, false);
|
||||
} else if (ACTION_PREVIOUS_SONG_AUTOPLAY.equals(action)) {
|
||||
go(-1, true);
|
||||
} else if (ACTION_PLAY_ITEMS.equals(action)) {
|
||||
mTimeline.chooseSongs(false, intent.getIntExtra("type", 3), intent.getLongExtra("id", -1));
|
||||
mHandler.sendEmptyMessage(TRACK_CHANGED);
|
||||
|
@ -24,6 +24,7 @@ import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.SharedPreferences;
|
||||
import android.preference.PreferenceManager;
|
||||
import android.util.Log;
|
||||
import android.widget.RemoteViews;
|
||||
|
||||
/**
|
||||
@ -36,6 +37,19 @@ import android.widget.RemoteViews;
|
||||
* lower line is the song artist.
|
||||
*/
|
||||
public class SongNotification extends Notification {
|
||||
/**
|
||||
* Notification click action: open LaunchActivity.
|
||||
*/
|
||||
private static final int ACTION_MAIN_ACTIVITY = 0;
|
||||
/**
|
||||
* Notification click action: open MiniPlaybackActivity.
|
||||
*/
|
||||
private static final int ACTION_MINI_ACTIVITY = 1;
|
||||
/**
|
||||
* Notification click action: skip to next song.
|
||||
*/
|
||||
private static final int ACTION_NEXT_SONG = 2;
|
||||
|
||||
/**
|
||||
* Create a SongNotification. Call through the NotificationManager to
|
||||
* display it.
|
||||
@ -47,7 +61,7 @@ public class SongNotification extends Notification {
|
||||
{
|
||||
Context context = ContextApplication.getContext();
|
||||
SharedPreferences prefs = PreferenceManager.getDefaultSharedPreferences(context);
|
||||
boolean remoteView = prefs.getBoolean("remote_player", true);
|
||||
int action = Integer.parseInt(prefs.getString("notification_action", "0"));
|
||||
int statusIcon = playing ? R.drawable.status_icon : R.drawable.status_icon_paused;
|
||||
|
||||
RemoteViews views = new RemoteViews(ContextApplication.getContext().getPackageName(), R.layout.notification);
|
||||
@ -58,7 +72,28 @@ public class SongNotification extends Notification {
|
||||
contentView = views;
|
||||
icon = statusIcon;
|
||||
flags |= Notification.FLAG_ONGOING_EVENT;
|
||||
Intent intent = new Intent(context, remoteView ? MiniPlaybackActivity.class : LaunchActivity.class);
|
||||
contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
|
||||
Intent intent;
|
||||
switch (action) {
|
||||
case ACTION_NEXT_SONG:
|
||||
intent = new Intent(context, PlaybackService.class);
|
||||
intent.setAction(PlaybackService.ACTION_NEXT_SONG_AUTOPLAY);
|
||||
contentIntent = PendingIntent.getService(context, 0, intent, 0);
|
||||
break;
|
||||
case ACTION_MINI_ACTIVITY:
|
||||
intent = new Intent(context, MiniPlaybackActivity.class);
|
||||
contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
break;
|
||||
default:
|
||||
Log.w("VanillaMusic", "Unknown value for notification_action: " + action + ". Resetting to 0.");
|
||||
SharedPreferences.Editor editor = prefs.edit();
|
||||
editor.putString("notification_action", "0");
|
||||
editor.commit();
|
||||
// fall through
|
||||
case ACTION_MAIN_ACTIVITY:
|
||||
intent = new Intent(context, LaunchActivity.class);
|
||||
contentIntent = PendingIntent.getActivity(context, 0, intent, 0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user