1 /* 2 * Copyright 2020 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package android.service.quickaccesswallet; 18 19 import android.annotation.NonNull; 20 import android.os.Parcel; 21 import android.os.Parcelable; 22 23 /** 24 * Represents a request to a {@link QuickAccessWalletService} for {@link WalletCard walletCards}. 25 * Wallet cards may represent anything that a user might carry in their wallet -- a credit card, 26 * library card, a transit pass, etc. This request contains the desired size of the card images and 27 * icons as well as the maximum number of cards that may be returned in the {@link 28 * GetWalletCardsResponse}. 29 * 30 * <p>Cards may be displayed with an optional icon and label. The icon and label should communicate 31 * the same idea. For example, if a card can be used at an NFC terminal, the icon could be an NFC 32 * icon and the label could inform the user how to interact with the NFC terminal. 33 * 34 * <p>The maximum number of cards that may be displayed in the wallet is provided in {@link 35 * #getMaxCards()}. The {@link QuickAccessWalletService} may provide up to this many cards in the 36 * {@link GetWalletCardsResponse#getWalletCards()}. If the list of cards provided exceeds this 37 * number, some of the cards may not be shown to the user. 38 */ 39 public final class GetWalletCardsRequest implements Parcelable { 40 41 private final int mCardWidthPx; 42 private final int mCardHeightPx; 43 private final int mIconSizePx; 44 private final int mMaxCards; 45 46 /** 47 * Creates a new GetWalletCardsRequest. 48 * 49 * @param cardWidthPx The width of the card image in pixels. 50 * @param cardHeightPx The height of the card image in pixels. 51 * @param iconSizePx The width and height of the optional card icon in pixels. 52 * @param maxCards The maximum number of cards that may be provided in the response. 53 */ GetWalletCardsRequest(int cardWidthPx, int cardHeightPx, int iconSizePx, int maxCards)54 public GetWalletCardsRequest(int cardWidthPx, int cardHeightPx, int iconSizePx, int maxCards) { 55 this.mCardWidthPx = cardWidthPx; 56 this.mCardHeightPx = cardHeightPx; 57 this.mIconSizePx = iconSizePx; 58 this.mMaxCards = maxCards; 59 } 60 61 /** 62 * {@inheritDoc} 63 */ 64 @Override describeContents()65 public int describeContents() { 66 return 0; 67 } 68 69 /** 70 * {@inheritDoc} 71 */ 72 @Override writeToParcel(@onNull Parcel dest, int flags)73 public void writeToParcel(@NonNull Parcel dest, int flags) { 74 dest.writeInt(mCardWidthPx); 75 dest.writeInt(mCardHeightPx); 76 dest.writeInt(mIconSizePx); 77 dest.writeInt(mMaxCards); 78 } 79 80 @NonNull 81 public static final Creator<GetWalletCardsRequest> CREATOR = 82 new Creator<GetWalletCardsRequest>() { 83 @Override 84 public GetWalletCardsRequest createFromParcel(Parcel source) { 85 int cardWidthPx = source.readInt(); 86 int cardHeightPx = source.readInt(); 87 int iconSizePx = source.readInt(); 88 int maxCards = source.readInt(); 89 return new GetWalletCardsRequest(cardWidthPx, 90 cardHeightPx, 91 iconSizePx, 92 maxCards); 93 } 94 95 @Override 96 public GetWalletCardsRequest[] newArray(int size) { 97 return new GetWalletCardsRequest[size]; 98 } 99 }; 100 101 /** 102 * The desired width of the {@link WalletCard#getCardImage()}, in pixels. The dimensions of the 103 * card image are requested so that it may be rendered without scaling. 104 * <p> 105 * The {@code cardWidthPx} and {@code cardHeightPx} should be applied to the size of the {@link 106 * WalletCard#getCardImage()}. The size of the card image is specified so that it may be 107 * rendered accurately and without distortion caused by scaling. 108 */ getCardWidthPx()109 public int getCardWidthPx() { 110 return mCardWidthPx; 111 } 112 113 /** 114 * The desired height of the {@link WalletCard#getCardImage()}, in pixels. The dimensions of the 115 * card image are requested so that it may be rendered without scaling. 116 */ getCardHeightPx()117 public int getCardHeightPx() { 118 return mCardHeightPx; 119 } 120 121 /** 122 * Wallet cards may be displayed next to an icon. The icon can help to convey additional 123 * information about the state of the card. If the provided icon is a bitmap, its width and 124 * height should equal iconSizePx so that it is rendered without distortion caused by scaling. 125 */ getIconSizePx()126 public int getIconSizePx() { 127 return mIconSizePx; 128 } 129 130 /** 131 * The maximum size of the {@link GetWalletCardsResponse#getWalletCards()}. If the list of cards 132 * exceeds this number, not all cards may be displayed. 133 */ getMaxCards()134 public int getMaxCards() { 135 return mMaxCards; 136 } 137 } 138