Remove setters for showing actions in Notification

PiperOrigin-RevId: 414441471
This commit is contained in:
jaewan 2021-12-06 15:51:11 +00:00 committed by Ian Baker
parent 5264da59b3
commit 6bceec3246

View File

@ -76,66 +76,6 @@ import java.util.Map;
* <p>If the player is released it must be removed from the manager by calling {@code * <p>If the player is released it must be removed from the manager by calling {@code
* setPlayer(null)}. * setPlayer(null)}.
* *
* <h2>Action customization</h2>
*
* Playback actions can be included or omitted as follows:
*
* <ul>
* <li><b>{@code usePlayPauseActions}</b> - Sets whether the play and pause actions are used.
* <ul>
* <li>Corresponding setter: {@link #setUsePlayPauseActions(boolean)}
* <li>Default: {@code true}
* </ul>
* <li><b>{@code useRewindAction}</b> - Sets whether the rewind action is used.
* <ul>
* <li>Corresponding setter: {@link #setUseRewindAction(boolean)}
* <li>Default: {@code true}
* </ul>
* <li><b>{@code useRewindActionInCompactView}</b> - If {@code useRewindAction} is {@code true},
* sets whether the rewind action is also used in compact view (including the lock screen
* notification). Else does nothing.
* <ul>
* <li>Corresponding setter: {@link #setUseRewindActionInCompactView(boolean)}
* <li>Default: {@code false}
* </ul>
* <li><b>{@code useFastForwardAction}</b> - Sets whether the fast forward action is used.
* <ul>
* <li>Corresponding setter: {@link #setUseFastForwardAction(boolean)}
* <li>Default: {@code true}
* </ul>
* <li><b>{@code useFastForwardActionInCompactView}</b> - If {@code useFastForwardAction} is
* {@code true}, sets whether the fast forward action is also used in compact view (including
* the lock screen notification). Else does nothing.
* <ul>
* <li>Corresponding setter: {@link #setUseFastForwardActionInCompactView(boolean)}
* <li>Default: {@code false}
* </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>
* </ul>
*
* <h2>Overriding drawables</h2> * <h2>Overriding drawables</h2>
* *
* The drawables used by PlayerNotificationManager can be overridden by drawables with the same * The drawables used by PlayerNotificationManager can be overridden by drawables with the same
@ -662,15 +602,6 @@ public class PlayerNotificationManager {
private boolean isNotificationStarted; private boolean isNotificationStarted;
private int currentNotificationTag; private int currentNotificationTag;
@Nullable private MediaSessionCompat.Token mediaSessionToken; @Nullable private MediaSessionCompat.Token mediaSessionToken;
private boolean usePreviousAction;
private boolean useNextAction;
private boolean usePreviousActionInCompactView;
private boolean useNextActionInCompactView;
private boolean useRewindAction;
private boolean useFastForwardAction;
private boolean useRewindActionInCompactView;
private boolean useFastForwardActionInCompactView;
private boolean usePlayPauseActions;
private int badgeIconType; private int badgeIconType;
private boolean colorized; private boolean colorized;
private int defaults; private int defaults;
@ -716,11 +647,6 @@ public class PlayerNotificationManager {
playerListener = new PlayerListener(); playerListener = new PlayerListener();
notificationBroadcastReceiver = new NotificationBroadcastReceiver(); notificationBroadcastReceiver = new NotificationBroadcastReceiver();
intentFilter = new IntentFilter(); intentFilter = new IntentFilter();
usePreviousAction = true;
useNextAction = true;
usePlayPauseActions = true;
useRewindAction = true;
useFastForwardAction = true;
colorized = true; colorized = true;
useChronometer = true; useChronometer = true;
color = Color.TRANSPARENT; color = Color.TRANSPARENT;
@ -787,146 +713,6 @@ public class PlayerNotificationManager {
} }
} }
/**
* Sets whether the next action should be used.
*
* @param useNextAction Whether to use the next action.
*/
public final void setUseNextAction(boolean useNextAction) {
if (this.useNextAction != useNextAction) {
this.useNextAction = useNextAction;
invalidate();
}
}
/**
* Sets whether the previous action should be used.
*
* @param usePreviousAction Whether to use the previous action.
*/
public final void setUsePreviousAction(boolean usePreviousAction) {
if (this.usePreviousAction != usePreviousAction) {
this.usePreviousAction = usePreviousAction;
invalidate();
}
}
/**
* 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}.
*
* <p>If set to {@code true}, {@link #setUseFastForwardActionInCompactView(boolean)
* setUseFastForwardActionInCompactView} is set to false.
*
* @param useNextActionInCompactView Whether to use the next action in compact view.
*/
public final void setUseNextActionInCompactView(boolean useNextActionInCompactView) {
if (this.useNextActionInCompactView != useNextActionInCompactView) {
this.useNextActionInCompactView = useNextActionInCompactView;
if (useNextActionInCompactView) {
useFastForwardActionInCompactView = false;
}
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}.
*
* <p>If set to {@code true}, {@link #setUseRewindActionInCompactView(boolean)
* setUseRewindActionInCompactView} is set to false.
*
* @param usePreviousActionInCompactView Whether to use the previous action in compact view.
*/
public final void setUsePreviousActionInCompactView(boolean usePreviousActionInCompactView) {
if (this.usePreviousActionInCompactView != usePreviousActionInCompactView) {
this.usePreviousActionInCompactView = usePreviousActionInCompactView;
if (usePreviousActionInCompactView) {
useRewindActionInCompactView = false;
}
invalidate();
}
}
/**
* Sets whether the fast forward action should be used.
*
* @param useFastForwardAction Whether to use the fast forward action.
*/
public final void setUseFastForwardAction(boolean useFastForwardAction) {
if (this.useFastForwardAction != useFastForwardAction) {
this.useFastForwardAction = useFastForwardAction;
invalidate();
}
}
/**
* Sets whether the rewind action should be used.
*
* @param useRewindAction Whether to use the rewind action.
*/
public final void setUseRewindAction(boolean useRewindAction) {
if (this.useRewindAction != useRewindAction) {
this.useRewindAction = useRewindAction;
invalidate();
}
}
/**
* Sets whether the fast forward action should also be used in compact view. Has no effect if
* {@link #ACTION_FAST_FORWARD} is not enabled, for instance if the media is not seekable.
*
* <p>If set to {@code true}, {@link #setUseNextActionInCompactView(boolean)
* setUseNextActionInCompactView} is set to false.
*
* @param useFastForwardActionInCompactView Whether to use the fast forward action in compact
* view.
*/
public final void setUseFastForwardActionInCompactView(
boolean useFastForwardActionInCompactView) {
if (this.useFastForwardActionInCompactView != useFastForwardActionInCompactView) {
this.useFastForwardActionInCompactView = useFastForwardActionInCompactView;
if (useFastForwardActionInCompactView) {
useNextActionInCompactView = false;
}
invalidate();
}
}
/**
* Sets whether the rewind action should also be used in compact view. Has no effect if {@link
* #ACTION_REWIND} is not enabled, for instance if the media is not seekable.
*
* <p>If set to {@code true}, {@link #setUsePreviousActionInCompactView(boolean)
* setUsePreviousActionInCompactView} is set to false.
*
* @param useRewindActionInCompactView Whether to use the rewind action in compact view.
*/
public final void setUseRewindActionInCompactView(boolean useRewindActionInCompactView) {
if (this.useRewindActionInCompactView != useRewindActionInCompactView) {
this.useRewindActionInCompactView = useRewindActionInCompactView;
if (useRewindActionInCompactView) {
usePreviousActionInCompactView = false;
}
invalidate();
}
}
/**
* Sets whether the play and pause actions should be used.
*
* @param usePlayPauseActions Whether to use play and pause actions.
*/
public final void setUsePlayPauseActions(boolean usePlayPauseActions) {
if (this.usePlayPauseActions != usePlayPauseActions) {
this.usePlayPauseActions = usePlayPauseActions;
invalidate();
}
}
/** /**
* Sets the {@link MediaSessionCompat.Token}. * Sets the {@link MediaSessionCompat.Token}.
* *
@ -1272,28 +1058,23 @@ public class PlayerNotificationManager {
boolean enableNext = player.isCommandAvailable(COMMAND_SEEK_TO_NEXT); boolean enableNext = player.isCommandAvailable(COMMAND_SEEK_TO_NEXT);
List<String> stringActions = new ArrayList<>(); List<String> stringActions = new ArrayList<>();
if (usePreviousAction && enablePrevious) { if (enablePrevious) {
stringActions.add(ACTION_PREVIOUS); stringActions.add(ACTION_PREVIOUS);
} }
if (useRewindAction && enableRewind) { if (enableRewind) {
stringActions.add(ACTION_REWIND); stringActions.add(ACTION_REWIND);
} }
if (usePlayPauseActions) {
if (shouldShowPauseButton(player)) { if (shouldShowPauseButton(player)) {
stringActions.add(ACTION_PAUSE); stringActions.add(ACTION_PAUSE);
} else { } else {
stringActions.add(ACTION_PLAY); stringActions.add(ACTION_PLAY);
} }
} if (enableFastForward) {
if (useFastForwardAction && enableFastForward) {
stringActions.add(ACTION_FAST_FORWARD); stringActions.add(ACTION_FAST_FORWARD);
} }
if (useNextAction && enableNext) { if (enableNext) {
stringActions.add(ACTION_NEXT); stringActions.add(ACTION_NEXT);
} }
if (customActionReceiver != null) {
stringActions.addAll(customActionReceiver.getCustomActions(player));
}
return stringActions; return stringActions;
} }
@ -1310,14 +1091,8 @@ 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 leftSideActionIndex = int leftSideActionIndex = actionNames.indexOf(ACTION_PREVIOUS);
usePreviousActionInCompactView int rightSideActionIndex = actionNames.indexOf(ACTION_NEXT);
? actionNames.indexOf(ACTION_PREVIOUS)
: (useRewindActionInCompactView ? actionNames.indexOf(ACTION_REWIND) : -1);
int rightSideActionIndex =
useNextActionInCompactView
? actionNames.indexOf(ACTION_NEXT)
: (useFastForwardActionInCompactView ? actionNames.indexOf(ACTION_FAST_FORWARD) : -1);
int[] actionIndices = new int[3]; int[] actionIndices = new int[3];
int actionCounter = 0; int actionCounter = 0;