Accept resource URIs for command buttons

PiperOrigin-RevId: 687239119
(cherry picked from commit 3e556a4b53a4b5ae6feebe302b7b3c2813281943)
This commit is contained in:
bachinger 2024-10-18 03:32:57 -07:00 committed by Iván Budnik
parent ed6b822ff5
commit 88a78ade04

View File

@ -571,11 +571,12 @@ public final class CommandButton {
}
/**
* Sets a content {@link Uri} for the icon of this button.
* Sets a {@linkplain ContentResolver#SCHEME_CONTENT content} or {@linkplain
* ContentResolver#SCHEME_ANDROID_RESOURCE resource} {@link Uri} for the icon of this button.
*
* <p>Note that this {@link Uri} may be used when the predefined {@link Icon} is not available
* or set to {@link #ICON_UNDEFINED}. It can be used in addition to {@link #setCustomIconResId}
* for consumers that are capable of loading the content {@link Uri}.
* for consumers that are capable of loading the content or resource {@link Uri}.
*
* @param uri The uri to an icon.
* @return This builder for chaining.
@ -584,8 +585,9 @@ public final class CommandButton {
@CanIgnoreReturnValue
public Builder setIconUri(Uri uri) {
checkArgument(
Objects.equal(uri.getScheme(), ContentResolver.SCHEME_CONTENT),
"Only content Uris are supported for CommandButton");
Objects.equal(uri.getScheme(), ContentResolver.SCHEME_CONTENT)
|| Objects.equal(uri.getScheme(), ContentResolver.SCHEME_ANDROID_RESOURCE),
"Only content or resource Uris are supported for CommandButton");
this.iconUri = uri;
return this;
}
@ -711,11 +713,13 @@ public final class CommandButton {
@DrawableRes public final int iconResId;
/**
* The content {@link Uri} for the icon of the button that is used when the predefined {@link
* #icon} is not available or set to {@link #ICON_UNDEFINED}. Can be {@code null}.
* The {@linkplain ContentResolver#SCHEME_CONTENT content} or {@linkplain
* ContentResolver#SCHEME_ANDROID_RESOURCE resource} {@link Uri} for the icon of the button that
* is used when the predefined {@link #icon} is not available or set to {@link #ICON_UNDEFINED}.
* Can be {@code null}.
*
* <p>Note that this value can be used in addition to {@link #iconResId} for consumers that are
* capable of loading the content {@link Uri}.
* capable of loading the content or resource {@link Uri}.
*/
@UnstableApi @Nullable public final Uri iconUri;
@ -938,7 +942,9 @@ public final class CommandButton {
if (playerCommand != Player.COMMAND_INVALID) {
builder.setPlayerCommand(playerCommand);
}
if (iconUri != null && Objects.equal(iconUri.getScheme(), ContentResolver.SCHEME_CONTENT)) {
if (iconUri != null
&& (Objects.equal(iconUri.getScheme(), ContentResolver.SCHEME_CONTENT)
|| Objects.equal(iconUri.getScheme(), ContentResolver.SCHEME_ANDROID_RESOURCE))) {
builder.setIconUri(iconUri);
}
return builder