| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
package android.app; |
| 18 |
|
| 19 |
import android.annotation.NonNull; |
| 20 |
import android.annotation.Nullable; |
| 21 |
import android.graphics.drawable.Icon; |
| 22 |
import android.net.Uri; |
| 23 |
import android.os.Parcel; |
| 24 |
import android.os.Parcelable; |
| 25 |
|
| 26 |
import java.util.Objects; |
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
public final class Person implements Parcelable { |
| 33 |
|
| 34 |
@Nullable private CharSequence mName; |
| 35 |
@Nullable private Icon mIcon; |
| 36 |
@Nullable private String mUri; |
| 37 |
@Nullable private String mKey; |
| 38 |
private boolean mIsBot; |
| 39 |
private boolean mIsImportant; |
| 40 |
|
| 41 |
private Person(Parcel in) { |
| 42 |
mName = in.readCharSequence(); |
| 43 |
if (in.readInt() != 0) { |
| 44 |
mIcon = Icon.CREATOR.createFromParcel(in); |
| 45 |
} |
| 46 |
mUri = in.readString(); |
| 47 |
mKey = in.readString(); |
| 48 |
mIsImportant = in.readBoolean(); |
| 49 |
mIsBot = in.readBoolean(); |
| 50 |
} |
| 51 |
|
| 52 |
private Person(Builder builder) { |
| 53 |
mName = builder.mName; |
| 54 |
mIcon = builder.mIcon; |
| 55 |
mUri = builder.mUri; |
| 56 |
mKey = builder.mKey; |
| 57 |
mIsBot = builder.mIsBot; |
| 58 |
mIsImportant = builder.mIsImportant; |
| 59 |
} |
| 60 |
|
| 61 |
|
| 62 |
public Builder toBuilder() { |
| 63 |
return new Builder(this); |
| 64 |
} |
| 65 |
|
| 66 |
|
| 67 |
|
| 68 |
|
| 69 |
@Nullable |
| 70 |
public String getUri() { |
| 71 |
return mUri; |
| 72 |
} |
| 73 |
|
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
@Nullable |
| 78 |
public CharSequence getName() { |
| 79 |
return mName; |
| 80 |
} |
| 81 |
|
| 82 |
|
| 83 |
|
| 84 |
|
| 85 |
@Nullable |
| 86 |
public Icon getIcon() { |
| 87 |
return mIcon; |
| 88 |
} |
| 89 |
|
| 90 |
|
| 91 |
|
| 92 |
|
| 93 |
@Nullable |
| 94 |
public String getKey() { |
| 95 |
return mKey; |
| 96 |
} |
| 97 |
|
| 98 |
|
| 99 |
|
| 100 |
|
| 101 |
public boolean isBot() { |
| 102 |
return mIsBot; |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
|
| 107 |
|
| 108 |
public boolean isImportant() { |
| 109 |
return mIsImportant; |
| 110 |
} |
| 111 |
|
| 112 |
|
| 113 |
|
| 114 |
|
| 115 |
|
| 116 |
public String resolveToLegacyUri() { |
| 117 |
if (mUri != null) { |
| 118 |
return mUri; |
| 119 |
} |
| 120 |
if (mName != null) { |
| 121 |
return "name:" + mName; |
| 122 |
} |
| 123 |
return ""; |
| 124 |
} |
| 125 |
|
| 126 |
|
| 127 |
|
| 128 |
|
| 129 |
|
| 130 |
|
| 131 |
@Nullable |
| 132 |
public Uri getIconUri() { |
| 133 |
if (mIcon != null && (mIcon.getType() == Icon.TYPE_URI |
| 134 |
|| mIcon.getType() == Icon.TYPE_URI_ADAPTIVE_BITMAP)) { |
| 135 |
return mIcon.getUri(); |
| 136 |
} |
| 137 |
return null; |
| 138 |
} |
| 139 |
|
| 140 |
@Override |
| 141 |
public boolean equals(@Nullable Object obj) { |
| 142 |
if (obj instanceof Person) { |
| 143 |
final Person other = (Person) obj; |
| 144 |
return Objects.equals(mName, other.mName) |
| 145 |
&& (mIcon == null ? other.mIcon == null : |
| 146 |
(other.mIcon != null && mIcon.sameAs(other.mIcon))) |
| 147 |
&& Objects.equals(mUri, other.mUri) |
| 148 |
&& Objects.equals(mKey, other.mKey) |
| 149 |
&& mIsBot == other.mIsBot |
| 150 |
&& mIsImportant == other.mIsImportant; |
| 151 |
} |
| 152 |
return false; |
| 153 |
} |
| 154 |
|
| 155 |
@Override |
| 156 |
public int hashCode() { |
| 157 |
return Objects.hash(mName, mIcon, mUri, mKey, mIsBot, mIsImportant); |
| 158 |
} |
| 159 |
|
| 160 |
@Override |
| 161 |
public int describeContents() { |
| 162 |
return 0; |
| 163 |
} |
| 164 |
|
| 165 |
@Override |
| 166 |
public void writeToParcel(Parcel dest, @WriteFlags int flags) { |
| 167 |
dest.writeCharSequence(mName); |
| 168 |
if (mIcon != null) { |
| 169 |
dest.writeInt(1); |
| 170 |
mIcon.writeToParcel(dest, 0); |
| 171 |
} else { |
| 172 |
dest.writeInt(0); |
| 173 |
} |
| 174 |
dest.writeString(mUri); |
| 175 |
dest.writeString(mKey); |
| 176 |
dest.writeBoolean(mIsImportant); |
| 177 |
dest.writeBoolean(mIsBot); |
| 178 |
} |
| 179 |
|
| 180 |
|
| 181 |
public static class Builder { |
| 182 |
@Nullable private CharSequence mName; |
| 183 |
@Nullable private Icon mIcon; |
| 184 |
@Nullable private String mUri; |
| 185 |
@Nullable private String mKey; |
| 186 |
private boolean mIsBot; |
| 187 |
private boolean mIsImportant; |
| 188 |
|
| 189 |
|
| 190 |
public Builder() { |
| 191 |
} |
| 192 |
|
| 193 |
private Builder(Person person) { |
| 194 |
mName = person.mName; |
| 195 |
mIcon = person.mIcon; |
| 196 |
mUri = person.mUri; |
| 197 |
mKey = person.mKey; |
| 198 |
mIsBot = person.mIsBot; |
| 199 |
mIsImportant = person.mIsImportant; |
| 200 |
} |
| 201 |
|
| 202 |
|
| 203 |
|
| 204 |
|
| 205 |
|
| 206 |
|
| 207 |
@NonNull |
| 208 |
public Person.Builder setName(@Nullable CharSequence name) { |
| 209 |
this.mName = name; |
| 210 |
return this; |
| 211 |
} |
| 212 |
|
| 213 |
|
| 214 |
|
| 215 |
|
| 216 |
|
| 217 |
|
| 218 |
|
| 219 |
|
| 220 |
@NonNull |
| 221 |
public Person.Builder setIcon(@Nullable Icon icon) { |
| 222 |
this.mIcon = icon; |
| 223 |
return this; |
| 224 |
} |
| 225 |
|
| 226 |
|
| 227 |
|
| 228 |
|
| 229 |
|
| 230 |
|
| 231 |
|
| 232 |
|
| 233 |
|
| 234 |
|
| 235 |
|
| 236 |
|
| 237 |
|
| 238 |
|
| 239 |
|
| 240 |
|
| 241 |
|
| 242 |
@NonNull |
| 243 |
public Person.Builder setUri(@Nullable String uri) { |
| 244 |
mUri = uri; |
| 245 |
return this; |
| 246 |
} |
| 247 |
|
| 248 |
|
| 249 |
|
| 250 |
|
| 251 |
|
| 252 |
|
| 253 |
|
| 254 |
|
| 255 |
|
| 256 |
|
| 257 |
|
| 258 |
@NonNull |
| 259 |
public Person.Builder setKey(@Nullable String key) { |
| 260 |
mKey = key; |
| 261 |
return this; |
| 262 |
} |
| 263 |
|
| 264 |
|
| 265 |
|
| 266 |
|
| 267 |
|
| 268 |
|
| 269 |
|
| 270 |
|
| 271 |
|
| 272 |
@NonNull |
| 273 |
public Person.Builder setImportant(boolean isImportant) { |
| 274 |
mIsImportant = isImportant; |
| 275 |
return this; |
| 276 |
} |
| 277 |
|
| 278 |
|
| 279 |
|
| 280 |
|
| 281 |
|
| 282 |
|
| 283 |
@NonNull |
| 284 |
public Person.Builder setBot(boolean isBot) { |
| 285 |
mIsBot = isBot; |
| 286 |
return this; |
| 287 |
} |
| 288 |
|
| 289 |
|
| 290 |
@NonNull |
| 291 |
public Person build() { |
| 292 |
return new Person(this); |
| 293 |
} |
| 294 |
} |
| 295 |
|
| 296 |
public static final @android.annotation.NonNull Creator<Person> CREATOR = new Creator<Person>() { |
| 297 |
@Override |
| 298 |
public Person createFromParcel(Parcel in) { |
| 299 |
return new Person(in); |
| 300 |
} |
| 301 |
|
| 302 |
@Override |
| 303 |
public Person[] newArray(int size) { |
| 304 |
return new Person[size]; |
| 305 |
} |
| 306 |
}; |
| 307 |
} |