Debian Codegraph @

core/java/android/app/smartspace/uitemplatedata/CombinedCardsTemplateData.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2022 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.app.smartspace.uitemplatedata;
18
19 import android.annotation.NonNull;
20 import android.annotation.Nullable;
21 import android.annotation.SystemApi;
22 import android.app.smartspace.SmartspaceTarget;
23 import android.os.Parcel;
24
25 import java.util.List;
26 import java.util.Objects;
27
28 /**
29 * Holds all the relevant data needed to render a Smartspace card with the combined-card Ui
30 * Template.
31 *
32 * We only support adding a 1 sub-list card combined with 1 sub-card card (may expand our supported
33 * combinations in the future) within the default-template card:
34 *
35 * <ul>
36 * <li> sub-list card, sub-card card </li>
37 * </ul>
38 *
39 * @hide
40 */
41 @SystemApi
42 public final class CombinedCardsTemplateData extends BaseTemplateData {
43
44 /** A list of secondary cards. */
45 @NonNull
46 private final List<BaseTemplateData> mCombinedCardDataList;
47
48 CombinedCardsTemplateData(@NonNull Parcel in) {
49 super(in);
50 mCombinedCardDataList = in.createTypedArrayList(BaseTemplateData.CREATOR);
51 }
52
53 private CombinedCardsTemplateData(@SmartspaceTarget.UiTemplateType int templateType,
54 @Nullable SubItemInfo primaryItem,
55 @Nullable SubItemInfo subtitleItem,
56 @Nullable SubItemInfo subtitleSupplementalItem,
57 @Nullable SubItemInfo supplementalLineItem,
58 @Nullable SubItemInfo supplementalAlarmItem,
59 int layoutWeight,
60 @NonNull List<BaseTemplateData> combinedCardDataList) {
61 super(templateType, primaryItem, subtitleItem, subtitleSupplementalItem,
62 supplementalLineItem, supplementalAlarmItem, layoutWeight);
63
64 mCombinedCardDataList = combinedCardDataList;
65 }
66
67 /** Returns the list of secondary cards. Can be null if not being set. */
68 @NonNull
69 public List<BaseTemplateData> getCombinedCardDataList() {
70 return mCombinedCardDataList;
71 }
72
73 /**
74 * @see Parcelable.Creator
75 */
76 @NonNull
77 public static final Creator<CombinedCardsTemplateData> CREATOR =
78 new Creator<CombinedCardsTemplateData>() {
79 @Override
80 public CombinedCardsTemplateData createFromParcel(Parcel in) {
81 return new CombinedCardsTemplateData(in);
82 }
83
84 @Override
85 public CombinedCardsTemplateData[] newArray(int size) {
86 return new CombinedCardsTemplateData[size];
87 }
88 };
89
90 @Override
91 public int describeContents() {
92 return 0;
93 }
94
95 @Override
96 public void writeToParcel(@NonNull Parcel out, int flags) {
97 super.writeToParcel(out, flags);
98 out.writeTypedList(mCombinedCardDataList);
99 }
100
101 @Override
102 public boolean equals(Object o) {
103 if (this == o) return true;
104 if (!(o instanceof CombinedCardsTemplateData)) return false;
105 if (!super.equals(o)) return false;
106 CombinedCardsTemplateData that = (CombinedCardsTemplateData) o;
107 return mCombinedCardDataList.equals(that.mCombinedCardDataList);
108 }
109
110 @Override
111 public int hashCode() {
112 return Objects.hash(super.hashCode(), mCombinedCardDataList);
113 }
114
115 @Override
116 public String toString() {
117 return super.toString() + " + SmartspaceCombinedCardsUiTemplateData{"
118 + "mCombinedCardDataList=" + mCombinedCardDataList
119 + '}';
120 }
121
122 /**
123 * A builder for {@link CombinedCardsTemplateData} object.
124 *
125 * @hide
126 */
127 @SystemApi
128 public static final class Builder extends BaseTemplateData.Builder {
129
130 private final List<BaseTemplateData> mCombinedCardDataList;
131
132 /**
133 * A builder for {@link CombinedCardsTemplateData}.
134 */
135 public Builder(@NonNull List<BaseTemplateData> combinedCardDataList) {
136 super(SmartspaceTarget.UI_TEMPLATE_COMBINED_CARDS);
137 mCombinedCardDataList = Objects.requireNonNull(combinedCardDataList);
138 }
139
140 /**
141 * Builds a new SmartspaceCombinedCardsUiTemplateData instance.
142 *
143 * @throws IllegalStateException if any required non-null field is null
144 */
145 @NonNull
146 public CombinedCardsTemplateData build() {
147 if (mCombinedCardDataList == null) {
148 throw new IllegalStateException("Please assign a value to all @NonNull args.");
149 }
150 return new CombinedCardsTemplateData(getTemplateType(), getPrimaryItem(),
151 getSubtitleItem(), getSubtitleSupplemtnalItem(),
152 getSupplementalLineItem(), getSupplementalAlarmItem(), getLayoutWeight(),
153 mCombinedCardDataList);
154 }
155 }
156 }