diff --git a/RELEASENOTES.md b/RELEASENOTES.md index 449a04e4cc..23da916f8a 100644 --- a/RELEASENOTES.md +++ b/RELEASENOTES.md @@ -26,6 +26,8 @@ * Add `bar_gravity` attribute into `DefaultTimeBar`. * Increase seekbar's touch target height in `StyledPlayerControlView`. * Update Styled Player settings dialogs to respect RTL. + * Support enabling the previous and next actions individually in + `PlayerNotificationManager`. * Audio: * Retry playback after some types of `AudioTrack` error. * Work around `AudioManager` crashes when calling `getStreamVolume` diff --git a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java index b183fddbb6..18862c4103 100644 --- a/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java +++ b/library/ui/src/main/java/com/google/android/exoplayer2/ui/PlayerNotificationManager.java @@ -57,7 +57,7 @@ import java.util.Map; /** * Starts, updates and cancels a media style notification reflecting the player state. The actions - * displayed and the drawables used can both be customized, as described below. + * included in the notification can be customized along with their drawables, as described below. * *

The notification is cancelled when {@code null} is passed to {@link #setPlayer(Player)} or * when the notification is dismissed by the user. @@ -67,43 +67,55 @@ import java.util.Map; * *

Action customization

* - * Playback actions can be displayed or omitted as follows: + * Playback actions can be included or omitted as follows: * * * *

Overriding drawables

@@ -382,8 +394,10 @@ public class PlayerNotificationManager { private int currentNotificationTag; @Nullable private NotificationListener notificationListener; @Nullable private MediaSessionCompat.Token mediaSessionToken; - private boolean useNavigationActions; - private boolean useNavigationActionsInCompactView; + private boolean usePreviousAction; + private boolean useNextAction; + private boolean usePreviousActionInCompactView; + private boolean useNextActionInCompactView; private boolean usePlayPauseActions; private boolean useStopAction; private int badgeIconType; @@ -620,7 +634,8 @@ public class PlayerNotificationManager { playerListener = new PlayerListener(); notificationBroadcastReceiver = new NotificationBroadcastReceiver(); intentFilter = new IntentFilter(); - useNavigationActions = true; + usePreviousAction = true; + useNextAction = true; usePlayPauseActions = true; colorized = true; useChronometer = true; @@ -750,34 +765,85 @@ public class PlayerNotificationManager { } /** - * Sets whether the navigation actions should be used. + * Sets whether the next action should be used. * - * @param useNavigationActions Whether to use navigation actions or not. + * @param useNextAction Whether to use the next action. */ - public final void setUseNavigationActions(boolean useNavigationActions) { - if (this.useNavigationActions != useNavigationActions) { - this.useNavigationActions = useNavigationActions; + public void setUseNextAction(boolean useNextAction) { + if (this.useNextAction != useNextAction) { + this.useNextAction = useNextAction; invalidate(); } } /** - * Sets whether navigation actions should be displayed in compact view. + * Sets whether the previous action should be used. * - *

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. + * @param usePreviousAction Whether to use the previous action. */ - public final void setUseNavigationActionsInCompactView( - boolean useNavigationActionsInCompactView) { - if (this.useNavigationActionsInCompactView != useNavigationActionsInCompactView) { - this.useNavigationActionsInCompactView = useNavigationActionsInCompactView; + public void setUsePreviousAction(boolean usePreviousAction) { + if (this.usePreviousAction != usePreviousAction) { + this.usePreviousAction = usePreviousAction; invalidate(); } } + /** + * Sets whether the navigation actions should be used. + * + * @param useNavigationActions Whether to use navigation actions. + * @deprecated Use {@link #setUseNextAction(boolean)} and {@link #setUsePreviousAction(boolean)}. + */ + @Deprecated + public final void setUseNavigationActions(boolean useNavigationActions) { + setUseNextAction(useNavigationActions); + setUsePreviousAction(useNavigationActions); + } + + /** + * If {@link #setUseNextAction useNextAction} is {@code true}, sets whether the next action should + * also be used in compact view. Has no effect if {@link #setUseNextAction useNextAction} is + * {@code false}. + * + * @param useNextActionInCompactView Whether to use the next action in compact view. + */ + public void setUseNextActionInCompactView(boolean useNextActionInCompactView) { + if (this.useNextActionInCompactView != useNextActionInCompactView) { + this.useNextActionInCompactView = useNextActionInCompactView; + invalidate(); + } + } + + /** + * If {@link #setUsePreviousAction usePreviousAction} is {@code true}, sets whether the previous + * action should also be used in compact view. Has no effect if {@link #setUsePreviousAction + * usePreviousAction} is {@code false}. + * + * @param usePreviousActionInCompactView Whether to use the previous action in compact view. + */ + public void setUsePreviousActionInCompactView(boolean usePreviousActionInCompactView) { + if (this.usePreviousActionInCompactView != usePreviousActionInCompactView) { + this.usePreviousActionInCompactView = usePreviousActionInCompactView; + invalidate(); + } + } + + /** + * If {@link #setUseNavigationActions useNavigationActions} is {@code true}, sets whether + * navigation actions should also be used in compact view. Has no effect if {@link + * #setUseNavigationActions useNavigationActions} is {@code false}. + * + * @param useNavigationActionsInCompactView Whether to use navigation actions in compact view. + * @deprecated Use {@link #setUseNextActionInCompactView(boolean)} and {@link + * #setUsePreviousActionInCompactView(boolean)} instead. + */ + @Deprecated + public final void setUseNavigationActionsInCompactView( + boolean useNavigationActionsInCompactView) { + setUseNextActionInCompactView(useNavigationActionsInCompactView); + setUsePreviousActionInCompactView(useNavigationActionsInCompactView); + } + /** * Sets whether the play and pause actions should be used. * @@ -1160,7 +1226,7 @@ public class PlayerNotificationManager { } List stringActions = new ArrayList<>(); - if (useNavigationActions && enablePrevious) { + if (usePreviousAction && enablePrevious) { stringActions.add(ACTION_PREVIOUS); } if (enableRewind) { @@ -1176,7 +1242,7 @@ public class PlayerNotificationManager { if (enableFastForward) { stringActions.add(ACTION_FAST_FORWARD); } - if (useNavigationActions && enableNext) { + if (useNextAction && enableNext) { stringActions.add(ACTION_NEXT); } if (customActionReceiver != null) { @@ -1201,15 +1267,14 @@ public class PlayerNotificationManager { protected int[] getActionIndicesForCompactView(List actionNames, Player player) { int pauseActionIndex = actionNames.indexOf(ACTION_PAUSE); int playActionIndex = actionNames.indexOf(ACTION_PLAY); - int skipPreviousActionIndex = - useNavigationActionsInCompactView ? actionNames.indexOf(ACTION_PREVIOUS) : -1; - int skipNextActionIndex = - useNavigationActionsInCompactView ? actionNames.indexOf(ACTION_NEXT) : -1; + int previousActionIndex = + usePreviousActionInCompactView ? actionNames.indexOf(ACTION_PREVIOUS) : -1; + int nextActionIndex = useNextActionInCompactView ? actionNames.indexOf(ACTION_NEXT) : -1; int[] actionIndices = new int[3]; int actionCounter = 0; - if (skipPreviousActionIndex != -1) { - actionIndices[actionCounter++] = skipPreviousActionIndex; + if (previousActionIndex != -1) { + actionIndices[actionCounter++] = previousActionIndex; } boolean shouldShowPauseButton = shouldShowPauseButton(player); if (pauseActionIndex != -1 && shouldShowPauseButton) { @@ -1217,8 +1282,8 @@ public class PlayerNotificationManager { } else if (playActionIndex != -1 && !shouldShowPauseButton) { actionIndices[actionCounter++] = playActionIndex; } - if (skipNextActionIndex != -1) { - actionIndices[actionCounter++] = skipNextActionIndex; + if (nextActionIndex != -1) { + actionIndices[actionCounter++] = nextActionIndex; } return Arrays.copyOf(actionIndices, actionCounter); }