From e7238dd12595cb6be953aed4271636df90de17fc Mon Sep 17 00:00:00 2001
From: Selim Cinek
+ * Depending on user preferences, this annotation may allow the notification to pass + * through interruption filters, if this notification is of category {@link #CATEGORY_CALL} + * or {@link #CATEGORY_MESSAGE}. The addition of people may also cause this notification to + * appear more prominently in the user interface. + *
+ * + *+ * A person should usually contain a uri in order to benefit from the ranking boost. + * However, even if no uri is provided, it's beneficial to provide other people in the + * notification, such that listeners and voice only devices can announce and handle them + * properly. + *
+ * + * @param person the person to add. + * @see Notification#EXTRA_PEOPLE_LIST + */ + public Builder addPerson(Person person) { + mPersonList.add(person); return this; } @@ -4968,8 +5005,7 @@ public class Notification implements Parcelable mActions.toArray(mN.actions); } if (!mPersonList.isEmpty()) { - mN.extras.putStringArray(EXTRA_PEOPLE, - mPersonList.toArray(new String[mPersonList.size()])); + mN.extras.putParcelableArrayList(EXTRA_PEOPLE_LIST, mPersonList); } if (mN.bigContentView != null || mN.contentView != null || mN.headsUpContentView != null) { @@ -7102,6 +7138,176 @@ public class Notification implements Parcelable } } + /** + * A Person associated with this Notification. + */ + public static final class Person implements Parcelable { + @Nullable private CharSequence mName; + @Nullable private Icon mIcon; + @Nullable private String mUri; + @Nullable private String mKey; + + protected Person(Parcel in) { + mName = in.readCharSequence(); + if (in.readInt() != 0) { + mIcon = Icon.CREATOR.createFromParcel(in); + } + mUri = in.readString(); + mKey = in.readString(); + } + + /** + * Create a new person. + */ + public Person() { + } + + /** + * Give this person a name. + * + * @param name the name of this person + */ + public Person setName(@Nullable CharSequence name) { + this.mName = name; + return this; + } + + /** + * Add an icon for this person. + *+ * Depending on user preferences, adding a URI to a Person may allow the notification to + * pass through interruption filters, if this notification is of + * category {@link #CATEGORY_CALL} or {@link #CATEGORY_MESSAGE}. + * The addition of people may also cause this notification to appear more prominently in + * the user interface. + *
+ * + *+ * The person should be specified by the {@code String} representation of a + * {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}. + *
+ * + *The system will also attempt to resolve {@code mailto:} and {@code tel:} schema + * URIs. The path part of these URIs must exist in the contacts database, in the + * appropriate column, or the reference will be discarded as invalid. Telephone schema + * URIs will be resolved by {@link android.provider.ContactsContract.PhoneLookup}. + *
+ * + * @param uri a URI for the person + */ + public Person setUri(@Nullable String uri) { + mUri = uri; + return this; + } + + /** + * Add a key to this person in order to uniquely identify it. + * This is especially useful if the name doesn't uniquely identify this person or if the + * display name is a short handle of the actual name. + * + *If no key is provided, the name serves as as the key for the purpose of + * identification.
+ * + * @param key the key that uniquely identifies this person + */ + public Person setKey(@Nullable String key) { + mKey = key; + return this; + } + + + /** + * @return the uri provided for this person or {@code null} if no Uri was provided + */ + @Nullable + public String getUri() { + return mUri; + } + + /** + * @return the name provided for this person or {@code null} if no name was provided + */ + @Nullable + public CharSequence getName() { + return mName; + } + + /** + * @return the icon provided for this person or {@code null} if no icon was provided + */ + @Nullable + public Icon getIcon() { + return mIcon; + } + + /** + * @return the key provided for this person or {@code null} if no key was provided + */ + @Nullable + public String getKey() { + return mKey; + } + + /** + * @return the URI associated with this person, or "name:mName" otherwise + * @hide + */ + public String resolveToLegacyUri() { + if (mUri != null) { + return mUri; + } + if (mName != null) { + return "name:" + mName; + } + return ""; + } + + @Override + public int describeContents() { + return 0; + } + + @Override + public void writeToParcel(Parcel dest, @WriteFlags int flags) { + dest.writeCharSequence(mName); + if (mIcon != null) { + dest.writeInt(1); + mIcon.writeToParcel(dest, 0); + } else { + dest.writeInt(0); + } + dest.writeString(mUri); + dest.writeString(mKey); + } + + public static final Creator