/* * Copyright 2022 The Android Open Source Project * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package androidx.appsearch.builtintypes; import android.net.Uri; import androidx.annotation.IntDef; import androidx.annotation.NonNull; import androidx.annotation.Nullable; import androidx.annotation.RestrictTo; import androidx.appsearch.annotation.Document; import androidx.appsearch.app.AppSearchSchema.StringPropertyConfig; import androidx.core.util.Preconditions; import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.util.ArrayList; import java.util.Collections; import java.util.List; /** * AppSearch document representing a Person entity modeled after * Person. * *
The {@link Person} document includes commonly searchable properties such as name,
* organization, and notes, as well as contact information such as phone numbers, email
* addresses, etc, grouped by their label. The labeled contact information is present in a nested
* {@link ContactPoint} document.
*/
@Document(name = "builtin:Person")
public class Person extends Thing {
/** Holds type information for additional names for Person. */
public static class AdditionalName {
/** @hide */
@RestrictTo(RestrictTo.Scope.LIBRARY)
@IntDef({
TYPE_UNKNOWN,
TYPE_NICKNAME,
TYPE_PHONETIC_NAME
})
@Retention(RetentionPolicy.SOURCE)
public @interface NameType {
}
/** The additional name is unknown. */
public static final int TYPE_UNKNOWN = 0;
/** The additional name is a nickname. */
public static final int TYPE_NICKNAME = 1;
/** The additional name is a phonetic name. */
public static final int TYPE_PHONETIC_NAME = 2;
@NameType
private final int mType;
private final String mValue;
/**
* Constructs an {@link AdditionalName}.
*/
public AdditionalName(@NameType int type,
@NonNull String value) {
mType = Preconditions.checkArgumentInRange(type, TYPE_UNKNOWN, TYPE_PHONETIC_NAME,
"type");
mValue = value;
}
@NameType
public int getType() {
return mType;
}
@NonNull
public String getValue() {
return mValue;
}
@Override
public boolean equals(@Nullable Object other) {
if (this == other) {
return true;
}
if (!(other instanceof AdditionalName)) {
return false;
}
return mType == ((AdditionalName) other).mType && mValue.equals(
((AdditionalName) other).mValue);
}
@Override
public int hashCode() {
String str = mType + mValue;
return str.hashCode();
}
}
@Document.StringProperty
private final String mGivenName;
@Document.StringProperty
private final String mMiddleName;
@Document.StringProperty
private final String mFamilyName;
@Document.StringProperty
final String mExternalUri;
@Document.StringProperty
final String mImageUri;
@Document.BooleanProperty
final boolean mIsImportant;
@Document.BooleanProperty
final boolean mIsBot;
@Document.StringProperty(indexingType = StringPropertyConfig.INDEXING_TYPE_PREFIXES)
private final List For a Person with multiple middle names, this method returns a flattened and whitespace
* separated list. For example, "middle1 middle2 ..."
*/
@Nullable
public String getMiddleName() {
return mMiddleName;
}
/** Returns the family (or last) name for this {@link Person}. */
@Nullable
public String getFamilyName() {
return mFamilyName;
}
/**
* Returns an external uri for this {@link Person}. Or {@code null} if no {@link Uri} is
* provided. A {@link Uri} can be any of the following:
*
* For mailto: and tel: URI schemes, it is recommended that the path portion
* refers to a valid contact in the Contacts Provider.
*/
@Nullable
public Uri getExternalUri() {
if (mExternalUri != null) {
return Uri.parse(mExternalUri);
}
return null;
}
/** Returns {@link Uri} of the profile image for this {@link Person}. */
@Nullable
public Uri getImageUri() {
if (mImageUri != null) {
return Uri.parse(mImageUri);
}
return null;
}
/**
* Returns whether this {@link Person} is important to the user of this device with
* regards to how frequently they interact.
*/
public boolean isImportant() {
return mIsImportant;
}
/** Returns whether this {@link Person} is a machine rather than a human. */
public boolean isBot() {
return mIsBot;
}
/** Returns the notes about this {@link Person}. */
@NonNull
public List Additional names can include something like phonetic names, or nicknames.
*
* Different from {@link #getTypedAdditionalNames()}, the return value doesn't include
* type information for the additional names.
*/
@NonNull
public List Additional names can include something like phonetic names, or nicknames.
*
* Each {@link AdditionalName} contains type information for the additional name.
*/
@NonNull
public List For a contact with the title "Software Engineer" in a department "Engineering" at a
* company "Cloud Company", this can include a flattened value of "Software Engineer,
* Engineering, Cloud Company".
*/
@NonNull
public List More information can be found in {@link ContactPoint}.
*/
@NonNull
public List For {@link Person} with multiple middle names, they can all be set in this
* single string. Each middle name could be separated by a whitespace like "middleName1
* middleName2 middleName3".
*/
@NonNull
public T setMiddleName(@NonNull String middleName) {
mMiddleName = Preconditions.checkNotNull(middleName);
return (T) this;
}
/** Sets the family name of this {@link Person}. */
@NonNull
public T setFamilyName(@NonNull String familyName) {
mFamilyName = Preconditions.checkNotNull(familyName);
return (T) this;
}
/**
* Sets an external {@link Uri} for this {@link Person}. Or {@code null} if no
* {@link Uri} is provided. A {@link Uri} can be any of the following:
*
* For mailto: and tel: URI schemes, it is recommended that the path
* portion refers to a valid contact in the Contacts Provider.
*/
@NonNull
public T setExternalUri(@NonNull Uri externalUri) {
mExternalUri = Preconditions.checkNotNull(externalUri);
return (T) this;
}
/** Sets the {@link Uri} of the profile image for the {@link Person}. */
@NonNull
public T setImageUri(@NonNull Uri imageUri) {
mImageUri = Preconditions.checkNotNull(imageUri);
return (T) this;
}
/** Sets whether this {@link Person} is important. */
@NonNull
public T setImportant(boolean isImportant) {
mIsImportant = isImportant;
return (T) this;
}
/** Sets whether this {@link Person} is a bot. */
@NonNull
public T setBot(boolean isBot) {
mIsBot = isBot;
return (T) this;
}
/** Sets the notes about this {@link Person}. */
@NonNull
public T setNotes(@NonNull List Only types defined in {@link AdditionalName.NameType} are accepted.
*/
@NonNull
public T setAdditionalNames(@NonNull List More information could be found in {@link ContactPoint}.
*/
@NonNull
public T setContactPoints(@NonNull List