| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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.app.smartspace.SmartspaceUtils; |
| 24 |
import android.os.Parcel; |
| 25 |
|
| 26 |
import java.util.Objects; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
|
| 39 |
@SystemApi |
| 40 |
public final class SubCardTemplateData extends BaseTemplateData { |
| 41 |
|
| 42 |
|
| 43 |
@NonNull |
| 44 |
private final Icon mSubCardIcon; |
| 45 |
|
| 46 |
|
| 47 |
@Nullable |
| 48 |
private final Text mSubCardText; |
| 49 |
|
| 50 |
|
| 51 |
@Nullable |
| 52 |
private final TapAction mSubCardAction; |
| 53 |
|
| 54 |
SubCardTemplateData(@NonNull Parcel in) { |
| 55 |
super(in); |
| 56 |
mSubCardIcon = in.readTypedObject(Icon.CREATOR); |
| 57 |
mSubCardText = in.readTypedObject(Text.CREATOR); |
| 58 |
mSubCardAction = in.readTypedObject(TapAction.CREATOR); |
| 59 |
} |
| 60 |
|
| 61 |
private SubCardTemplateData(int templateType, |
| 62 |
@Nullable SubItemInfo primaryItem, |
| 63 |
@Nullable SubItemInfo subtitleItem, |
| 64 |
@Nullable SubItemInfo subtitleSupplementalItem, |
| 65 |
@Nullable SubItemInfo supplementalLineItem, |
| 66 |
@Nullable SubItemInfo supplementalAlarmItem, |
| 67 |
int layoutWeight, |
| 68 |
@NonNull Icon subCardIcon, |
| 69 |
@Nullable Text subCardText, |
| 70 |
@Nullable TapAction subCardAction) { |
| 71 |
super(templateType, primaryItem, subtitleItem, subtitleSupplementalItem, |
| 72 |
supplementalLineItem, supplementalAlarmItem, layoutWeight); |
| 73 |
|
| 74 |
mSubCardIcon = subCardIcon; |
| 75 |
mSubCardText = subCardText; |
| 76 |
mSubCardAction = subCardAction; |
| 77 |
} |
| 78 |
|
| 79 |
|
| 80 |
@NonNull |
| 81 |
public Icon getSubCardIcon() { |
| 82 |
return mSubCardIcon; |
| 83 |
} |
| 84 |
|
| 85 |
|
| 86 |
@Nullable |
| 87 |
public Text getSubCardText() { |
| 88 |
return mSubCardText; |
| 89 |
} |
| 90 |
|
| 91 |
|
| 92 |
@Nullable |
| 93 |
public TapAction getSubCardAction() { |
| 94 |
return mSubCardAction; |
| 95 |
} |
| 96 |
|
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
@NonNull |
| 101 |
public static final Creator<SubCardTemplateData> CREATOR = |
| 102 |
new Creator<SubCardTemplateData>() { |
| 103 |
@Override |
| 104 |
public SubCardTemplateData createFromParcel(Parcel in) { |
| 105 |
return new SubCardTemplateData(in); |
| 106 |
} |
| 107 |
|
| 108 |
@Override |
| 109 |
public SubCardTemplateData[] newArray(int size) { |
| 110 |
return new SubCardTemplateData[size]; |
| 111 |
} |
| 112 |
}; |
| 113 |
|
| 114 |
@Override |
| 115 |
public int describeContents() { |
| 116 |
return 0; |
| 117 |
} |
| 118 |
|
| 119 |
@Override |
| 120 |
public void writeToParcel(@NonNull Parcel out, int flags) { |
| 121 |
super.writeToParcel(out, flags); |
| 122 |
out.writeTypedObject(mSubCardIcon, flags); |
| 123 |
out.writeTypedObject(mSubCardText, flags); |
| 124 |
out.writeTypedObject(mSubCardAction, flags); |
| 125 |
} |
| 126 |
|
| 127 |
@Override |
| 128 |
public boolean equals(Object o) { |
| 129 |
if (this == o) return true; |
| 130 |
if (!(o instanceof SubCardTemplateData)) return false; |
| 131 |
if (!super.equals(o)) return false; |
| 132 |
SubCardTemplateData that = (SubCardTemplateData) o; |
| 133 |
return mSubCardIcon.equals(that.mSubCardIcon) && SmartspaceUtils.isEqual(mSubCardText, |
| 134 |
that.mSubCardText) && Objects.equals(mSubCardAction, |
| 135 |
that.mSubCardAction); |
| 136 |
} |
| 137 |
|
| 138 |
@Override |
| 139 |
public int hashCode() { |
| 140 |
return Objects.hash(super.hashCode(), mSubCardIcon, mSubCardText, mSubCardAction); |
| 141 |
} |
| 142 |
|
| 143 |
@Override |
| 144 |
public String toString() { |
| 145 |
return super.toString() + " + SmartspaceSubCardUiTemplateData{" |
| 146 |
+ "mSubCardIcon=" + mSubCardIcon |
| 147 |
+ ", mSubCardText=" + mSubCardText |
| 148 |
+ ", mSubCardAction=" + mSubCardAction |
| 149 |
+ '}'; |
| 150 |
} |
| 151 |
|
| 152 |
|
| 153 |
|
| 154 |
|
| 155 |
|
| 156 |
|
| 157 |
@SystemApi |
| 158 |
public static final class Builder extends BaseTemplateData.Builder { |
| 159 |
|
| 160 |
private final Icon mSubCardIcon; |
| 161 |
private Text mSubCardText; |
| 162 |
private TapAction mSubCardAction; |
| 163 |
|
| 164 |
|
| 165 |
|
| 166 |
|
| 167 |
public Builder(@NonNull Icon subCardIcon) { |
| 168 |
super(SmartspaceTarget.UI_TEMPLATE_SUB_CARD); |
| 169 |
mSubCardIcon = Objects.requireNonNull(subCardIcon); |
| 170 |
} |
| 171 |
|
| 172 |
|
| 173 |
|
| 174 |
|
| 175 |
@NonNull |
| 176 |
public Builder setSubCardText(@NonNull Text subCardText) { |
| 177 |
mSubCardText = subCardText; |
| 178 |
return this; |
| 179 |
} |
| 180 |
|
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
@NonNull |
| 185 |
public Builder setSubCardAction(@NonNull TapAction subCardAction) { |
| 186 |
mSubCardAction = subCardAction; |
| 187 |
return this; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
@NonNull |
| 194 |
public SubCardTemplateData build() { |
| 195 |
return new SubCardTemplateData(getTemplateType(), getPrimaryItem(), |
| 196 |
getSubtitleItem(), getSubtitleSupplemtnalItem(), |
| 197 |
getSupplementalLineItem(), getSupplementalAlarmItem(), getLayoutWeight(), |
| 198 |
mSubCardIcon, |
| 199 |
mSubCardText, |
| 200 |
mSubCardAction); |
| 201 |
} |
| 202 |
} |
| 203 |
} |