Merge "DO NOT MERGE Address API review feedback for WalletCard. Bug: b/266675271 Test: atest CtsQuickAccessWalletTestCases" into tm-qpr-dev

This commit is contained in:
Charles Wang
2023-02-22 15:40:34 +00:00
committed by Android (Google) Code Review

View File

@@ -36,7 +36,7 @@ import java.lang.annotation.RetentionPolicy;
* card, library card, transit pass, etc. Cards are identified by a String identifier and contain a * card, library card, transit pass, etc. Cards are identified by a String identifier and contain a
* card type, card image, card image content description, and a {@link PendingIntent} to be used if * card type, card image, card image content description, and a {@link PendingIntent} to be used if
* the user clicks on the card. Cards may be displayed with an icon and label, though these are * the user clicks on the card. Cards may be displayed with an icon and label, though these are
* optional. Valuable cards will also have a second image that will be displayed when the card is * optional. Non-payment cards will also have a second image that will be displayed when the card is
* tapped. * tapped.
*/ */
@@ -56,11 +56,11 @@ public final class WalletCard implements Parcelable {
public static final int CARD_TYPE_PAYMENT = 1; public static final int CARD_TYPE_PAYMENT = 1;
/** /**
* Valuable cards refer to any cards that are not used for cash-equivalent payment. * Non-payment cards refer to any cards that are not used for cash-equivalent payment, including
* This includes event tickets, flights, offers, loyalty cards, gift cards and transit tickets. * event tickets, flights, offers, loyalty cards, gift cards and transit tickets.
* @hide * @hide
*/ */
public static final int CARD_TYPE_VALUABLE = 2; public static final int CARD_TYPE_NON_PAYMENT = 2;
private final String mCardId; private final String mCardId;
private final int mCardType; private final int mCardType;
@@ -69,7 +69,7 @@ public final class WalletCard implements Parcelable {
private final PendingIntent mPendingIntent; private final PendingIntent mPendingIntent;
private final Icon mCardIcon; private final Icon mCardIcon;
private final CharSequence mCardLabel; private final CharSequence mCardLabel;
private final Icon mValuableCardSecondaryImage; private final Icon mNonPaymentCardSecondaryImage;
private WalletCard(Builder builder) { private WalletCard(Builder builder) {
this.mCardId = builder.mCardId; this.mCardId = builder.mCardId;
@@ -79,7 +79,7 @@ public final class WalletCard implements Parcelable {
this.mPendingIntent = builder.mPendingIntent; this.mPendingIntent = builder.mPendingIntent;
this.mCardIcon = builder.mCardIcon; this.mCardIcon = builder.mCardIcon;
this.mCardLabel = builder.mCardLabel; this.mCardLabel = builder.mCardLabel;
this.mValuableCardSecondaryImage = builder.mValuableCardSecondaryImage; this.mNonPaymentCardSecondaryImage = builder.mNonPaymentCardSecondaryImage;
} }
/** /**
@@ -89,7 +89,7 @@ public final class WalletCard implements Parcelable {
@IntDef(prefix = {"CARD_TYPE_"}, value = { @IntDef(prefix = {"CARD_TYPE_"}, value = {
CARD_TYPE_UNKNOWN, CARD_TYPE_UNKNOWN,
CARD_TYPE_PAYMENT, CARD_TYPE_PAYMENT,
CARD_TYPE_VALUABLE CARD_TYPE_NON_PAYMENT
}) })
public @interface CardType { public @interface CardType {
} }
@@ -108,7 +108,7 @@ public final class WalletCard implements Parcelable {
PendingIntent.writePendingIntentOrNullToParcel(mPendingIntent, dest); PendingIntent.writePendingIntentOrNullToParcel(mPendingIntent, dest);
writeIconIfNonNull(mCardIcon, dest, flags); writeIconIfNonNull(mCardIcon, dest, flags);
TextUtils.writeToParcel(mCardLabel, dest, flags); TextUtils.writeToParcel(mCardLabel, dest, flags);
writeIconIfNonNull(mValuableCardSecondaryImage, dest, flags); writeIconIfNonNull(mNonPaymentCardSecondaryImage, dest, flags);
} }
@@ -131,14 +131,14 @@ public final class WalletCard implements Parcelable {
PendingIntent pendingIntent = PendingIntent.readPendingIntentOrNullFromParcel(source); PendingIntent pendingIntent = PendingIntent.readPendingIntentOrNullFromParcel(source);
Icon cardIcon = source.readByte() == 0 ? null : Icon.CREATOR.createFromParcel(source); Icon cardIcon = source.readByte() == 0 ? null : Icon.CREATOR.createFromParcel(source);
CharSequence cardLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source); CharSequence cardLabel = TextUtils.CHAR_SEQUENCE_CREATOR.createFromParcel(source);
Icon valuableCardSecondaryImage = source.readByte() == 0 ? null : Icon nonPaymentCardSecondaryImage = source.readByte() == 0 ? null :
Icon.CREATOR.createFromParcel(source); Icon.CREATOR.createFromParcel(source);
Builder builder = new Builder(cardId, cardType, cardImage, contentDesc, pendingIntent) Builder builder = new Builder(cardId, cardType, cardImage, contentDesc, pendingIntent)
.setCardIcon(cardIcon) .setCardIcon(cardIcon)
.setCardLabel(cardLabel); .setCardLabel(cardLabel);
return cardType == CARD_TYPE_VALUABLE return cardType == CARD_TYPE_NON_PAYMENT
? builder.setValuableCardSecondaryImage(valuableCardSecondaryImage).build() : ? builder.setNonPaymentCardSecondaryImage(nonPaymentCardSecondaryImage).build() :
builder.build(); builder.build();
} }
@@ -229,13 +229,13 @@ public final class WalletCard implements Parcelable {
} }
/** /**
* Visual representation of the card when it is tapped. Includes a barcode to scan the card in * Visual representation of the card when it is tapped. May include additional information
* addition to the information in the primary image. * unique to the card, such as a barcode or number. Only valid for CARD_TYPE_NON_PAYMENT.
* @hide * @hide
*/ */
@Nullable @Nullable
public Icon getValuableCardSecondaryImage() { public Icon getNonPaymentCardSecondaryImage() {
return mValuableCardSecondaryImage; return mNonPaymentCardSecondaryImage;
} }
/** /**
@@ -251,7 +251,7 @@ public final class WalletCard implements Parcelable {
private PendingIntent mPendingIntent; private PendingIntent mPendingIntent;
private Icon mCardIcon; private Icon mCardIcon;
private CharSequence mCardLabel; private CharSequence mCardLabel;
private Icon mValuableCardSecondaryImage; private Icon mNonPaymentCardSecondaryImage;
/** /**
* @param cardId The card id must be non-null and unique within the list of * @param cardId The card id must be non-null and unique within the list of
@@ -259,7 +259,7 @@ public final class WalletCard implements Parcelable {
* </b> this card ID should <b>not</b> contain PII (Personally * </b> this card ID should <b>not</b> contain PII (Personally
* Identifiable Information, such as username or email address). * Identifiable Information, such as username or email address).
* @param cardType Integer representing the card type. The card type must be * @param cardType Integer representing the card type. The card type must be
* non-null. If not provided, it defaults to unknown. * non-null.
* @param cardImage The visual representation of the card. If the card image Icon * @param cardImage The visual representation of the card. If the card image Icon
* is a bitmap, it should have a width of {@link * is a bitmap, it should have a width of {@link
* GetWalletCardsRequest#getCardWidthPx()} and a height of {@link * GetWalletCardsRequest#getCardWidthPx()} and a height of {@link
@@ -294,7 +294,7 @@ public final class WalletCard implements Parcelable {
} }
/** /**
* Called when a card type is not provided. * Called when a card type is not provided, in which case it defaults to CARD_TYPE_UNKNOWN.
*/ */
public Builder(@NonNull String cardId, public Builder(@NonNull String cardId,
@NonNull Icon cardImage, @NonNull Icon cardImage,
@@ -336,15 +336,16 @@ public final class WalletCard implements Parcelable {
} }
/** /**
* Visual representation of the card when it is tapped. Includes a barcode to scan the card * Visual representation of the card when it is tapped. May include additional information
* in addition to the information in the primary image. * unique to the card, such as a barcode or number. Only valid for CARD_TYPE_NON_PAYMENT.
* @hide * @hide
*/ */
@NonNull @NonNull
public Builder setValuableCardSecondaryImage(@Nullable Icon valuableCardSecondaryImage) { public Builder
Preconditions.checkState(mCardType == CARD_TYPE_VALUABLE, setNonPaymentCardSecondaryImage(@Nullable Icon nonPaymentCardSecondaryImage) {
"This field can only be set on valuable cards"); Preconditions.checkState(mCardType == CARD_TYPE_NON_PAYMENT,
mValuableCardSecondaryImage = valuableCardSecondaryImage; "This field can only be set on non-payment cards");
mNonPaymentCardSecondaryImage = nonPaymentCardSecondaryImage;
return this; return this;
} }