Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(3516)

Unified Diff: chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaNotificationManager.java

Issue 2441403002: Add media controls in media notification (Closed)
Patch Set: nits Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaNotificationManager.java
diff --git a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaNotificationManager.java b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaNotificationManager.java
index 2a4f0e2867bce13e16c281d2c0b15530b61f5823..f80cc883debbbbdb01bbe048fa460d6bbe6ee27d 100644
--- a/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaNotificationManager.java
+++ b/chrome/android/java/src/org/chromium/chrome/browser/media/ui/MediaNotificationManager.java
@@ -76,6 +76,10 @@ public class MediaNotificationManager {
"MediaNotificationManager.ListenerService.SWIPE";
private static final String ACTION_CANCEL =
"MediaNotificationManager.ListenerService.CANCEL";
+ private static final String ACTION_PREVIOUS_TRACK =
+ "MediaNotificationManager.ListenerService.PREVIOUS_TRACK";
+ private static final String ACTION_NEXT_TRACK =
+ "MediaNotificationManager.ListenerService.NEXT_TRACK";
@Override
public IBinder onBind(Intent intent) {
@@ -159,6 +163,10 @@ public class MediaNotificationManager {
manager.onPause(MediaNotificationListener.ACTION_SOURCE_MEDIA_NOTIFICATION);
} else if (AudioManager.ACTION_AUDIO_BECOMING_NOISY.equals(action)) {
manager.onPause(MediaNotificationListener.ACTION_SOURCE_HEADSET_UNPLUG);
+ } else if (ACTION_PREVIOUS_TRACK.equals(action)) {
+ manager.onMediaSessionAction(MediaSessionAction.ACTION_PREVIOUS_TRACK);
+ } else if (ACTION_NEXT_TRACK.equals(action)) {
+ manager.onMediaSessionAction(MediaSessionAction.ACTION_NEXT_TRACK);
}
}
}
@@ -430,6 +438,8 @@ public class MediaNotificationManager {
private final String mPlayDescription;
private final String mPauseDescription;
private final String mStopDescription;
+ private final String mPreviousTrackDescription;
+ private final String mNextTrackDescription;
private NotificationCompat.Builder mNotificationBuilder;
@@ -461,6 +471,9 @@ public class MediaNotificationManager {
mPlayDescription = context.getResources().getString(R.string.accessibility_play);
mPauseDescription = context.getResources().getString(R.string.accessibility_pause);
mStopDescription = context.getResources().getString(R.string.accessibility_stop);
+ mPreviousTrackDescription = context.getResources().getString(
+ R.string.accessibility_previous_track);
+ mNextTrackDescription = context.getResources().getString(R.string.accessibility_next_track);
}
/**
@@ -502,6 +515,10 @@ public class MediaNotificationManager {
mMediaNotificationInfo.listener.onStop(actionSource);
}
+ private void onMediaSessionAction(MediaSessionAction action) {
+ mMediaNotificationInfo.listener.onMediaSessionAction(action);
+ }
+
private void showNotification(MediaNotificationInfo mediaNotificationInfo) {
if (mediaNotificationInfo.equals(mMediaNotificationInfo)) return;
@@ -690,15 +707,34 @@ public class MediaNotificationManager {
NotificationCompat.MediaStyle style = new NotificationCompat.MediaStyle();
style.setMediaSession(mMediaSession.getSessionToken());
+ int numActions = 0;
whywhat 2016/10/24 20:54:01 nit: maybe extract actions/style setup as a functi
Zhiqiang Zhang (Slow) 2016/10/25 12:45:35 Done. BTW, I think we need to remove the word "Me
+
+ if (mMediaNotificationInfo.mediaSessionActions.contains(
+ MediaSessionAction.ACTION_PREVIOUS_TRACK)) {
+ builder.addAction(R.drawable.ic_vidcontrol_play, mPlayDescription,
mlamouri (slow - plz ping) 2016/10/25 10:38:13 mPreviousTrackDescription
Zhiqiang Zhang (Slow) 2016/10/25 12:45:35 Done.
+ createPendingIntent(ListenerService.ACTION_PREVIOUS_TRACK));
+ ++numActions;
+ }
if (mMediaNotificationInfo.isPaused) {
builder.addAction(R.drawable.ic_vidcontrol_play, mPlayDescription,
createPendingIntent(ListenerService.ACTION_PLAY));
+ ++numActions;
whywhat 2016/10/24 20:54:01 nit: this seems redundant as it will increment num
Zhiqiang Zhang (Slow) 2016/10/25 12:45:35 Hmm, I think we should the pattern consistent (inc
} else {
// If we're here, the notification supports play/pause button and is playing.
builder.addAction(R.drawable.ic_vidcontrol_pause, mPauseDescription,
createPendingIntent(ListenerService.ACTION_PAUSE));
+ ++numActions;
+ }
+ if (mMediaNotificationInfo.mediaSessionActions.contains(
+ MediaSessionAction.ACTION_NEXT_TRACK)) {
+ builder.addAction(R.drawable.ic_vidcontrol_play, mPlayDescription,
mlamouri (slow - plz ping) 2016/10/25 10:38:13 mNextTrackDescription
Zhiqiang Zhang (Slow) 2016/10/25 12:45:35 Done.
+ createPendingIntent(ListenerService.ACTION_NEXT_TRACK));
+ ++numActions;
}
- style.setShowActionsInCompactView(0);
+ numActions = Math.min(numActions, 3);
+ int[] compactViewActions = new int[numActions];
+ for (int i = 0; i < numActions; ++i) compactViewActions[i] = i;
+ style.setShowActionsInCompactView(compactViewActions);
style.setCancelButtonIntent(createPendingIntent(ListenerService.ACTION_CANCEL));
style.setShowCancelButton(true);
builder.setStyle(style);

Powered by Google App Engine
This is Rietveld 408576698