Support enabling next/previous actions in PlayerNotificationManager
The ref'd issue was marked as a doucmentation candidate, but I think the confusion likely arises from the lack of "next" and "previous" in the method names. Our other UI components also support enabling each button individually, so this also brings notifications in line with those. Issue: #6491 #exofixit PiperOrigin-RevId: 344058969
This commit is contained in:
parent
d605b6c766
commit
27d8bcf4cb
@ -26,6 +26,8 @@
|
|||||||
* Add `bar_gravity` attribute into `DefaultTimeBar`.
|
* Add `bar_gravity` attribute into `DefaultTimeBar`.
|
||||||
* Increase seekbar's touch target height in `StyledPlayerControlView`.
|
* Increase seekbar's touch target height in `StyledPlayerControlView`.
|
||||||
* Update Styled Player settings dialogs to respect RTL.
|
* Update Styled Player settings dialogs to respect RTL.
|
||||||
|
* Support enabling the previous and next actions individually in
|
||||||
|
`PlayerNotificationManager`.
|
||||||
* Audio:
|
* Audio:
|
||||||
* Retry playback after some types of `AudioTrack` error.
|
* Retry playback after some types of `AudioTrack` error.
|
||||||
* Work around `AudioManager` crashes when calling `getStreamVolume`
|
* Work around `AudioManager` crashes when calling `getStreamVolume`
|
||||||
|
@ -57,7 +57,7 @@ import java.util.Map;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Starts, updates and cancels a media style notification reflecting the player state. The actions
|
* 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.
|
||||||
*
|
*
|
||||||
* <p>The notification is cancelled when {@code null} is passed to {@link #setPlayer(Player)} or
|
* <p>The notification is cancelled when {@code null} is passed to {@link #setPlayer(Player)} or
|
||||||
* when the notification is dismissed by the user.
|
* when the notification is dismissed by the user.
|
||||||
@ -67,43 +67,55 @@ import java.util.Map;
|
|||||||
*
|
*
|
||||||
* <h3>Action customization</h3>
|
* <h3>Action customization</h3>
|
||||||
*
|
*
|
||||||
* Playback actions can be displayed or omitted as follows:
|
* Playback actions can be included or omitted as follows:
|
||||||
*
|
*
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li><b>{@code useNavigationActions}</b> - Sets whether the previous and next actions are
|
* <li><b>{@code usePlayPauseActions}</b> - Sets whether the play and pause actions are used.
|
||||||
* displayed.
|
|
||||||
* <ul>
|
|
||||||
* <li>Corresponding setter: {@link #setUseNavigationActions(boolean)}
|
|
||||||
* <li>Default: {@code true}
|
|
||||||
* </ul>
|
|
||||||
* <li><b>{@code useNavigationActionsInCompactView}</b> - Sets whether the previous and next
|
|
||||||
* actions 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.
|
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Corresponding setter: {@link #setUsePlayPauseActions(boolean)}
|
* <li>Corresponding setter: {@link #setUsePlayPauseActions(boolean)}
|
||||||
* <li>Default: {@code true}
|
* <li>Default: {@code true}
|
||||||
* </ul>
|
* </ul>
|
||||||
* <li><b>{@code useStopAction}</b> - Sets whether the stop action is displayed.
|
|
||||||
* <ul>
|
|
||||||
* <li>Corresponding setter: {@link #setUseStopAction(boolean)}
|
|
||||||
* <li>Default: {@code false}
|
|
||||||
* </ul>
|
|
||||||
* <li><b>{@code rewindIncrementMs}</b> - Sets the rewind increment. If set to zero the rewind
|
* <li><b>{@code rewindIncrementMs}</b> - Sets the rewind increment. If set to zero the rewind
|
||||||
* action is not displayed.
|
* action is not used.
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Corresponding setter: {@link #setControlDispatcher(ControlDispatcher)}
|
* <li>Corresponding setter: {@link #setControlDispatcher(ControlDispatcher)}
|
||||||
* <li>Default: {@link DefaultControlDispatcher#DEFAULT_REWIND_MS} (5000)
|
* <li>Default: {@link DefaultControlDispatcher#DEFAULT_REWIND_MS} (5000)
|
||||||
* </ul>
|
* </ul>
|
||||||
* <li><b>{@code fastForwardIncrementMs}</b> - Sets the fast forward increment. If set to zero the
|
* <li><b>{@code fastForwardIncrementMs}</b> - Sets the fast forward increment. If set to zero the
|
||||||
* fast forward action is not displayed.
|
* fast forward action is not used.
|
||||||
* <ul>
|
* <ul>
|
||||||
* <li>Corresponding setter: {@link #setControlDispatcher(ControlDispatcher)}
|
* <li>Corresponding setter: {@link #setControlDispatcher(ControlDispatcher)}
|
||||||
* <li>Default: {@link DefaultControlDispatcher#DEFAULT_FAST_FORWARD_MS} (15000)
|
* <li>Default: {@link DefaultControlDispatcher#DEFAULT_FAST_FORWARD_MS} (15000)
|
||||||
* </ul>
|
* </ul>
|
||||||
|
* <li><b>{@code usePreviousAction}</b> - Whether the previous action is used.
|
||||||
|
* <ul>
|
||||||
|
* <li>Corresponding setter: {@link #setUsePreviousAction(boolean)}
|
||||||
|
* <li>Default: {@code true}
|
||||||
|
* </ul>
|
||||||
|
* <li><b>{@code usePreviousActionInCompactView}</b> - If {@code usePreviousAction} is {@code
|
||||||
|
* true}, sets whether the previous action is also used in compact view (including the lock
|
||||||
|
* screen notification). Else does nothing.
|
||||||
|
* <ul>
|
||||||
|
* <li>Corresponding setter: {@link #setUsePreviousActionInCompactView(boolean)}
|
||||||
|
* <li>Default: {@code false}
|
||||||
|
* </ul>
|
||||||
|
* <li><b>{@code useNextAction}</b> - Whether the next action is used.
|
||||||
|
* <ul>
|
||||||
|
* <li>Corresponding setter: {@link #setUseNextAction(boolean)}
|
||||||
|
* <li>Default: {@code true}
|
||||||
|
* </ul>
|
||||||
|
* <li><b>{@code useNextActionInCompactView}</b> - If {@code useNextAction} is {@code true}, sets
|
||||||
|
* whether the next action is also used in compact view (including the lock screen
|
||||||
|
* notification). Else does nothing.
|
||||||
|
* <ul>
|
||||||
|
* <li>Corresponding setter: {@link #setUseNextActionInCompactView(boolean)}
|
||||||
|
* <li>Default: {@code false}
|
||||||
|
* </ul>
|
||||||
|
* <li><b>{@code useStopAction}</b> - Sets whether the stop action is used.
|
||||||
|
* <ul>
|
||||||
|
* <li>Corresponding setter: {@link #setUseStopAction(boolean)}
|
||||||
|
* <li>Default: {@code false}
|
||||||
|
* </ul>
|
||||||
* </ul>
|
* </ul>
|
||||||
*
|
*
|
||||||
* <h3>Overriding drawables</h3>
|
* <h3>Overriding drawables</h3>
|
||||||
@ -382,8 +394,10 @@ public class PlayerNotificationManager {
|
|||||||
private int currentNotificationTag;
|
private int currentNotificationTag;
|
||||||
@Nullable private NotificationListener notificationListener;
|
@Nullable private NotificationListener notificationListener;
|
||||||
@Nullable private MediaSessionCompat.Token mediaSessionToken;
|
@Nullable private MediaSessionCompat.Token mediaSessionToken;
|
||||||
private boolean useNavigationActions;
|
private boolean usePreviousAction;
|
||||||
private boolean useNavigationActionsInCompactView;
|
private boolean useNextAction;
|
||||||
|
private boolean usePreviousActionInCompactView;
|
||||||
|
private boolean useNextActionInCompactView;
|
||||||
private boolean usePlayPauseActions;
|
private boolean usePlayPauseActions;
|
||||||
private boolean useStopAction;
|
private boolean useStopAction;
|
||||||
private int badgeIconType;
|
private int badgeIconType;
|
||||||
@ -620,7 +634,8 @@ public class PlayerNotificationManager {
|
|||||||
playerListener = new PlayerListener();
|
playerListener = new PlayerListener();
|
||||||
notificationBroadcastReceiver = new NotificationBroadcastReceiver();
|
notificationBroadcastReceiver = new NotificationBroadcastReceiver();
|
||||||
intentFilter = new IntentFilter();
|
intentFilter = new IntentFilter();
|
||||||
useNavigationActions = true;
|
usePreviousAction = true;
|
||||||
|
useNextAction = true;
|
||||||
usePlayPauseActions = true;
|
usePlayPauseActions = true;
|
||||||
colorized = true;
|
colorized = true;
|
||||||
useChronometer = 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) {
|
public void setUseNextAction(boolean useNextAction) {
|
||||||
if (this.useNavigationActions != useNavigationActions) {
|
if (this.useNextAction != useNextAction) {
|
||||||
this.useNavigationActions = useNavigationActions;
|
this.useNextAction = useNextAction;
|
||||||
invalidate();
|
invalidate();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sets whether navigation actions should be displayed in compact view.
|
* Sets whether the previous action should be used.
|
||||||
*
|
*
|
||||||
* <p>If {@link #useNavigationActions} is set to {@code false} navigation actions are displayed
|
* @param usePreviousAction Whether to use the previous action.
|
||||||
* 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(
|
public void setUsePreviousAction(boolean usePreviousAction) {
|
||||||
boolean useNavigationActionsInCompactView) {
|
if (this.usePreviousAction != usePreviousAction) {
|
||||||
if (this.useNavigationActionsInCompactView != useNavigationActionsInCompactView) {
|
this.usePreviousAction = usePreviousAction;
|
||||||
this.useNavigationActionsInCompactView = useNavigationActionsInCompactView;
|
|
||||||
invalidate();
|
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.
|
* Sets whether the play and pause actions should be used.
|
||||||
*
|
*
|
||||||
@ -1160,7 +1226,7 @@ public class PlayerNotificationManager {
|
|||||||
}
|
}
|
||||||
|
|
||||||
List<String> stringActions = new ArrayList<>();
|
List<String> stringActions = new ArrayList<>();
|
||||||
if (useNavigationActions && enablePrevious) {
|
if (usePreviousAction && enablePrevious) {
|
||||||
stringActions.add(ACTION_PREVIOUS);
|
stringActions.add(ACTION_PREVIOUS);
|
||||||
}
|
}
|
||||||
if (enableRewind) {
|
if (enableRewind) {
|
||||||
@ -1176,7 +1242,7 @@ public class PlayerNotificationManager {
|
|||||||
if (enableFastForward) {
|
if (enableFastForward) {
|
||||||
stringActions.add(ACTION_FAST_FORWARD);
|
stringActions.add(ACTION_FAST_FORWARD);
|
||||||
}
|
}
|
||||||
if (useNavigationActions && enableNext) {
|
if (useNextAction && enableNext) {
|
||||||
stringActions.add(ACTION_NEXT);
|
stringActions.add(ACTION_NEXT);
|
||||||
}
|
}
|
||||||
if (customActionReceiver != null) {
|
if (customActionReceiver != null) {
|
||||||
@ -1201,15 +1267,14 @@ 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);
|
||||||
int skipPreviousActionIndex =
|
int previousActionIndex =
|
||||||
useNavigationActionsInCompactView ? actionNames.indexOf(ACTION_PREVIOUS) : -1;
|
usePreviousActionInCompactView ? actionNames.indexOf(ACTION_PREVIOUS) : -1;
|
||||||
int skipNextActionIndex =
|
int nextActionIndex = useNextActionInCompactView ? actionNames.indexOf(ACTION_NEXT) : -1;
|
||||||
useNavigationActionsInCompactView ? actionNames.indexOf(ACTION_NEXT) : -1;
|
|
||||||
|
|
||||||
int[] actionIndices = new int[3];
|
int[] actionIndices = new int[3];
|
||||||
int actionCounter = 0;
|
int actionCounter = 0;
|
||||||
if (skipPreviousActionIndex != -1) {
|
if (previousActionIndex != -1) {
|
||||||
actionIndices[actionCounter++] = skipPreviousActionIndex;
|
actionIndices[actionCounter++] = previousActionIndex;
|
||||||
}
|
}
|
||||||
boolean shouldShowPauseButton = shouldShowPauseButton(player);
|
boolean shouldShowPauseButton = shouldShowPauseButton(player);
|
||||||
if (pauseActionIndex != -1 && shouldShowPauseButton) {
|
if (pauseActionIndex != -1 && shouldShowPauseButton) {
|
||||||
@ -1217,8 +1282,8 @@ public class PlayerNotificationManager {
|
|||||||
} else if (playActionIndex != -1 && !shouldShowPauseButton) {
|
} else if (playActionIndex != -1 && !shouldShowPauseButton) {
|
||||||
actionIndices[actionCounter++] = playActionIndex;
|
actionIndices[actionCounter++] = playActionIndex;
|
||||||
}
|
}
|
||||||
if (skipNextActionIndex != -1) {
|
if (nextActionIndex != -1) {
|
||||||
actionIndices[actionCounter++] = skipNextActionIndex;
|
actionIndices[actionCounter++] = nextActionIndex;
|
||||||
}
|
}
|
||||||
return Arrays.copyOf(actionIndices, actionCounter);
|
return Arrays.copyOf(actionIndices, actionCounter);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user