Add iconUri to CommandButton
PiperOrigin-RevId: 578916804
This commit is contained in:
parent
901f89c456
commit
21a9bfe440
@ -19,6 +19,7 @@ import static androidx.media3.common.util.Assertions.checkArgument;
|
||||
import static androidx.media3.common.util.Assertions.checkNotNull;
|
||||
import static androidx.media3.common.util.Assertions.checkState;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import android.text.TextUtils;
|
||||
import androidx.annotation.DrawableRes;
|
||||
@ -48,6 +49,7 @@ public final class CommandButton implements Bundleable {
|
||||
@Nullable private SessionCommand sessionCommand;
|
||||
private @Player.Command int playerCommand;
|
||||
@DrawableRes private int iconResId;
|
||||
@Nullable private Uri iconUri;
|
||||
private CharSequence displayName;
|
||||
private Bundle extras;
|
||||
private boolean enabled;
|
||||
@ -111,6 +113,19 @@ public final class CommandButton implements Bundleable {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a {@link Uri} for the icon of this button.
|
||||
*
|
||||
* @param uri The uri to an icon.
|
||||
* @return This builder for chaining.
|
||||
*/
|
||||
@UnstableApi
|
||||
@CanIgnoreReturnValue
|
||||
public Builder setIconUri(Uri uri) {
|
||||
this.iconUri = uri;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets a display name of this button.
|
||||
*
|
||||
@ -153,7 +168,7 @@ public final class CommandButton implements Bundleable {
|
||||
(sessionCommand == null) != (playerCommand == Player.COMMAND_INVALID),
|
||||
"Exactly one of sessionCommand and playerCommand should be set");
|
||||
return new CommandButton(
|
||||
sessionCommand, playerCommand, iconResId, displayName, extras, enabled);
|
||||
sessionCommand, playerCommand, iconResId, iconUri, displayName, extras, enabled);
|
||||
}
|
||||
}
|
||||
|
||||
@ -172,6 +187,9 @@ public final class CommandButton implements Bundleable {
|
||||
*/
|
||||
@DrawableRes public final int iconResId;
|
||||
|
||||
/** The {@link Uri} for the icon of the button. Can be {@code null}. */
|
||||
@UnstableApi @Nullable public final Uri iconUri;
|
||||
|
||||
/**
|
||||
* The display name of the button. Can be empty if the command is predefined and a custom name
|
||||
* isn't needed.
|
||||
@ -191,12 +209,14 @@ public final class CommandButton implements Bundleable {
|
||||
@Nullable SessionCommand sessionCommand,
|
||||
@Player.Command int playerCommand,
|
||||
@DrawableRes int iconResId,
|
||||
@Nullable Uri iconUri,
|
||||
CharSequence displayName,
|
||||
Bundle extras,
|
||||
boolean enabled) {
|
||||
this.sessionCommand = sessionCommand;
|
||||
this.playerCommand = playerCommand;
|
||||
this.iconResId = iconResId;
|
||||
this.iconUri = iconUri;
|
||||
this.displayName = displayName;
|
||||
this.extras = new Bundle(extras);
|
||||
this.isEnabled = enabled;
|
||||
@ -212,7 +232,13 @@ public final class CommandButton implements Bundleable {
|
||||
return this;
|
||||
}
|
||||
return new CommandButton(
|
||||
sessionCommand, playerCommand, iconResId, displayName, new Bundle(extras), isEnabled);
|
||||
sessionCommand,
|
||||
playerCommand,
|
||||
iconResId,
|
||||
iconUri,
|
||||
displayName,
|
||||
new Bundle(extras),
|
||||
isEnabled);
|
||||
}
|
||||
|
||||
/** Checks the given command button for equality while ignoring {@link #extras}. */
|
||||
@ -228,13 +254,15 @@ public final class CommandButton implements Bundleable {
|
||||
return Objects.equal(sessionCommand, button.sessionCommand)
|
||||
&& playerCommand == button.playerCommand
|
||||
&& iconResId == button.iconResId
|
||||
&& Objects.equal(iconUri, button.iconUri)
|
||||
&& TextUtils.equals(displayName, button.displayName)
|
||||
&& isEnabled == button.isEnabled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hashCode(sessionCommand, playerCommand, iconResId, displayName, isEnabled);
|
||||
return Objects.hashCode(
|
||||
sessionCommand, playerCommand, iconResId, displayName, isEnabled, iconUri);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -19,6 +19,7 @@ import static androidx.media3.session.CommandButton.CREATOR;
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.junit.Assert.assertThrows;
|
||||
|
||||
import android.net.Uri;
|
||||
import android.os.Bundle;
|
||||
import androidx.media3.common.Player;
|
||||
import androidx.test.ext.junit.runners.AndroidJUnit4;
|
||||
@ -114,18 +115,46 @@ public class CommandButtonTest {
|
||||
.containsExactly(button1.copyWithIsEnabled(true), button2.copyWithIsEnabled(true));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIconUri_returnsUri() {
|
||||
Uri uri = Uri.parse("content://test");
|
||||
CommandButton button =
|
||||
new CommandButton.Builder()
|
||||
.setDisplayName("button1")
|
||||
.setIconResId(R.drawable.media3_notification_small_icon)
|
||||
.setIconUri(uri)
|
||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||
.build();
|
||||
|
||||
assertThat(button.iconUri).isEqualTo(uri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void getIconUri_returnsNullIfUnset() {
|
||||
CommandButton button =
|
||||
new CommandButton.Builder()
|
||||
.setDisplayName("button1")
|
||||
.setIconResId(R.drawable.media3_notification_small_icon)
|
||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_PREVIOUS)
|
||||
.build();
|
||||
|
||||
assertThat(button.iconUri).isNull();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void equals() {
|
||||
assertThat(
|
||||
new CommandButton.Builder()
|
||||
.setDisplayName("button")
|
||||
.setIconResId(R.drawable.media3_notification_small_icon)
|
||||
.setIconUri(Uri.parse("content://test"))
|
||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||
.build())
|
||||
.isEqualTo(
|
||||
new CommandButton.Builder()
|
||||
.setDisplayName("button")
|
||||
.setIconResId(R.drawable.media3_notification_small_icon)
|
||||
.setIconUri(Uri.parse("content://test"))
|
||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||
.build());
|
||||
}
|
||||
@ -176,6 +205,14 @@ public class CommandButtonTest {
|
||||
.setDisplayName("button")
|
||||
.setIconResId(R.drawable.media3_notification_small_icon)
|
||||
.build());
|
||||
assertThat(button)
|
||||
.isNotEqualTo(
|
||||
new CommandButton.Builder()
|
||||
.setDisplayName("button")
|
||||
.setIconResId(R.drawable.media3_notification_small_icon)
|
||||
.setIconUri(Uri.parse("content://test"))
|
||||
.setPlayerCommand(Player.COMMAND_SEEK_TO_NEXT)
|
||||
.build());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
Loading…
x
Reference in New Issue
Block a user