Commit baf00406 by bachinger Committed by Oliver Woodman

Provide option to include next/prev button in lock screen/compact mode.

Issue: #5616
PiperOrigin-RevId: 242452686
parent a6d52d4a
...@@ -74,6 +74,8 @@ ...@@ -74,6 +74,8 @@
`PlayerNotificationManager` has been fixed. Apps using `PlayerNotificationManager` has been fixed. Apps using
`DownloadNotificationUtil` should switch to using `DownloadNotificationUtil` should switch to using
`DownloadNotificationHelper`. `DownloadNotificationHelper`.
* Provide flag to include next/prev buttons in compact mode of a notification
([#5616](https://github.com/google/ExoPlayer/issues/5616)).
* Move creation of dialogs for `TrackSelectionView`s to * Move creation of dialogs for `TrackSelectionView`s to
`TrackSelectionDialogBuilder` and add option to select multiple overrides. `TrackSelectionDialogBuilder` and add option to select multiple overrides.
* MediaSessionConnector: Let apps intercept media button events * MediaSessionConnector: Let apps intercept media button events
......
...@@ -47,6 +47,7 @@ import java.lang.annotation.Documented; ...@@ -47,6 +47,7 @@ import java.lang.annotation.Documented;
import java.lang.annotation.Retention; import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy; import java.lang.annotation.RetentionPolicy;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
...@@ -74,6 +75,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull; ...@@ -74,6 +75,12 @@ import org.checkerframework.checker.nullness.qual.RequiresNonNull;
* <li>Corresponding setter: {@link #setUseNavigationActions(boolean)} * <li>Corresponding setter: {@link #setUseNavigationActions(boolean)}
* <li>Default: {@code true} * <li>Default: {@code true}
* </ul> * </ul>
* <li><b>{@code useNavigationActionsInCompactView}</b> - Sets whether the navigation previous and
* next actions should are displayed in compact view (including the lock screen notification).
* <ul>
* <li>Corresponding setter: {@link #setUseNavigationActionsInCompactView(boolean)}
* <li>Default: {@code false}
* </ul>
* <li><b>{@code usePlayPauseActions}</b> - Sets whether the play and pause actions are displayed. * <li><b>{@code usePlayPauseActions}</b> - Sets whether the play and pause actions are displayed.
* <ul> * <ul>
* <li>Corresponding setter: {@link #setUsePlayPauseActions(boolean)} * <li>Corresponding setter: {@link #setUsePlayPauseActions(boolean)}
...@@ -362,6 +369,7 @@ public class PlayerNotificationManager { ...@@ -362,6 +369,7 @@ public class PlayerNotificationManager {
@Nullable private NotificationListener notificationListener; @Nullable private NotificationListener notificationListener;
@Nullable private MediaSessionCompat.Token mediaSessionToken; @Nullable private MediaSessionCompat.Token mediaSessionToken;
private boolean useNavigationActions; private boolean useNavigationActions;
private boolean useNavigationActionsInCompactView;
private boolean usePlayPauseActions; private boolean usePlayPauseActions;
private boolean useStopAction; private boolean useStopAction;
private long fastForwardMs; private long fastForwardMs;
...@@ -688,6 +696,23 @@ public class PlayerNotificationManager { ...@@ -688,6 +696,23 @@ public class PlayerNotificationManager {
} }
/** /**
* Sets whether navigation actions should be displayed in compact view.
*
* <p>If {@link #useNavigationActions} is set to {@code false} navigation actions are displayed
* neither in compact nor in full view mode of the notification.
*
* @param useNavigationActionsInCompactView Whether the navigation actions should be displayed in
* compact view.
*/
public final void setUseNavigationActionsInCompactView(
boolean useNavigationActionsInCompactView) {
if (this.useNavigationActionsInCompactView != useNavigationActionsInCompactView) {
this.useNavigationActionsInCompactView = useNavigationActionsInCompactView;
invalidate();
}
}
/**
* Sets whether the play and pause actions should be used. * Sets whether the play and pause actions should be used.
* *
* @param usePlayPauseActions Whether to use play and pause actions. * @param usePlayPauseActions Whether to use play and pause actions.
...@@ -1096,9 +1121,26 @@ public class PlayerNotificationManager { ...@@ -1096,9 +1121,26 @@ public class PlayerNotificationManager {
protected int[] getActionIndicesForCompactView(List<String> actionNames, Player player) { protected int[] getActionIndicesForCompactView(List<String> actionNames, Player player) {
int pauseActionIndex = actionNames.indexOf(ACTION_PAUSE); int pauseActionIndex = actionNames.indexOf(ACTION_PAUSE);
int playActionIndex = actionNames.indexOf(ACTION_PLAY); int playActionIndex = actionNames.indexOf(ACTION_PLAY);
return pauseActionIndex != -1 int skipPreviousActionIndex =
? new int[] {pauseActionIndex} useNavigationActionsInCompactView ? actionNames.indexOf(ACTION_PREVIOUS) : -1;
: (playActionIndex != -1 ? new int[] {playActionIndex} : new int[0]); int skipNextActionIndex =
useNavigationActionsInCompactView ? actionNames.indexOf(ACTION_NEXT) : -1;
int[] actionIndices = new int[3];
int actionCounter = 0;
if (skipPreviousActionIndex != -1) {
actionIndices[actionCounter++] = skipPreviousActionIndex;
}
boolean playWhenReady = player.getPlayWhenReady();
if (pauseActionIndex != -1 && playWhenReady) {
actionIndices[actionCounter++] = pauseActionIndex;
} else if (playActionIndex != -1 && !playWhenReady) {
actionIndices[actionCounter++] = playActionIndex;
}
if (skipNextActionIndex != -1) {
actionIndices[actionCounter++] = skipNextActionIndex;
}
return Arrays.copyOf(actionIndices, actionCounter);
} }
/** Returns whether the generated notification should be ongoing. */ /** Returns whether the generated notification should be ongoing. */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment