191 lines
6 KiB
Java
191 lines
6 KiB
Java
|
package androidx.core.app;
|
||
|
|
||
|
import android.app.Person;
|
||
|
import android.os.Bundle;
|
||
|
import android.os.PersistableBundle;
|
||
|
import androidx.annotation.NonNull;
|
||
|
import androidx.annotation.Nullable;
|
||
|
import androidx.annotation.RequiresApi;
|
||
|
import androidx.annotation.RestrictTo;
|
||
|
import androidx.core.graphics.drawable.IconCompat;
|
||
|
public class Person {
|
||
|
private static final String ICON_KEY = "icon";
|
||
|
private static final String IS_BOT_KEY = "isBot";
|
||
|
private static final String IS_IMPORTANT_KEY = "isImportant";
|
||
|
private static final String KEY_KEY = "key";
|
||
|
private static final String NAME_KEY = "name";
|
||
|
private static final String URI_KEY = "uri";
|
||
|
@Nullable
|
||
|
public IconCompat mIcon;
|
||
|
public boolean mIsBot;
|
||
|
public boolean mIsImportant;
|
||
|
@Nullable
|
||
|
public String mKey;
|
||
|
@Nullable
|
||
|
public CharSequence mName;
|
||
|
@Nullable
|
||
|
public String mUri;
|
||
|
|
||
|
public static class Builder {
|
||
|
@Nullable
|
||
|
public IconCompat mIcon;
|
||
|
public boolean mIsBot;
|
||
|
public boolean mIsImportant;
|
||
|
@Nullable
|
||
|
public String mKey;
|
||
|
@Nullable
|
||
|
public CharSequence mName;
|
||
|
@Nullable
|
||
|
public String mUri;
|
||
|
|
||
|
public Builder() {
|
||
|
}
|
||
|
|
||
|
public Builder(Person person) {
|
||
|
this.mName = person.mName;
|
||
|
this.mIcon = person.mIcon;
|
||
|
this.mUri = person.mUri;
|
||
|
this.mKey = person.mKey;
|
||
|
this.mIsBot = person.mIsBot;
|
||
|
this.mIsImportant = person.mIsImportant;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Person build() {
|
||
|
return new Person(this);
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Builder setBot(boolean z2) {
|
||
|
this.mIsBot = z2;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Builder setIcon(@Nullable IconCompat iconCompat) {
|
||
|
this.mIcon = iconCompat;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Builder setImportant(boolean z2) {
|
||
|
this.mIsImportant = z2;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Builder setKey(@Nullable String str) {
|
||
|
this.mKey = str;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Builder setName(@Nullable CharSequence charSequence) {
|
||
|
this.mName = charSequence;
|
||
|
return this;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Builder setUri(@Nullable String str) {
|
||
|
this.mUri = str;
|
||
|
return this;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public Person(Builder builder) {
|
||
|
this.mName = builder.mName;
|
||
|
this.mIcon = builder.mIcon;
|
||
|
this.mUri = builder.mUri;
|
||
|
this.mKey = builder.mKey;
|
||
|
this.mIsBot = builder.mIsBot;
|
||
|
this.mIsImportant = builder.mIsImportant;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
@RequiresApi(28)
|
||
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
||
|
public static Person fromAndroidPerson(@NonNull android.app.Person person) {
|
||
|
return new Builder().setName(person.getName()).setIcon(person.getIcon() != null ? IconCompat.createFromIcon(person.getIcon()) : null).setUri(person.getUri()).setKey(person.getKey()).setBot(person.isBot()).setImportant(person.isImportant()).build();
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public static Person fromBundle(@NonNull Bundle bundle) {
|
||
|
Bundle bundle2 = bundle.getBundle("icon");
|
||
|
return new Builder().setName(bundle.getCharSequence("name")).setIcon(bundle2 != null ? IconCompat.createFromBundle(bundle2) : null).setUri(bundle.getString("uri")).setKey(bundle.getString("key")).setBot(bundle.getBoolean("isBot")).setImportant(bundle.getBoolean("isImportant")).build();
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
@RequiresApi(22)
|
||
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
||
|
public static Person fromPersistableBundle(@NonNull PersistableBundle persistableBundle) {
|
||
|
return new Builder().setName(persistableBundle.getString("name")).setUri(persistableBundle.getString("uri")).setKey(persistableBundle.getString("key")).setBot(persistableBundle.getBoolean("isBot")).setImportant(persistableBundle.getBoolean("isImportant")).build();
|
||
|
}
|
||
|
|
||
|
@Nullable
|
||
|
public IconCompat getIcon() {
|
||
|
return this.mIcon;
|
||
|
}
|
||
|
|
||
|
@Nullable
|
||
|
public String getKey() {
|
||
|
return this.mKey;
|
||
|
}
|
||
|
|
||
|
@Nullable
|
||
|
public CharSequence getName() {
|
||
|
return this.mName;
|
||
|
}
|
||
|
|
||
|
@Nullable
|
||
|
public String getUri() {
|
||
|
return this.mUri;
|
||
|
}
|
||
|
|
||
|
public boolean isBot() {
|
||
|
return this.mIsBot;
|
||
|
}
|
||
|
|
||
|
public boolean isImportant() {
|
||
|
return this.mIsImportant;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
@RequiresApi(28)
|
||
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
||
|
public android.app.Person toAndroidPerson() {
|
||
|
return new Person.Builder().setName(getName()).setIcon(getIcon() != null ? getIcon().toIcon() : null).setUri(getUri()).setKey(getKey()).setBot(isBot()).setImportant(isImportant()).build();
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Builder toBuilder() {
|
||
|
return new Builder(this);
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
public Bundle toBundle() {
|
||
|
Bundle bundle = new Bundle();
|
||
|
bundle.putCharSequence("name", this.mName);
|
||
|
IconCompat iconCompat = this.mIcon;
|
||
|
bundle.putBundle("icon", iconCompat != null ? iconCompat.toBundle() : null);
|
||
|
bundle.putString("uri", this.mUri);
|
||
|
bundle.putString("key", this.mKey);
|
||
|
bundle.putBoolean("isBot", this.mIsBot);
|
||
|
bundle.putBoolean("isImportant", this.mIsImportant);
|
||
|
return bundle;
|
||
|
}
|
||
|
|
||
|
@NonNull
|
||
|
@RequiresApi(22)
|
||
|
@RestrictTo({RestrictTo.Scope.LIBRARY_GROUP_PREFIX})
|
||
|
public PersistableBundle toPersistableBundle() {
|
||
|
PersistableBundle persistableBundle = new PersistableBundle();
|
||
|
CharSequence charSequence = this.mName;
|
||
|
persistableBundle.putString("name", charSequence != null ? charSequence.toString() : null);
|
||
|
persistableBundle.putString("uri", this.mUri);
|
||
|
persistableBundle.putString("key", this.mKey);
|
||
|
persistableBundle.putBoolean("isBot", this.mIsBot);
|
||
|
persistableBundle.putBoolean("isImportant", this.mIsImportant);
|
||
|
return persistableBundle;
|
||
|
}
|
||
|
}
|