Debian Codegraph @

core/java/android/service/settings/suggestions/Suggestion.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2017 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.settings.suggestions;
18
19 import android.annotation.IntDef;
20 import android.annotation.SystemApi;
21 import android.app.PendingIntent;
22 import android.graphics.drawable.Icon;
23 import android.os.Parcel;
24 import android.os.Parcelable;
25 import android.text.TextUtils;
26
27 import java.lang.annotation.Retention;
28 import java.lang.annotation.RetentionPolicy;
29
30 /**
31 * Data object that has information about a device suggestion.
32 *
33 * @hide
34 */
35 @SystemApi
36 public final class Suggestion implements Parcelable {
37
38 /**
39 * @hide
40 */
41 @IntDef(flag = true, prefix = { "FLAG_" }, value = {
42 FLAG_HAS_BUTTON,
43 FLAG_ICON_TINTABLE,
44 })
45 @Retention(RetentionPolicy.SOURCE)
46 public @interface Flags {
47 }
48
49 /**
50 * Flag for suggestion type with a single button
51 */
52 public static final int FLAG_HAS_BUTTON = 1 << 0;
53 /**
54 * @hide
55 */
56 public static final int FLAG_ICON_TINTABLE = 1 << 1;
57
58 private final String mId;
59 private final CharSequence mTitle;
60 private final CharSequence mSummary;
61 private final Icon mIcon;
62 @Flags
63 private final int mFlags;
64 private final PendingIntent mPendingIntent;
65
66 /**
67 * Gets the id for the suggestion object.
68 */
69 public String getId() {
70 return mId;
71 }
72
73 /**
74 * Title of the suggestion that is shown to the user.
75 */
76 public CharSequence getTitle() {
77 return mTitle;
78 }
79
80 /**
81 * Optional summary describing what this suggestion controls.
82 */
83 public CharSequence getSummary() {
84 return mSummary;
85 }
86
87 /**
88 * Optional icon for this suggestion.
89 */
90 public Icon getIcon() {
91 return mIcon;
92 }
93
94 /**
95 * Optional flags for this suggestion. This will influence UI when rendering suggestion in
96 * different style.
97 */
98 @Flags
99 public int getFlags() {
100 return mFlags;
101 }
102
103 /**
104 * The Intent to launch when the suggestion is activated.
105 */
106 public PendingIntent getPendingIntent() {
107 return mPendingIntent;
108 }
109
110 private Suggestion(Builder builder) {
111 mId = builder.mId;
112 mTitle = builder.mTitle;
113 mSummary = builder.mSummary;
114 mIcon = builder.mIcon;
115 mFlags = builder.mFlags;
116 mPendingIntent = builder.mPendingIntent;
117 }
118
119 private Suggestion(Parcel in) {
120 mId = in.readString();
121 mTitle = in.readCharSequence();
122 mSummary = in.readCharSequence();
123 mIcon = in.readParcelable(Icon.class.getClassLoader(), android.graphics.drawable.Icon.class);
124 mFlags = in.readInt();
125 mPendingIntent = in.readParcelable(PendingIntent.class.getClassLoader(), android.app.PendingIntent.class);
126 }
127
128 public static final @android.annotation.NonNull Creator<Suggestion> CREATOR = new Creator<Suggestion>() {
129 @Override
130 public Suggestion createFromParcel(Parcel in) {
131 return new Suggestion(in);
132 }
133
134 @Override
135 public Suggestion[] newArray(int size) {
136 return new Suggestion[size];
137 }
138 };
139
140 @Override
141 public int describeContents() {
142 return 0;
143 }
144
145 @Override
146 public void writeToParcel(Parcel dest, int flags) {
147 dest.writeString(mId);
148 dest.writeCharSequence(mTitle);
149 dest.writeCharSequence(mSummary);
150 dest.writeParcelable(mIcon, flags);
151 dest.writeInt(mFlags);
152 dest.writeParcelable(mPendingIntent, flags);
153 }
154
155 /**
156 * Builder class for {@link Suggestion}.
157 */
158 public static class Builder {
159 private final String mId;
160 private CharSequence mTitle;
161 private CharSequence mSummary;
162 private Icon mIcon;
163 @Flags
164 private int mFlags;
165 private PendingIntent mPendingIntent;
166
167 public Builder(String id) {
168 if (TextUtils.isEmpty(id)) {
169 throw new IllegalArgumentException("Suggestion id cannot be empty");
170 }
171 mId = id;
172 }
173
174 /**
175 * Sets suggestion title
176 */
177 public Builder setTitle(CharSequence title) {
178 mTitle = title;
179 return this;
180 }
181
182 /**
183 * Sets suggestion summary
184 */
185 public Builder setSummary(CharSequence summary) {
186 mSummary = summary;
187 return this;
188 }
189
190 /**
191 * Sets icon for the suggestion.
192 */
193 public Builder setIcon(Icon icon) {
194 mIcon = icon;
195 return this;
196 }
197
198 /**
199 * Sets a UI type for this suggestion. This will influence UI when rendering suggestion in
200 * different style.
201 */
202 public Builder setFlags(@Flags int flags) {
203 mFlags = flags;
204 return this;
205 }
206
207 /**
208 * Sets suggestion intent
209 */
210 public Builder setPendingIntent(PendingIntent pendingIntent) {
211 mPendingIntent = pendingIntent;
212 return this;
213 }
214
215 /**
216 * Builds an immutable {@link Suggestion} object.
217 */
218 public Suggestion build() {
219 return new Suggestion(this /* builder */);
220 }
221 }
222 }