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 import java.util.ArrayList; 24 import java.util.List; 25 26 /** 27 * The response for an {@link GetWalletCardsRequest} contains a list of wallet cards and the index 28 * of the card that should initially be displayed in the 'selected' position. 29 */ 30 public final class GetWalletCardsResponse implements Parcelable { 31 32 private final List<WalletCard> mWalletCards; 33 private final int mSelectedIndex; 34 35 /** 36 * Construct a new response. 37 * 38 * @param walletCards The list of wallet cards. The list may be empty but must NOT be larger 39 * than {@link GetWalletCardsRequest#getMaxCards()}. The list may not 40 * contain null values. 41 * @param selectedIndex The index of the card that should be presented as the initially 42 * 'selected' card. The index must be greater than or equal to zero and 43 * less than the size of the list of walletCards (unless the list is empty 44 * in which case the value may be 0). 45 */ GetWalletCardsResponse(@onNull List<WalletCard> walletCards, int selectedIndex)46 public GetWalletCardsResponse(@NonNull List<WalletCard> walletCards, int selectedIndex) { 47 this.mWalletCards = walletCards; 48 this.mSelectedIndex = selectedIndex; 49 } 50 51 @Override describeContents()52 public int describeContents() { 53 return 0; 54 } 55 56 @Override writeToParcel(@onNull Parcel dest, int flags)57 public void writeToParcel(@NonNull Parcel dest, int flags) { 58 dest.writeInt(mWalletCards.size()); 59 dest.writeParcelableList(mWalletCards, flags); 60 dest.writeInt(mSelectedIndex); 61 } 62 readFromParcel(Parcel source)63 private static GetWalletCardsResponse readFromParcel(Parcel source) { 64 int size = source.readInt(); 65 List<WalletCard> walletCards = 66 source.readParcelableList(new ArrayList<>(size), WalletCard.class.getClassLoader(), android.service.quickaccesswallet.WalletCard.class); 67 int selectedIndex = source.readInt(); 68 return new GetWalletCardsResponse(walletCards, selectedIndex); 69 } 70 71 @NonNull 72 public static final Creator<GetWalletCardsResponse> CREATOR = 73 new Creator<GetWalletCardsResponse>() { 74 @Override 75 public GetWalletCardsResponse createFromParcel(Parcel source) { 76 return readFromParcel(source); 77 } 78 79 @Override 80 public GetWalletCardsResponse[] newArray(int size) { 81 return new GetWalletCardsResponse[size]; 82 } 83 }; 84 85 /** 86 * The list of {@link WalletCard}s. The size of this list should not exceed {@link 87 * GetWalletCardsRequest#getMaxCards()}. 88 */ 89 @NonNull getWalletCards()90 public List<WalletCard> getWalletCards() { 91 return mWalletCards; 92 } 93 94 /** 95 * The {@code selectedIndex} represents the index of the card that should be presented in the 96 * 'selected' position when the cards are initially displayed in the quick access wallet. The 97 * {@code selectedIndex} should be greater than or equal to zero and less than the size of the 98 * list of {@link WalletCard walletCards}, unless the list is empty in which case the {@code 99 * selectedIndex} can take any value. 0 is a nice round number for such cases. 100 */ getSelectedIndex()101 public int getSelectedIndex() { 102 return mSelectedIndex; 103 } 104 } 105