Merge "Migrated the Person class to its own file" into pi-dev
This commit is contained in:
@@ -5393,7 +5393,7 @@ package android.app {
|
||||
method public android.app.Notification.Builder addAction(android.app.Notification.Action);
|
||||
method public android.app.Notification.Builder addExtras(android.os.Bundle);
|
||||
method public deprecated android.app.Notification.Builder addPerson(java.lang.String);
|
||||
method public android.app.Notification.Builder addPerson(android.app.Notification.Person);
|
||||
method public android.app.Notification.Builder addPerson(android.app.Person);
|
||||
method public android.app.Notification build();
|
||||
method public android.widget.RemoteViews createBigContentView();
|
||||
method public android.widget.RemoteViews createContentView();
|
||||
@@ -5518,15 +5518,15 @@ package android.app {
|
||||
|
||||
public static class Notification.MessagingStyle extends android.app.Notification.Style {
|
||||
ctor public deprecated Notification.MessagingStyle(java.lang.CharSequence);
|
||||
ctor public Notification.MessagingStyle(android.app.Notification.Person);
|
||||
ctor public Notification.MessagingStyle(android.app.Person);
|
||||
method public android.app.Notification.MessagingStyle addHistoricMessage(android.app.Notification.MessagingStyle.Message);
|
||||
method public deprecated android.app.Notification.MessagingStyle addMessage(java.lang.CharSequence, long, java.lang.CharSequence);
|
||||
method public android.app.Notification.MessagingStyle addMessage(java.lang.CharSequence, long, android.app.Notification.Person);
|
||||
method public android.app.Notification.MessagingStyle addMessage(java.lang.CharSequence, long, android.app.Person);
|
||||
method public android.app.Notification.MessagingStyle addMessage(android.app.Notification.MessagingStyle.Message);
|
||||
method public java.lang.CharSequence getConversationTitle();
|
||||
method public java.util.List<android.app.Notification.MessagingStyle.Message> getHistoricMessages();
|
||||
method public java.util.List<android.app.Notification.MessagingStyle.Message> getMessages();
|
||||
method public android.app.Notification.Person getUser();
|
||||
method public android.app.Person getUser();
|
||||
method public deprecated java.lang.CharSequence getUserDisplayName();
|
||||
method public boolean isGroupConversation();
|
||||
method public android.app.Notification.MessagingStyle setConversationTitle(java.lang.CharSequence);
|
||||
@@ -5536,37 +5536,17 @@ package android.app {
|
||||
|
||||
public static final class Notification.MessagingStyle.Message {
|
||||
ctor public deprecated Notification.MessagingStyle.Message(java.lang.CharSequence, long, java.lang.CharSequence);
|
||||
ctor public Notification.MessagingStyle.Message(java.lang.CharSequence, long, android.app.Notification.Person);
|
||||
ctor public Notification.MessagingStyle.Message(java.lang.CharSequence, long, android.app.Person);
|
||||
method public java.lang.String getDataMimeType();
|
||||
method public android.net.Uri getDataUri();
|
||||
method public android.os.Bundle getExtras();
|
||||
method public deprecated java.lang.CharSequence getSender();
|
||||
method public android.app.Notification.Person getSenderPerson();
|
||||
method public android.app.Person getSenderPerson();
|
||||
method public java.lang.CharSequence getText();
|
||||
method public long getTimestamp();
|
||||
method public android.app.Notification.MessagingStyle.Message setData(java.lang.String, android.net.Uri);
|
||||
}
|
||||
|
||||
public static final class Notification.Person implements android.os.Parcelable {
|
||||
ctor protected Notification.Person(android.os.Parcel);
|
||||
ctor public Notification.Person();
|
||||
method public int describeContents();
|
||||
method public android.graphics.drawable.Icon getIcon();
|
||||
method public java.lang.String getKey();
|
||||
method public java.lang.CharSequence getName();
|
||||
method public java.lang.String getUri();
|
||||
method public boolean isBot();
|
||||
method public boolean isImportant();
|
||||
method public android.app.Notification.Person setBot(boolean);
|
||||
method public android.app.Notification.Person setIcon(android.graphics.drawable.Icon);
|
||||
method public android.app.Notification.Person setImportant(boolean);
|
||||
method public android.app.Notification.Person setKey(java.lang.String);
|
||||
method public android.app.Notification.Person setName(java.lang.CharSequence);
|
||||
method public android.app.Notification.Person setUri(java.lang.String);
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.app.Notification.Person> CREATOR;
|
||||
}
|
||||
|
||||
public static abstract class Notification.Style {
|
||||
ctor public Notification.Style();
|
||||
method public android.app.Notification build();
|
||||
@@ -5817,6 +5797,30 @@ package android.app {
|
||||
method public abstract void onSendFinished(android.app.PendingIntent, android.content.Intent, int, java.lang.String, android.os.Bundle);
|
||||
}
|
||||
|
||||
public final class Person implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method public android.graphics.drawable.Icon getIcon();
|
||||
method public java.lang.String getKey();
|
||||
method public java.lang.CharSequence getName();
|
||||
method public java.lang.String getUri();
|
||||
method public boolean isBot();
|
||||
method public boolean isImportant();
|
||||
method public android.app.Person.Builder toBuilder();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
field public static final android.os.Parcelable.Creator<android.app.Person> CREATOR;
|
||||
}
|
||||
|
||||
public static class Person.Builder {
|
||||
ctor public Person.Builder();
|
||||
method public android.app.Person build();
|
||||
method public android.app.Person.Builder setBot(boolean);
|
||||
method public android.app.Person.Builder setIcon(android.graphics.drawable.Icon);
|
||||
method public android.app.Person.Builder setImportant(boolean);
|
||||
method public android.app.Person.Builder setKey(java.lang.String);
|
||||
method public android.app.Person.Builder setName(java.lang.CharSequence);
|
||||
method public android.app.Person.Builder setUri(java.lang.String);
|
||||
}
|
||||
|
||||
public final class PictureInPictureParams implements android.os.Parcelable {
|
||||
method public int describeContents();
|
||||
method public void writeToParcel(android.os.Parcel, int);
|
||||
|
||||
@@ -3902,7 +3902,7 @@ public class Notification implements Parcelable
|
||||
* @deprecated use {@link #addPerson(Person)}
|
||||
*/
|
||||
public Builder addPerson(String uri) {
|
||||
addPerson(new Person().setUri(uri));
|
||||
addPerson(new Person.Builder().setUri(uri).build());
|
||||
return this;
|
||||
}
|
||||
|
||||
@@ -6384,7 +6384,7 @@ public class Notification implements Parcelable
|
||||
* @deprecated use {@code MessagingStyle(Person)}
|
||||
*/
|
||||
public MessagingStyle(@NonNull CharSequence userDisplayName) {
|
||||
this(new Person().setName(userDisplayName));
|
||||
this(new Person.Builder().setName(userDisplayName).build());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6489,7 +6489,7 @@ public class Notification implements Parcelable
|
||||
*/
|
||||
public MessagingStyle addMessage(CharSequence text, long timestamp, CharSequence sender) {
|
||||
return addMessage(text, timestamp,
|
||||
sender == null ? null : new Person().setName(sender));
|
||||
sender == null ? null : new Person.Builder().setName(sender).build());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6661,7 +6661,7 @@ public class Notification implements Parcelable
|
||||
mUser = extras.getParcelable(EXTRA_MESSAGING_PERSON);
|
||||
if (mUser == null) {
|
||||
CharSequence displayName = extras.getCharSequence(EXTRA_SELF_DISPLAY_NAME);
|
||||
mUser = new Person().setName(displayName);
|
||||
mUser = new Person.Builder().setName(displayName).build();
|
||||
}
|
||||
mConversationTitle = extras.getCharSequence(EXTRA_CONVERSATION_TITLE);
|
||||
Parcelable[] messages = extras.getParcelableArray(EXTRA_MESSAGES);
|
||||
@@ -6916,7 +6916,8 @@ public class Notification implements Parcelable
|
||||
* @deprecated use {@code Message(CharSequence, long, Person)}
|
||||
*/
|
||||
public Message(CharSequence text, long timestamp, CharSequence sender){
|
||||
this(text, timestamp, sender == null ? null : new Person().setName(sender));
|
||||
this(text, timestamp, sender == null ? null
|
||||
: new Person.Builder().setName(sender).build());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -6927,10 +6928,11 @@ public class Notification implements Parcelable
|
||||
* Should be <code>null</code> for messages by the current user, in which case
|
||||
* the platform will insert the user set in {@code MessagingStyle(Person)}.
|
||||
* <p>
|
||||
* The person provided should contain an Icon, set with {@link Person#setIcon(Icon)}
|
||||
* and also have a name provided with {@link Person#setName(CharSequence)}. If multiple
|
||||
* users have the same name, consider providing a key with {@link Person#setKey(String)}
|
||||
* in order to differentiate between the different users.
|
||||
* The person provided should contain an Icon, set with
|
||||
* {@link Person.Builder#setIcon(Icon)} and also have a name provided
|
||||
* with {@link Person.Builder#setName(CharSequence)}. If multiple users have the same
|
||||
* name, consider providing a key with {@link Person.Builder#setKey(String)} in order
|
||||
* to differentiate between the different users.
|
||||
* </p>
|
||||
*/
|
||||
public Message(CharSequence text, long timestamp, @Nullable Person sender){
|
||||
@@ -7092,7 +7094,7 @@ public class Notification implements Parcelable
|
||||
// the native api instead
|
||||
CharSequence senderName = bundle.getCharSequence(KEY_SENDER);
|
||||
if (senderName != null) {
|
||||
senderPerson = new Person().setName(senderName);
|
||||
senderPerson = new Person.Builder().setName(senderName).build();
|
||||
}
|
||||
}
|
||||
Message message = new Message(bundle.getCharSequence(KEY_TEXT),
|
||||
@@ -7787,217 +7789,6 @@ 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;
|
||||
private boolean mBot;
|
||||
private boolean mImportant;
|
||||
|
||||
protected Person(Parcel in) {
|
||||
mName = in.readCharSequence();
|
||||
if (in.readInt() != 0) {
|
||||
mIcon = Icon.CREATOR.createFromParcel(in);
|
||||
}
|
||||
mUri = in.readString();
|
||||
mKey = in.readString();
|
||||
mImportant = in.readBoolean();
|
||||
mBot = in.readBoolean();
|
||||
}
|
||||
|
||||
/**
|
||||
* 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.
|
||||
* <br />
|
||||
* This is currently only used for {@link MessagingStyle} notifications and should not be
|
||||
* provided otherwise, in order to save memory. The system will prefer this icon over any
|
||||
* images that are resolved from the URI.
|
||||
*
|
||||
* @param icon the icon of the person
|
||||
*/
|
||||
public Person setIcon(@Nullable Icon icon) {
|
||||
this.mIcon = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a URI associated with this person.
|
||||
*
|
||||
* <P>
|
||||
* 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.
|
||||
* </P>
|
||||
*
|
||||
* <P>
|
||||
* The person should be specified by the {@code String} representation of a
|
||||
* {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}.
|
||||
* </P>
|
||||
*
|
||||
* <P>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}.
|
||||
* </P>
|
||||
*
|
||||
* @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.
|
||||
*
|
||||
* <P>If no key is provided, the name serves as as the key for the purpose of
|
||||
* identification.</P>
|
||||
*
|
||||
* @param key the key that uniquely identifies this person
|
||||
*/
|
||||
public Person setKey(@Nullable String key) {
|
||||
mKey = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this is an important person. Use this method to denote users who frequently
|
||||
* interact with the user of this device, when it is not possible to refer to the user
|
||||
* by {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}.
|
||||
*
|
||||
* @param isImportant {@code true} if this is an important person, {@code false} otherwise.
|
||||
*/
|
||||
public Person setImportant(boolean isImportant) {
|
||||
mImportant = isImportant;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this person is a machine rather than a human.
|
||||
*
|
||||
* @param isBot {@code true} if this person is a machine, {@code false} otherwise.
|
||||
*/
|
||||
public Person setBot(boolean isBot) {
|
||||
mBot = isBot;
|
||||
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 whether this Person is a machine.
|
||||
*/
|
||||
public boolean isBot() {
|
||||
return mBot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this Person is important.
|
||||
*/
|
||||
public boolean isImportant() {
|
||||
return mImportant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
dest.writeBoolean(mImportant);
|
||||
dest.writeBoolean(mBot);
|
||||
}
|
||||
|
||||
public static final Creator<Person> CREATOR = new Creator<Person>() {
|
||||
@Override
|
||||
public Person createFromParcel(Parcel in) {
|
||||
return new Person(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Person[] newArray(int size) {
|
||||
return new Person[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// When adding a new Style subclass here, don't forget to update
|
||||
// Builder.getNotificationStyleClass.
|
||||
|
||||
|
||||
270
core/java/android/app/Person.java
Normal file
270
core/java/android/app/Person.java
Normal file
@@ -0,0 +1,270 @@
|
||||
/*
|
||||
* Copyright (C) 2018 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 android.app;
|
||||
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.graphics.drawable.Icon;
|
||||
import android.os.Parcel;
|
||||
import android.os.Parcelable;
|
||||
|
||||
/**
|
||||
* Provides an immutable reference to an entity that appears repeatedly on different surfaces of the
|
||||
* platform. For example, this could represent the sender of a message.
|
||||
*/
|
||||
public final class Person implements Parcelable {
|
||||
|
||||
@Nullable private CharSequence mName;
|
||||
@Nullable private Icon mIcon;
|
||||
@Nullable private String mUri;
|
||||
@Nullable private String mKey;
|
||||
private boolean mIsBot;
|
||||
private boolean mIsImportant;
|
||||
|
||||
private Person(Parcel in) {
|
||||
mName = in.readCharSequence();
|
||||
if (in.readInt() != 0) {
|
||||
mIcon = Icon.CREATOR.createFromParcel(in);
|
||||
}
|
||||
mUri = in.readString();
|
||||
mKey = in.readString();
|
||||
mIsImportant = in.readBoolean();
|
||||
mIsBot = in.readBoolean();
|
||||
}
|
||||
|
||||
private Person(Builder builder) {
|
||||
mName = builder.mName;
|
||||
mIcon = builder.mIcon;
|
||||
mUri = builder.mUri;
|
||||
mKey = builder.mKey;
|
||||
mIsBot = builder.mIsBot;
|
||||
mIsImportant = builder.mIsImportant;
|
||||
}
|
||||
|
||||
/** Creates and returns a new {@link Builder} initialized with this Person's data. */
|
||||
public Builder toBuilder() {
|
||||
return new Builder(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 whether this Person is a machine.
|
||||
*/
|
||||
public boolean isBot() {
|
||||
return mIsBot;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return whether this Person is important.
|
||||
*/
|
||||
public boolean isImportant() {
|
||||
return mIsImportant;
|
||||
}
|
||||
|
||||
/**
|
||||
* @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);
|
||||
dest.writeBoolean(mIsImportant);
|
||||
dest.writeBoolean(mIsBot);
|
||||
}
|
||||
|
||||
/** Builder for the immutable {@link Person} class. */
|
||||
public static class Builder {
|
||||
@Nullable private CharSequence mName;
|
||||
@Nullable private Icon mIcon;
|
||||
@Nullable private String mUri;
|
||||
@Nullable private String mKey;
|
||||
private boolean mIsBot;
|
||||
private boolean mIsImportant;
|
||||
|
||||
/** Creates a new, empty {@link Builder}. */
|
||||
public Builder() {
|
||||
}
|
||||
|
||||
private Builder(Person person) {
|
||||
mName = person.mName;
|
||||
mIcon = person.mIcon;
|
||||
mUri = person.mUri;
|
||||
mKey = person.mKey;
|
||||
mIsBot = person.mIsBot;
|
||||
mIsImportant = person.mIsImportant;
|
||||
}
|
||||
|
||||
/**
|
||||
* Give this person a name.
|
||||
*
|
||||
* @param name the name of this person.
|
||||
*/
|
||||
@NonNull
|
||||
public Person.Builder setName(@Nullable CharSequence name) {
|
||||
this.mName = name;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add an icon for this person.
|
||||
* <br />
|
||||
* The system will prefer this icon over any images that are resolved from the URI.
|
||||
*
|
||||
* @param icon the icon of the person.
|
||||
*/
|
||||
@NonNull
|
||||
public Person.Builder setIcon(@Nullable Icon icon) {
|
||||
this.mIcon = icon;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set a URI associated with this person.
|
||||
*
|
||||
* <P>
|
||||
* The person should be specified by the {@code String} representation of a
|
||||
* {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}.
|
||||
* </P>
|
||||
*
|
||||
* <P>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}.
|
||||
* </P>
|
||||
*
|
||||
* @param uri a URI for the person.
|
||||
*/
|
||||
@NonNull
|
||||
public Person.Builder 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.
|
||||
*
|
||||
* <P>If no key is provided, the name serves as the key for the purpose of
|
||||
* identification.</P>
|
||||
*
|
||||
* @param key the key that uniquely identifies this person.
|
||||
*/
|
||||
@NonNull
|
||||
public Person.Builder setKey(@Nullable String key) {
|
||||
mKey = key;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this is an important person. Use this method to denote users who frequently
|
||||
* interact with the user of this device when {@link #setUri(String)} isn't provided with
|
||||
* {@link android.provider.ContactsContract.Contacts#CONTENT_LOOKUP_URI}, and instead with
|
||||
* the {@code mailto:} or {@code tel:} schemas.
|
||||
*
|
||||
* @param isImportant {@code true} if this is an important person, {@code false} otherwise.
|
||||
*/
|
||||
@NonNull
|
||||
public Person.Builder setImportant(boolean isImportant) {
|
||||
mIsImportant = isImportant;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets whether this person is a machine rather than a human.
|
||||
*
|
||||
* @param isBot {@code true} if this person is a machine, {@code false} otherwise.
|
||||
*/
|
||||
@NonNull
|
||||
public Person.Builder setBot(boolean isBot) {
|
||||
mIsBot = isBot;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Creates and returns the {@link Person} this builder represents. */
|
||||
@NonNull
|
||||
public Person build() {
|
||||
return new Person(this);
|
||||
}
|
||||
}
|
||||
|
||||
public static final Creator<Person> CREATOR = new Creator<Person>() {
|
||||
@Override
|
||||
public Person createFromParcel(Parcel in) {
|
||||
return new Person(in);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Person[] newArray(int size) {
|
||||
return new Person[size];
|
||||
}
|
||||
};
|
||||
}
|
||||
@@ -28,6 +28,7 @@ import android.app.Notification.Builder;
|
||||
import android.app.NotificationChannel;
|
||||
import android.app.NotificationChannelGroup;
|
||||
import android.app.NotificationManager;
|
||||
import android.app.Person;
|
||||
import android.app.Service;
|
||||
import android.companion.CompanionDeviceManager;
|
||||
import android.content.ComponentName;
|
||||
@@ -1195,13 +1196,13 @@ public abstract class NotificationListenerService extends Service {
|
||||
*/
|
||||
private void maybePopulatePeople(Notification notification) {
|
||||
if (getContext().getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.P) {
|
||||
ArrayList<Notification.Person> people = notification.extras.getParcelableArrayList(
|
||||
ArrayList<Person> people = notification.extras.getParcelableArrayList(
|
||||
Notification.EXTRA_PEOPLE_LIST);
|
||||
if (people != null && people.isEmpty()) {
|
||||
int size = people.size();
|
||||
String[] peopleArray = new String[size];
|
||||
for (int i = 0; i < size; i++) {
|
||||
Notification.Person person = people.get(i);
|
||||
Person person = people.get(i);
|
||||
peopleArray[i] = person.resolveToLegacyUri();
|
||||
}
|
||||
notification.extras.putStringArray(Notification.EXTRA_PEOPLE, peopleArray);
|
||||
|
||||
@@ -20,7 +20,7 @@ import android.annotation.AttrRes;
|
||||
import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StyleRes;
|
||||
import android.app.Notification;
|
||||
import android.app.Person;
|
||||
import android.content.Context;
|
||||
import android.graphics.Point;
|
||||
import android.graphics.Rect;
|
||||
@@ -63,7 +63,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
|
||||
private boolean mFirstLayout;
|
||||
private boolean mIsHidingAnimated;
|
||||
private boolean mNeedsGeneratedAvatar;
|
||||
private Notification.Person mSender;
|
||||
private Person mSender;
|
||||
private boolean mImagesAtEnd;
|
||||
private ViewGroup mImageContainer;
|
||||
private MessagingImageMessage mIsolatedMessage;
|
||||
@@ -126,7 +126,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
|
||||
return position;
|
||||
}
|
||||
|
||||
public void setSender(Notification.Person sender, CharSequence nameOverride) {
|
||||
public void setSender(Person sender, CharSequence nameOverride) {
|
||||
mSender = sender;
|
||||
if (nameOverride == null) {
|
||||
nameOverride = sender.getName();
|
||||
@@ -466,7 +466,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
|
||||
return mNeedsGeneratedAvatar;
|
||||
}
|
||||
|
||||
public Notification.Person getSender() {
|
||||
public Person getSender() {
|
||||
return mSender;
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import android.annotation.NonNull;
|
||||
import android.annotation.Nullable;
|
||||
import android.annotation.StyleRes;
|
||||
import android.app.Notification;
|
||||
import android.app.Person;
|
||||
import android.content.Context;
|
||||
import android.graphics.Bitmap;
|
||||
import android.graphics.Canvas;
|
||||
@@ -79,7 +80,7 @@ public class MessagingLayout extends FrameLayout {
|
||||
private Icon mLargeIcon;
|
||||
private boolean mIsOneToOne;
|
||||
private ArrayList<MessagingGroup> mAddedGroups = new ArrayList<>();
|
||||
private Notification.Person mUser;
|
||||
private Person mUser;
|
||||
private CharSequence mNameReplacement;
|
||||
private boolean mDisplayImagesAtEnd;
|
||||
|
||||
@@ -160,7 +161,7 @@ public class MessagingLayout extends FrameLayout {
|
||||
for (int i = remoteInputHistory.length - 1; i >= 0; i--) {
|
||||
CharSequence message = remoteInputHistory[i];
|
||||
newMessages.add(new Notification.MessagingStyle.Message(
|
||||
message, 0, (Notification.Person) null));
|
||||
message, 0, (Person) null));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,13 +297,13 @@ public class MessagingLayout extends FrameLayout {
|
||||
mIsOneToOne = oneToOne;
|
||||
}
|
||||
|
||||
public void setUser(Notification.Person user) {
|
||||
public void setUser(Person user) {
|
||||
mUser = user;
|
||||
if (mUser.getIcon() == null) {
|
||||
Icon userIcon = Icon.createWithResource(getContext(),
|
||||
com.android.internal.R.drawable.messaging_user);
|
||||
userIcon.setTint(mLayoutColor);
|
||||
mUser.setIcon(userIcon);
|
||||
mUser = mUser.toBuilder().setIcon(userIcon).build();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -310,7 +311,7 @@ public class MessagingLayout extends FrameLayout {
|
||||
List<MessagingMessage> messages) {
|
||||
// Let's first find our groups!
|
||||
List<List<MessagingMessage>> groups = new ArrayList<>();
|
||||
List<Notification.Person> senders = new ArrayList<>();
|
||||
List<Person> senders = new ArrayList<>();
|
||||
|
||||
// Lets first find the groups
|
||||
findGroups(historicMessages, messages, groups, senders);
|
||||
@@ -320,7 +321,7 @@ public class MessagingLayout extends FrameLayout {
|
||||
}
|
||||
|
||||
private void createGroupViews(List<List<MessagingMessage>> groups,
|
||||
List<Notification.Person> senders) {
|
||||
List<Person> senders) {
|
||||
mGroups.clear();
|
||||
for (int groupIndex = 0; groupIndex < groups.size(); groupIndex++) {
|
||||
List<MessagingMessage> group = groups.get(groupIndex);
|
||||
@@ -339,7 +340,7 @@ public class MessagingLayout extends FrameLayout {
|
||||
}
|
||||
newGroup.setDisplayImagesAtEnd(mDisplayImagesAtEnd);
|
||||
newGroup.setLayoutColor(mLayoutColor);
|
||||
Notification.Person sender = senders.get(groupIndex);
|
||||
Person sender = senders.get(groupIndex);
|
||||
CharSequence nameOverride = null;
|
||||
if (sender != mUser && mNameReplacement != null) {
|
||||
nameOverride = mNameReplacement;
|
||||
@@ -357,7 +358,7 @@ public class MessagingLayout extends FrameLayout {
|
||||
|
||||
private void findGroups(List<MessagingMessage> historicMessages,
|
||||
List<MessagingMessage> messages, List<List<MessagingMessage>> groups,
|
||||
List<Notification.Person> senders) {
|
||||
List<Person> senders) {
|
||||
CharSequence currentSenderKey = null;
|
||||
List<MessagingMessage> currentGroup = null;
|
||||
int histSize = historicMessages.size();
|
||||
@@ -369,7 +370,7 @@ public class MessagingLayout extends FrameLayout {
|
||||
message = messages.get(i - histSize);
|
||||
}
|
||||
boolean isNewGroup = currentGroup == null;
|
||||
Notification.Person sender = message.getMessage().getSenderPerson();
|
||||
Person sender = message.getMessage().getSenderPerson();
|
||||
CharSequence key = sender == null ? null
|
||||
: sender.getKey() == null ? sender.getName() : sender.getKey();
|
||||
isNewGroup |= !TextUtils.equals(key, currentSenderKey);
|
||||
|
||||
@@ -18,6 +18,7 @@ package com.android.server.notification;
|
||||
|
||||
import android.annotation.Nullable;
|
||||
import android.app.Notification;
|
||||
import android.app.Person;
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.database.ContentObserver;
|
||||
@@ -332,8 +333,8 @@ public class ValidateNotificationPeople implements NotificationSignalExtractor {
|
||||
return array;
|
||||
}
|
||||
|
||||
if (arrayList.get(0) instanceof Notification.Person) {
|
||||
ArrayList<Notification.Person> list = (ArrayList<Notification.Person>) arrayList;
|
||||
if (arrayList.get(0) instanceof Person) {
|
||||
ArrayList<Person> list = (ArrayList<Person>) arrayList;
|
||||
final int N = list.size();
|
||||
String[] array = new String[N];
|
||||
for (int i = 0; i < N; i++) {
|
||||
|
||||
@@ -28,7 +28,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.ActivityManager;
|
||||
import android.app.Notification;
|
||||
import android.app.Notification.Person;
|
||||
import android.app.Person;
|
||||
import android.app.PendingIntent;
|
||||
import android.app.RemoteInput;
|
||||
import android.content.Context;
|
||||
@@ -193,13 +193,13 @@ public class NotificationTest extends UiServiceTestCase {
|
||||
Notification.Builder nM1 = new Notification.Builder(mContext, "test")
|
||||
.setStyle(new Notification.MessagingStyle("")
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
"a", 100, mock(Notification.Person.class))));
|
||||
"a", 100, mock(Person.class))));
|
||||
Notification.Builder nM2 = new Notification.Builder(mContext, "test")
|
||||
.setStyle(new Notification.MessagingStyle("")
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
"a", 100, mock(Notification.Person.class)))
|
||||
"a", 100, mock(Person.class)))
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
"b", 100, mock(Notification.Person.class)))
|
||||
"b", 100, mock(Person.class)))
|
||||
);
|
||||
|
||||
assertTrue(Notification.areStyledNotificationsVisiblyDifferent(nM1, nM2));
|
||||
@@ -257,11 +257,11 @@ public class NotificationTest extends UiServiceTestCase {
|
||||
Notification.Builder nM1 = new Notification.Builder(mContext, "test")
|
||||
.setStyle(new Notification.MessagingStyle("")
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
"a", 100, mock(Notification.Person.class))));
|
||||
"a", 100, mock(Person.class))));
|
||||
Notification.Builder nM2 = new Notification.Builder(mContext, "test")
|
||||
.setStyle(new Notification.MessagingStyle("")
|
||||
.addMessage(new Notification.MessagingStyle.Message(
|
||||
"a", 1000, mock(Notification.Person.class)))
|
||||
"a", 1000, mock(Person.class)))
|
||||
);
|
||||
|
||||
assertFalse(Notification.areStyledNotificationsVisiblyDifferent(nM1, nM2));
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package com.android.server.notification;
|
||||
|
||||
import android.app.Notification;
|
||||
import android.app.Person;
|
||||
import android.os.Bundle;
|
||||
import android.support.test.runner.AndroidJUnit4;
|
||||
import android.test.suitebuilder.annotation.SmallTest;
|
||||
@@ -158,10 +159,10 @@ public class ValidateNotificationPeopleTest extends UiServiceTestCase {
|
||||
public void testPeopleArrayList() throws Exception {
|
||||
Bundle bundle = new Bundle();
|
||||
String[] expected = { "name:test" , "tel:1234" };
|
||||
final ArrayList<Notification.Person> arrayList =
|
||||
final ArrayList<Person> arrayList =
|
||||
new ArrayList<>(expected.length);
|
||||
arrayList.add(new Notification.Person().setName("test"));
|
||||
arrayList.add(new Notification.Person().setUri(expected[1]));
|
||||
arrayList.add(new Person.Builder().setName("test").build());
|
||||
arrayList.add(new Person.Builder().setUri(expected[1]).build());
|
||||
bundle.putParcelableArrayList(Notification.EXTRA_PEOPLE_LIST, arrayList);
|
||||
String[] result = ValidateNotificationPeople.getExtraPeople(bundle);
|
||||
assertStringArrayEquals("testPeopleArrayList", expected, result);
|
||||
|
||||
Reference in New Issue
Block a user