| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 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 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
@SystemApi |
| 36 |
public final class Suggestion implements Parcelable { |
| 37 |
|
| 38 |
|
| 39 |
|
| 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 |
|
| 51 |
|
| 52 |
public static final int FLAG_HAS_BUTTON = 1 << 0; |
| 53 |
|
| 54 |
|
| 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 |
|
| 68 |
|
| 69 |
public String getId() { |
| 70 |
return mId; |
| 71 |
} |
| 72 |
|
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
public CharSequence getTitle() { |
| 77 |
return mTitle; |
| 78 |
} |
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
|
| 83 |
public CharSequence getSummary() { |
| 84 |
return mSummary; |
| 85 |
} |
| 86 |
|
| 87 |
|
| 88 |
|
| 89 |
|
| 90 |
public Icon getIcon() { |
| 91 |
return mIcon; |
| 92 |
} |
| 93 |
|
| 94 |
|
| 95 |
|
| 96 |
|
| 97 |
|
| 98 |
@Flags |
| 99 |
public int getFlags() { |
| 100 |
return mFlags; |
| 101 |
} |
| 102 |
|
| 103 |
|
| 104 |
|
| 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 |
|
| 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 |
|
| 176 |
|
| 177 |
public Builder setTitle(CharSequence title) { |
| 178 |
mTitle = title; |
| 179 |
return this; |
| 180 |
} |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
|
| 185 |
public Builder setSummary(CharSequence summary) { |
| 186 |
mSummary = summary; |
| 187 |
return this; |
| 188 |
} |
| 189 |
|
| 190 |
|
| 191 |
|
| 192 |
|
| 193 |
public Builder setIcon(Icon icon) { |
| 194 |
mIcon = icon; |
| 195 |
return this; |
| 196 |
} |
| 197 |
|
| 198 |
|
| 199 |
|
| 200 |
|
| 201 |
|
| 202 |
public Builder setFlags(@Flags int flags) { |
| 203 |
mFlags = flags; |
| 204 |
return this; |
| 205 |
} |
| 206 |
|
| 207 |
|
| 208 |
|
| 209 |
|
| 210 |
public Builder setPendingIntent(PendingIntent pendingIntent) { |
| 211 |
mPendingIntent = pendingIntent; |
| 212 |
return this; |
| 213 |
} |
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
public Suggestion build() { |
| 219 |
return new Suggestion(this ); |
| 220 |
} |
| 221 |
} |
| 222 |
} |