mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00
Make getCustomLayoutFromMediaButtonPreferences side-effect free
The method currently modifies the input Bundle, but it's easier to reason about it if the method is side-effect free and the places that need to modify a Bundle do this after calling the method. PiperOrigin-RevId: 693288031
This commit is contained in:
parent
76e4abe428
commit
9fb4ed91b6
@ -1179,17 +1179,17 @@ public final class CommandButton {
|
|||||||
* custom layout} according to the implicit button placement rules applied for custom layouts.
|
* custom layout} according to the implicit button placement rules applied for custom layouts.
|
||||||
*
|
*
|
||||||
* @param mediaButtonPreferences The list of buttons as media button preferences.
|
* @param mediaButtonPreferences The list of buttons as media button preferences.
|
||||||
* @param reservationExtras A writable {@link Bundle} that receives the extras for slot
|
* @param backSlotAllowed Whether the custom layout can put a button into {@link #SLOT_BACK}.
|
||||||
* reservations via {@link MediaConstants#EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT} or {@link
|
* @param forwardSlotAllowed Whether the custom layout can put a button into {@link
|
||||||
* MediaConstants#EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV} to match the returned custom
|
* #SLOT_FORWARD}.
|
||||||
* layout.
|
* @return A list of buttons compatible with the placement rules of custom layouts. The buttons
|
||||||
* @return A list of buttons compatible with the placement rules of custom layouts.
|
* will have their intended slots assigned as the only option.
|
||||||
*/
|
*/
|
||||||
/* package */ static ImmutableList<CommandButton> getCustomLayoutFromMediaButtonPreferences(
|
/* package */ static ImmutableList<CommandButton> getCustomLayoutFromMediaButtonPreferences(
|
||||||
List<CommandButton> mediaButtonPreferences, Bundle reservationExtras) {
|
List<CommandButton> mediaButtonPreferences,
|
||||||
|
boolean backSlotAllowed,
|
||||||
|
boolean forwardSlotAllowed) {
|
||||||
if (mediaButtonPreferences.isEmpty()) {
|
if (mediaButtonPreferences.isEmpty()) {
|
||||||
reservationExtras.putBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV, true);
|
|
||||||
reservationExtras.putBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT, true);
|
|
||||||
return ImmutableList.of();
|
return ImmutableList.of();
|
||||||
}
|
}
|
||||||
int backButtonIndex = C.INDEX_UNSET;
|
int backButtonIndex = C.INDEX_UNSET;
|
||||||
@ -1201,35 +1201,52 @@ public final class CommandButton {
|
|||||||
if (slot == SLOT_OVERFLOW) {
|
if (slot == SLOT_OVERFLOW) {
|
||||||
// Will go into overflow.
|
// Will go into overflow.
|
||||||
break;
|
break;
|
||||||
} else if (backButtonIndex == C.INDEX_UNSET && slot == SLOT_BACK) {
|
} else if (backSlotAllowed && backButtonIndex == C.INDEX_UNSET && slot == SLOT_BACK) {
|
||||||
backButtonIndex = i;
|
backButtonIndex = i;
|
||||||
} else if (forwardButtonIndex == C.INDEX_UNSET && slot == SLOT_FORWARD) {
|
break;
|
||||||
|
} else if (forwardSlotAllowed
|
||||||
|
&& forwardButtonIndex == C.INDEX_UNSET
|
||||||
|
&& slot == SLOT_FORWARD) {
|
||||||
forwardButtonIndex = i;
|
forwardButtonIndex = i;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
boolean hasBackButton = backButtonIndex != C.INDEX_UNSET;
|
|
||||||
boolean hasForwardButton = forwardButtonIndex != C.INDEX_UNSET;
|
|
||||||
reservationExtras.putBoolean(
|
|
||||||
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV, !hasBackButton);
|
|
||||||
reservationExtras.putBoolean(
|
|
||||||
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT, !hasForwardButton);
|
|
||||||
ImmutableList.Builder<CommandButton> customLayout = ImmutableList.builder();
|
ImmutableList.Builder<CommandButton> customLayout = ImmutableList.builder();
|
||||||
if (hasBackButton) {
|
if (backButtonIndex != C.INDEX_UNSET) {
|
||||||
customLayout.add(mediaButtonPreferences.get(backButtonIndex));
|
customLayout.add(
|
||||||
|
mediaButtonPreferences
|
||||||
|
.get(backButtonIndex)
|
||||||
|
.copyWithSlots(ImmutableIntArray.of(SLOT_BACK)));
|
||||||
}
|
}
|
||||||
if (hasForwardButton) {
|
if (forwardButtonIndex != C.INDEX_UNSET) {
|
||||||
customLayout.add(mediaButtonPreferences.get(forwardButtonIndex));
|
customLayout.add(
|
||||||
|
mediaButtonPreferences
|
||||||
|
.get(forwardButtonIndex)
|
||||||
|
.copyWithSlots(ImmutableIntArray.of(SLOT_FORWARD)));
|
||||||
}
|
}
|
||||||
for (int i = 0; i < mediaButtonPreferences.size(); i++) {
|
for (int i = 0; i < mediaButtonPreferences.size(); i++) {
|
||||||
CommandButton button = mediaButtonPreferences.get(i);
|
CommandButton button = mediaButtonPreferences.get(i);
|
||||||
if (i != backButtonIndex && i != forwardButtonIndex && button.slots.contains(SLOT_OVERFLOW)) {
|
if (i != backButtonIndex && i != forwardButtonIndex && button.slots.contains(SLOT_OVERFLOW)) {
|
||||||
customLayout.add(button);
|
customLayout.add(button.copyWithSlots(ImmutableIntArray.of(SLOT_OVERFLOW)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return customLayout.build();
|
return customLayout.build();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns whether the provided list of buttons contains a button for a given {@link Slot}. This
|
||||||
|
* method assumes the slots have been resolved and there is only a single slot per button.
|
||||||
|
*/
|
||||||
|
/* package */ static boolean containsButtonForSlot(List<CommandButton> buttons, @Slot int slot) {
|
||||||
|
for (int i = 0; i < buttons.size(); i++) {
|
||||||
|
if (buttons.get(i).slots.get(0) == slot) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts a list of buttons defined according to the implicit button placement rules for
|
* Converts a list of buttons defined according to the implicit button placement rules for
|
||||||
* {@linkplain MediaSession#getCustomLayout custom layouts} to {@linkplain
|
* {@linkplain MediaSession#getCustomLayout custom layouts} to {@linkplain
|
||||||
|
@ -131,10 +131,13 @@ import java.util.List;
|
|||||||
mediaButtonPreferences, CommandButton::toBundle));
|
mediaButtonPreferences, CommandButton::toBundle));
|
||||||
} else {
|
} else {
|
||||||
// Controller doesn't support media button preferences, send the list as a custom layout.
|
// Controller doesn't support media button preferences, send the list as a custom layout.
|
||||||
// Ignore reservation extras as they were not directly supported in older controllers.
|
// TODO: b/332877990 - Improve this logic to take allowed command and session extras for
|
||||||
|
// this controller into account instead of assuming all slots are allowed.
|
||||||
ImmutableList<CommandButton> customLayout =
|
ImmutableList<CommandButton> customLayout =
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
mediaButtonPreferences, /* reservationExtras= */ new Bundle());
|
mediaButtonPreferences,
|
||||||
|
/* backSlotAllowed= */ true,
|
||||||
|
/* forwardSlotAllowed= */ true);
|
||||||
bundle.putParcelableArrayList(
|
bundle.putParcelableArrayList(
|
||||||
FIELD_CUSTOM_LAYOUT,
|
FIELD_CUSTOM_LAYOUT,
|
||||||
BundleCollectionUtil.toBundleArrayList(customLayout, CommandButton::toBundle));
|
BundleCollectionUtil.toBundleArrayList(customLayout, CommandButton::toBundle));
|
||||||
|
@ -445,14 +445,13 @@ public class DefaultMediaNotificationProvider implements MediaNotification.Provi
|
|||||||
Player.Commands playerCommands,
|
Player.Commands playerCommands,
|
||||||
ImmutableList<CommandButton> mediaButtonPreferences,
|
ImmutableList<CommandButton> mediaButtonPreferences,
|
||||||
boolean showPauseButton) {
|
boolean showPauseButton) {
|
||||||
Bundle reservations = new Bundle();
|
|
||||||
ImmutableList<CommandButton> customLayout =
|
ImmutableList<CommandButton> customLayout =
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
mediaButtonPreferences, reservations);
|
mediaButtonPreferences, /* backSlotAllowed= */ true, /* forwardSlotAllowed= */ true);
|
||||||
boolean hasCustomBackButton =
|
boolean hasCustomBackButton =
|
||||||
!reservations.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV);
|
CommandButton.containsButtonForSlot(customLayout, CommandButton.SLOT_BACK);
|
||||||
boolean hasCustomForwardButton =
|
boolean hasCustomForwardButton =
|
||||||
!reservations.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT);
|
CommandButton.containsButtonForSlot(customLayout, CommandButton.SLOT_FORWARD);
|
||||||
int nextCustomLayoutIndex = 0;
|
int nextCustomLayoutIndex = 0;
|
||||||
|
|
||||||
ImmutableList.Builder<CommandButton> commandButtons = new ImmutableList.Builder<>();
|
ImmutableList.Builder<CommandButton> commandButtons = new ImmutableList.Builder<>();
|
||||||
|
@ -2085,10 +2085,13 @@ import java.util.concurrent.ExecutionException;
|
|||||||
BundleCollectionUtil.toBundleList(mediaButtonPreferences, CommandButton::toBundle));
|
BundleCollectionUtil.toBundleList(mediaButtonPreferences, CommandButton::toBundle));
|
||||||
} else {
|
} else {
|
||||||
// Controller doesn't support media button preferences, send the list as a custom layout.
|
// Controller doesn't support media button preferences, send the list as a custom layout.
|
||||||
// Ignore reservation extras as they were not directly supported in older controllers.
|
// TODO: b/332877990 - Improve this logic to take allowed command and session extras for
|
||||||
|
// this controller into account instead of assuming all slots are allowed.
|
||||||
ImmutableList<CommandButton> customLayout =
|
ImmutableList<CommandButton> customLayout =
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
mediaButtonPreferences, /* reservationExtras= */ new Bundle());
|
mediaButtonPreferences,
|
||||||
|
/* backSlotAllowed= */ true,
|
||||||
|
/* forwardSlotAllowed= */ true);
|
||||||
iController.onSetCustomLayout(
|
iController.onSetCustomLayout(
|
||||||
sequenceNumber,
|
sequenceNumber,
|
||||||
BundleCollectionUtil.toBundleList(customLayout, CommandButton::toBundle));
|
BundleCollectionUtil.toBundleList(customLayout, CommandButton::toBundle));
|
||||||
|
@ -107,9 +107,7 @@ import java.util.List;
|
|||||||
this.availablePlayerCommands = availablePlayerCommands;
|
this.availablePlayerCommands = availablePlayerCommands;
|
||||||
this.legacyExtras = legacyExtras;
|
this.legacyExtras = legacyExtras;
|
||||||
if (!mediaButtonPreferences.isEmpty()) {
|
if (!mediaButtonPreferences.isEmpty()) {
|
||||||
this.customLayout =
|
updateCustomLayoutAndLegacyExtrasForMediaButtonPreferences();
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
|
||||||
mediaButtonPreferences, this.legacyExtras);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -143,18 +141,16 @@ import java.util.List;
|
|||||||
this.mediaButtonPreferences = mediaButtonPreferences;
|
this.mediaButtonPreferences = mediaButtonPreferences;
|
||||||
boolean hadPrevReservation =
|
boolean hadPrevReservation =
|
||||||
legacyExtras.getBoolean(
|
legacyExtras.getBoolean(
|
||||||
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV, /* defaultVale= */ false);
|
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV, /* defaultValue= */ false);
|
||||||
boolean hadNextReservation =
|
boolean hadNextReservation =
|
||||||
legacyExtras.getBoolean(
|
legacyExtras.getBoolean(
|
||||||
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT, /* defaultVale= */ false);
|
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT, /* defaultValue= */ false);
|
||||||
this.customLayout =
|
updateCustomLayoutAndLegacyExtrasForMediaButtonPreferences();
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
|
||||||
mediaButtonPreferences, legacyExtras);
|
|
||||||
return (legacyExtras.getBoolean(
|
return (legacyExtras.getBoolean(
|
||||||
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV, /* defaultVale= */ false)
|
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV, /* defaultValue= */ false)
|
||||||
!= hadPrevReservation)
|
!= hadPrevReservation)
|
||||||
|| (legacyExtras.getBoolean(
|
|| (legacyExtras.getBoolean(
|
||||||
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT, /* defaultVale= */ false)
|
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT, /* defaultValue= */ false)
|
||||||
!= hadNextReservation);
|
!= hadNextReservation);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,12 +165,11 @@ import java.util.List;
|
|||||||
public void setLegacyExtras(Bundle extras) {
|
public void setLegacyExtras(Bundle extras) {
|
||||||
checkArgument(!extras.containsKey(EXTRAS_KEY_PLAYBACK_SPEED_COMPAT));
|
checkArgument(!extras.containsKey(EXTRAS_KEY_PLAYBACK_SPEED_COMPAT));
|
||||||
checkArgument(!extras.containsKey(EXTRAS_KEY_MEDIA_ID_COMPAT));
|
checkArgument(!extras.containsKey(EXTRAS_KEY_MEDIA_ID_COMPAT));
|
||||||
|
this.legacyExtras = extras;
|
||||||
if (!mediaButtonPreferences.isEmpty()) {
|
if (!mediaButtonPreferences.isEmpty()) {
|
||||||
// Re-calculate custom layout in case we have to set any additional extras.
|
// Re-calculate custom layout in case we have to set any additional extras.
|
||||||
this.customLayout =
|
updateCustomLayoutAndLegacyExtrasForMediaButtonPreferences();
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(mediaButtonPreferences, extras);
|
|
||||||
}
|
}
|
||||||
this.legacyExtras = extras;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public Bundle getLegacyExtras() {
|
public Bundle getLegacyExtras() {
|
||||||
@ -1309,6 +1304,18 @@ import java.util.List;
|
|||||||
checkState(Looper.myLooper() == getApplicationLooper());
|
checkState(Looper.myLooper() == getApplicationLooper());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void updateCustomLayoutAndLegacyExtrasForMediaButtonPreferences() {
|
||||||
|
customLayout =
|
||||||
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
|
mediaButtonPreferences, /* backSlotAllowed= */ true, /* forwardSlotAllowed= */ true);
|
||||||
|
legacyExtras.putBoolean(
|
||||||
|
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV,
|
||||||
|
!CommandButton.containsButtonForSlot(customLayout, CommandButton.SLOT_BACK));
|
||||||
|
legacyExtras.putBoolean(
|
||||||
|
MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT,
|
||||||
|
!CommandButton.containsButtonForSlot(customLayout, CommandButton.SLOT_FORWARD));
|
||||||
|
}
|
||||||
|
|
||||||
@SuppressWarnings("deprecation") // Uses deprecated PlaybackStateCompat actions.
|
@SuppressWarnings("deprecation") // Uses deprecated PlaybackStateCompat actions.
|
||||||
private static long convertCommandToPlaybackStateActions(@Command int command) {
|
private static long convertCommandToPlaybackStateActions(@Command int command) {
|
||||||
switch (command) {
|
switch (command) {
|
||||||
|
@ -560,29 +560,22 @@ public class CommandButtonTest {
|
|||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
||||||
.build());
|
.build());
|
||||||
Bundle reservationBundle = new Bundle();
|
|
||||||
|
|
||||||
ImmutableList<CommandButton> customLayout =
|
ImmutableList<CommandButton> customLayout =
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
mediaButtonPreferences, reservationBundle);
|
mediaButtonPreferences, /* backSlotAllowed= */ true, /* forwardSlotAllowed= */ true);
|
||||||
|
|
||||||
assertThat(customLayout)
|
assertThat(customLayout)
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
.setPlayerCommand(Player.COMMAND_PREPARE)
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
.setSlots(CommandButton.SLOT_OVERFLOW, CommandButton.SLOT_BACK)
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
.build(),
|
.build(),
|
||||||
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
.build())
|
.build())
|
||||||
.inOrder();
|
.inOrder();
|
||||||
assertThat(
|
|
||||||
reservationBundle.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV))
|
|
||||||
.isTrue();
|
|
||||||
assertThat(
|
|
||||||
reservationBundle.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT))
|
|
||||||
.isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -605,33 +598,69 @@ public class CommandButtonTest {
|
|||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
||||||
.build());
|
.build());
|
||||||
Bundle reservationBundle = new Bundle();
|
|
||||||
|
|
||||||
ImmutableList<CommandButton> customLayout =
|
ImmutableList<CommandButton> customLayout =
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
mediaButtonPreferences, reservationBundle);
|
mediaButtonPreferences, /* backSlotAllowed= */ true, /* forwardSlotAllowed= */ true);
|
||||||
|
|
||||||
assertThat(customLayout)
|
assertThat(customLayout)
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
new CommandButton.Builder(CommandButton.ICON_PREVIOUS)
|
new CommandButton.Builder(CommandButton.ICON_PREVIOUS)
|
||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_BACK, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_BACK)
|
||||||
.build(),
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build())
|
||||||
|
.inOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void
|
||||||
|
getCustomLayoutFromMediaButtonPreferences_withBackSlotButNoBackSlotAllowed_returnsCorrectButtons() {
|
||||||
|
ImmutableList<CommandButton> mediaButtonPreferences =
|
||||||
|
ImmutableList.of(
|
||||||
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
.setPlayerCommand(Player.COMMAND_PREPARE)
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
.setSlots(CommandButton.SLOT_OVERFLOW, CommandButton.SLOT_BACK)
|
.setSlots(CommandButton.SLOT_OVERFLOW, CommandButton.SLOT_BACK)
|
||||||
.build(),
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_PREVIOUS)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_BACK, CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
|
.setSlots(CommandButton.SLOT_FORWARD_SECONDARY)
|
||||||
|
.build(),
|
||||||
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
ImmutableList<CommandButton> customLayout =
|
||||||
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
|
mediaButtonPreferences, /* backSlotAllowed= */ false, /* forwardSlotAllowed= */ true);
|
||||||
|
|
||||||
|
assertThat(customLayout)
|
||||||
|
.containsExactly(
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_PREVIOUS)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
.build())
|
.build())
|
||||||
.inOrder();
|
.inOrder();
|
||||||
assertThat(
|
|
||||||
reservationBundle.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV))
|
|
||||||
.isFalse();
|
|
||||||
assertThat(
|
|
||||||
reservationBundle.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT))
|
|
||||||
.isTrue();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -654,33 +683,69 @@ public class CommandButtonTest {
|
|||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
||||||
.build());
|
.build());
|
||||||
Bundle reservationBundle = new Bundle();
|
|
||||||
|
|
||||||
ImmutableList<CommandButton> customLayout =
|
ImmutableList<CommandButton> customLayout =
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
mediaButtonPreferences, reservationBundle);
|
mediaButtonPreferences, /* backSlotAllowed= */ true, /* forwardSlotAllowed= */ true);
|
||||||
|
|
||||||
assertThat(customLayout)
|
assertThat(customLayout)
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
.setSlots(CommandButton.SLOT_FORWARD, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_FORWARD)
|
||||||
.build(),
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build())
|
||||||
|
.inOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void
|
||||||
|
getCustomLayoutFromMediaButtonPreferences_withForwardSlotButNoForwardSlotAllowed_returnsCorrectButtons() {
|
||||||
|
ImmutableList<CommandButton> mediaButtonPreferences =
|
||||||
|
ImmutableList.of(
|
||||||
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
.setPlayerCommand(Player.COMMAND_PREPARE)
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
.setSlots(CommandButton.SLOT_OVERFLOW, CommandButton.SLOT_FORWARD)
|
.setSlots(CommandButton.SLOT_OVERFLOW, CommandButton.SLOT_FORWARD)
|
||||||
.build(),
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
|
.setSlots(CommandButton.SLOT_FORWARD, CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
|
.setSlots(CommandButton.SLOT_FORWARD_SECONDARY)
|
||||||
|
.build(),
|
||||||
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
ImmutableList<CommandButton> customLayout =
|
||||||
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
|
mediaButtonPreferences, /* backSlotAllowed= */ true, /* forwardSlotAllowed= */ false);
|
||||||
|
|
||||||
|
assertThat(customLayout)
|
||||||
|
.containsExactly(
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
.build())
|
.build())
|
||||||
.inOrder();
|
.inOrder();
|
||||||
assertThat(
|
|
||||||
reservationBundle.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV))
|
|
||||||
.isTrue();
|
|
||||||
assertThat(
|
|
||||||
reservationBundle.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT))
|
|
||||||
.isFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -708,37 +773,77 @@ public class CommandButtonTest {
|
|||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_CENTRAL, CommandButton.SLOT_BACK)
|
.setSlots(CommandButton.SLOT_CENTRAL, CommandButton.SLOT_BACK)
|
||||||
.build());
|
.build());
|
||||||
Bundle reservationBundle = new Bundle();
|
|
||||||
|
|
||||||
ImmutableList<CommandButton> customLayout =
|
ImmutableList<CommandButton> customLayout =
|
||||||
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
mediaButtonPreferences, reservationBundle);
|
mediaButtonPreferences, /* backSlotAllowed= */ true, /* forwardSlotAllowed= */ true);
|
||||||
|
|
||||||
assertThat(customLayout)
|
assertThat(customLayout)
|
||||||
.containsExactly(
|
.containsExactly(
|
||||||
new CommandButton.Builder(CommandButton.ICON_PREVIOUS)
|
new CommandButton.Builder(CommandButton.ICON_PREVIOUS)
|
||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_CENTRAL, CommandButton.SLOT_BACK)
|
.setSlots(CommandButton.SLOT_BACK)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
|
.setSlots(CommandButton.SLOT_FORWARD)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build())
|
||||||
|
.inOrder();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void
|
||||||
|
getCustomLayoutFromMediaButtonPreferences_withForwardAndBackSlotButNoForwardBackSlotsAllowed_returnsCorrectButtons() {
|
||||||
|
ImmutableList<CommandButton> mediaButtonPreferences =
|
||||||
|
ImmutableList.of(
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW, CommandButton.SLOT_FORWARD)
|
||||||
.build(),
|
.build(),
|
||||||
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
.setSlots(CommandButton.SLOT_FORWARD, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_FORWARD, CommandButton.SLOT_OVERFLOW)
|
||||||
.build(),
|
.build(),
|
||||||
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
.setPlayerCommand(Player.COMMAND_PREPARE)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
.setSlots(CommandButton.SLOT_OVERFLOW, CommandButton.SLOT_FORWARD)
|
.setSlots(CommandButton.SLOT_FORWARD_SECONDARY)
|
||||||
.build(),
|
.build(),
|
||||||
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
.setSlots(CommandButton.SLOT_BACK_SECONDARY, CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_PREVIOUS)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_CENTRAL, CommandButton.SLOT_BACK)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
ImmutableList<CommandButton> customLayout =
|
||||||
|
CommandButton.getCustomLayoutFromMediaButtonPreferences(
|
||||||
|
mediaButtonPreferences, /* backSlotAllowed= */ false, /* forwardSlotAllowed= */ false);
|
||||||
|
|
||||||
|
assertThat(customLayout)
|
||||||
|
.containsExactly(
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_ALBUM)
|
||||||
|
.setPlayerCommand(Player.COMMAND_PREPARE)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_NEXT)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
|
.build(),
|
||||||
|
new CommandButton.Builder(CommandButton.ICON_REWIND)
|
||||||
|
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||||
|
.setSlots(CommandButton.SLOT_OVERFLOW)
|
||||||
.build())
|
.build())
|
||||||
.inOrder();
|
.inOrder();
|
||||||
assertThat(
|
|
||||||
reservationBundle.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_PREV))
|
|
||||||
.isFalse();
|
|
||||||
assertThat(
|
|
||||||
reservationBundle.getBoolean(MediaConstants.EXTRAS_KEY_SLOT_RESERVATION_SEEK_TO_NEXT))
|
|
||||||
.isFalse();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
Loading…
x
Reference in New Issue
Block a user