summaryrefslogtreecommitdiff
path: root/core/java
diff options
context:
space:
mode:
authorKenny Guy <kennyguy@google.com>2018-04-06 16:20:16 +0100
committerKenny Guy <kennyguy@google.com>2018-04-23 18:58:19 +0100
commita0f6de8ab2d78445fe0259ef0f5f00e25a3f7d19 (patch)
treef7736b33b39e8555619cdfd44c3cbfa05275081d /core/java
parent1f4d564713c0f1470fd823d6205be0324e7e4bfb (diff)
Add spinner for smart replies.
Add a spinner to MessagingGroup that is enabled when the user has clicked on a smart reply. Bug: 73607490 Test: atest SystemUiTests Change-Id: I4d892c19b5df2b443761819929a83f016967e217
Diffstat (limited to 'core/java')
-rw-r--r--core/java/android/app/Notification.java76
-rw-r--r--core/java/com/android/internal/widget/MessagingGroup.java50
-rw-r--r--core/java/com/android/internal/widget/MessagingLayout.java18
-rw-r--r--core/java/com/android/internal/widget/MessagingMessage.java3
4 files changed, 135 insertions, 12 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 4f88a03db435..4b153782aec7 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -972,6 +972,18 @@ public class Notification implements Parcelable
public static final String EXTRA_REMOTE_INPUT_HISTORY = "android.remoteInputHistory";
/**
+ * {@link #extras} key: boolean as supplied to
+ * {@link Builder#setShowRemoteInputSpinner(boolean)}.
+ *
+ * If set to true, then the view displaying the remote input history from
+ * {@link Builder#setRemoteInputHistory(CharSequence[])} will have a progress spinner.
+ *
+ * @see Builder#setShowRemoteInputSpinner(boolean)
+ * @hide
+ */
+ public static final String EXTRA_SHOW_REMOTE_INPUT_SPINNER = "android.remoteInputSpinner";
+
+ /**
* {@link #extras} key: this is a small piece of additional text as supplied to
* {@link Builder#setContentInfo(CharSequence)}.
*/
@@ -3537,6 +3549,15 @@ public class Notification implements Parcelable
}
/**
+ * Sets whether remote history entries view should have a spinner.
+ * @hide
+ */
+ public Builder setShowRemoteInputSpinner(boolean showSpinner) {
+ mN.extras.putBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER, showSpinner);
+ return this;
+ }
+
+ /**
* Sets the number of items this notification represents. May be displayed as a badge count
* for Launchers that support badging.
*/
@@ -4760,6 +4781,8 @@ public class Notification implements Parcelable
big.setViewVisibility(R.id.notification_material_reply_container, View.GONE);
big.setTextViewText(R.id.notification_material_reply_text_1, null);
+ big.setViewVisibility(R.id.notification_material_reply_text_1_container, View.GONE);
+ big.setViewVisibility(R.id.notification_material_reply_progress, View.GONE);
big.setViewVisibility(R.id.notification_material_reply_text_2, View.GONE);
big.setTextViewText(R.id.notification_material_reply_text_2, null);
@@ -4810,10 +4833,19 @@ public class Notification implements Parcelable
CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY);
if (!p.ambient && validRemoteInput && replyText != null
&& replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) {
+ boolean showSpinner = mN.extras.getBoolean(EXTRA_SHOW_REMOTE_INPUT_SPINNER);
big.setViewVisibility(R.id.notification_material_reply_container, View.VISIBLE);
+ big.setViewVisibility(R.id.notification_material_reply_text_1_container,
+ View.VISIBLE);
big.setTextViewText(R.id.notification_material_reply_text_1,
processTextSpans(replyText[0]));
setTextViewColorSecondary(big, R.id.notification_material_reply_text_1);
+ big.setViewVisibility(R.id.notification_material_reply_progress,
+ showSpinner ? View.VISIBLE : View.GONE);
+ big.setProgressIndeterminateTintList(
+ R.id.notification_material_reply_progress,
+ ColorStateList.valueOf(
+ isColorized() ? getPrimaryTextColor() : resolveContrastColor()));
if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) {
big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE);
@@ -6953,11 +6985,16 @@ public class Notification implements Parcelable
static final String KEY_DATA_MIME_TYPE = "type";
static final String KEY_DATA_URI= "uri";
static final String KEY_EXTRAS_BUNDLE = "extras";
+ static final String KEY_REMOTE_INPUT_HISTORY = "remote_input_history";
private final CharSequence mText;
private final long mTimestamp;
@Nullable
private final Person mSender;
+ /** True if this message was generated from the extra
+ * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}
+ */
+ private final boolean mRemoteInputHistory;
private Bundle mExtras = new Bundle();
private String mDataMimeType;
@@ -6996,9 +7033,33 @@ public class Notification implements Parcelable
* </p>
*/
public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender) {
+ this(text, timestamp, sender, false /* remoteHistory */);
+ }
+
+ /**
+ * Constructor
+ * @param text A {@link CharSequence} to be displayed as the message content
+ * @param timestamp Time at which the message arrived
+ * @param sender The {@link Person} who sent the message.
+ * 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)}.
+ * @param remoteInputHistory True if the messages was generated from the extra
+ * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}.
+ * <p>
+ * 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>
+ * @hide
+ */
+ public Message(@NonNull CharSequence text, long timestamp, @Nullable Person sender,
+ boolean remoteInputHistory) {
mText = text;
mTimestamp = timestamp;
mSender = sender;
+ mRemoteInputHistory = remoteInputHistory;
}
/**
@@ -7088,6 +7149,15 @@ public class Notification implements Parcelable
return mDataUri;
}
+ /**
+ * @return True if the message was generated from
+ * {@link Notification#EXTRA_REMOTE_INPUT_HISTORY}.
+ * @hide
+ */
+ public boolean isRemoteInputHistory() {
+ return mRemoteInputHistory;
+ }
+
private Bundle toBundle() {
Bundle bundle = new Bundle();
if (mText != null) {
@@ -7108,6 +7178,9 @@ public class Notification implements Parcelable
if (mExtras != null) {
bundle.putBundle(KEY_EXTRAS_BUNDLE, mExtras);
}
+ if (mRemoteInputHistory) {
+ bundle.putBoolean(KEY_REMOTE_INPUT_HISTORY, mRemoteInputHistory);
+ }
return bundle;
}
@@ -7159,7 +7232,8 @@ public class Notification implements Parcelable
}
Message message = new Message(bundle.getCharSequence(KEY_TEXT),
bundle.getLong(KEY_TIMESTAMP),
- senderPerson);
+ senderPerson,
+ bundle.getBoolean(KEY_REMOTE_INPUT_HISTORY, false));
if (bundle.containsKey(KEY_DATA_MIME_TYPE) &&
bundle.containsKey(KEY_DATA_URI)) {
message.setData(bundle.getString(KEY_DATA_MIME_TYPE),
diff --git a/core/java/com/android/internal/widget/MessagingGroup.java b/core/java/com/android/internal/widget/MessagingGroup.java
index 07d78fe2abda..627cf47dae68 100644
--- a/core/java/com/android/internal/widget/MessagingGroup.java
+++ b/core/java/com/android/internal/widget/MessagingGroup.java
@@ -22,6 +22,8 @@ import android.annotation.Nullable;
import android.annotation.StyleRes;
import android.app.Person;
import android.content.Context;
+import android.content.res.ColorStateList;
+import android.graphics.Color;
import android.graphics.Point;
import android.graphics.Rect;
import android.graphics.drawable.Icon;
@@ -29,6 +31,7 @@ import android.text.TextUtils;
import android.util.AttributeSet;
import android.util.DisplayMetrics;
import android.util.Pools;
+import android.util.TypedValue;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
@@ -36,6 +39,7 @@ import android.view.ViewParent;
import android.view.ViewTreeObserver;
import android.widget.ImageView;
import android.widget.LinearLayout;
+import android.widget.ProgressBar;
import android.widget.RemoteViews;
import com.android.internal.R;
@@ -58,6 +62,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
private CharSequence mAvatarName = "";
private Icon mAvatarIcon;
private int mTextColor;
+ private int mSendingTextColor;
private List<MessagingMessage> mMessages;
private ArrayList<MessagingMessage> mAddedMessages = new ArrayList<>();
private boolean mFirstLayout;
@@ -69,6 +74,8 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
private MessagingImageMessage mIsolatedMessage;
private boolean mTransformingImages;
private Point mDisplaySize = new Point();
+ private ProgressBar mSendingSpinner;
+ private View mSendingSpinnerContainer;
public MessagingGroup(@NonNull Context context) {
super(context);
@@ -96,6 +103,8 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
mSenderName.addOnLayoutChangeListener(MessagingLayout.MESSAGING_PROPERTY_ANIMATOR);
mAvatarView = findViewById(R.id.message_icon);
mImageContainer = findViewById(R.id.messaging_group_icon_container);
+ mSendingSpinner = findViewById(R.id.messaging_group_sending_progress);
+ mSendingSpinnerContainer = findViewById(R.id.messaging_group_sending_progress_container);
DisplayMetrics displayMetrics = getResources().getDisplayMetrics();
mDisplaySize.x = displayMetrics.widthPixels;
mDisplaySize.y = displayMetrics.heightPixels;
@@ -139,17 +148,37 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
mAvatarView.setVisibility(VISIBLE);
mSenderName.setVisibility(VISIBLE);
mTextColor = getNormalTextColor();
+ mSendingTextColor = calculateSendingTextColor();
+ }
+
+ public void setSending(boolean sending) {
+ int visibility = sending ? View.VISIBLE : View.GONE;
+ if (mSendingSpinnerContainer.getVisibility() != visibility) {
+ mSendingSpinnerContainer.setVisibility(visibility);
+ updateMessageColor();
+ }
}
private int getNormalTextColor() {
return mContext.getColor(R.color.notification_secondary_text_color_light);
}
+ private int calculateSendingTextColor() {
+ TypedValue alphaValue = new TypedValue();
+ mContext.getResources().getValue(
+ R.dimen.notification_secondary_text_disabled_alpha, alphaValue, true);
+ float alpha = alphaValue.getFloat();
+ return Color.valueOf(
+ Color.red(mTextColor),
+ Color.green(mTextColor),
+ Color.blue(mTextColor),
+ alpha).toArgb();
+ }
+
public void setAvatar(Icon icon) {
mAvatarIcon = icon;
mAvatarView.setImageIcon(icon);
mAvatarSymbol = "";
- mLayoutColor = 0;
mAvatarName = "";
}
@@ -321,13 +350,26 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
|| layoutColor != mLayoutColor) {
setAvatar(cachedIcon);
mAvatarSymbol = avatarSymbol;
- mLayoutColor = layoutColor;
+ setLayoutColor(layoutColor);
mAvatarName = avatarName;
}
}
public void setLayoutColor(int layoutColor) {
- mLayoutColor = layoutColor;
+ if (layoutColor != mLayoutColor){
+ mLayoutColor = layoutColor;
+ mSendingSpinner.setIndeterminateTintList(ColorStateList.valueOf(mLayoutColor));
+ }
+ }
+
+ private void updateMessageColor() {
+ if (mMessages != null) {
+ int color = mSendingSpinnerContainer.getVisibility() == View.VISIBLE
+ ? mSendingTextColor : mTextColor;
+ for (MessagingMessage message : mMessages) {
+ message.setColor(message.getMessage().isRemoteInputHistory() ? color : mTextColor);
+ }
+ }
}
public void setMessages(List<MessagingMessage> group) {
@@ -336,7 +378,6 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
MessagingImageMessage isolatedMessage = null;
for (int messageIndex = 0; messageIndex < group.size(); messageIndex++) {
MessagingMessage message = group.get(messageIndex);
- message.setColor(mTextColor);
if (message.getGroup() != this) {
message.setMessagingGroup(this);
mAddedMessages.add(message);
@@ -376,6 +417,7 @@ public class MessagingGroup extends LinearLayout implements MessagingLinearLayou
}
mIsolatedMessage = isolatedMessage;
mMessages = group;
+ updateMessageColor();
}
/**
diff --git a/core/java/com/android/internal/widget/MessagingLayout.java b/core/java/com/android/internal/widget/MessagingLayout.java
index f8236c78ac43..df20e639adf0 100644
--- a/core/java/com/android/internal/widget/MessagingLayout.java
+++ b/core/java/com/android/internal/widget/MessagingLayout.java
@@ -149,7 +149,9 @@ public class MessagingLayout extends FrameLayout {
}
addRemoteInputHistoryToMessages(newMessages,
extras.getCharSequenceArray(Notification.EXTRA_REMOTE_INPUT_HISTORY));
- bind(newMessages, newHistoricMessages);
+ boolean showSpinner =
+ extras.getBoolean(Notification.EXTRA_SHOW_REMOTE_INPUT_SPINNER, false);
+ bind(newMessages, newHistoricMessages, showSpinner);
}
private void addRemoteInputHistoryToMessages(
@@ -161,17 +163,18 @@ 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, (Person) null));
+ message, 0, (Person) null, true /* remoteHistory */));
}
}
private void bind(List<Notification.MessagingStyle.Message> newMessages,
- List<Notification.MessagingStyle.Message> newHistoricMessages) {
+ List<Notification.MessagingStyle.Message> newHistoricMessages,
+ boolean showSpinner) {
List<MessagingMessage> historicMessages = createMessages(newHistoricMessages,
true /* isHistoric */);
List<MessagingMessage> messages = createMessages(newMessages, false /* isHistoric */);
- addMessagesToGroups(historicMessages, messages);
+ addMessagesToGroups(historicMessages, messages, showSpinner);
// Let's remove the remaining messages
mMessages.forEach(REMOVE_MESSAGE);
@@ -308,7 +311,7 @@ public class MessagingLayout extends FrameLayout {
}
private void addMessagesToGroups(List<MessagingMessage> historicMessages,
- List<MessagingMessage> messages) {
+ List<MessagingMessage> messages, boolean showSpinner) {
// Let's first find our groups!
List<List<MessagingMessage>> groups = new ArrayList<>();
List<Person> senders = new ArrayList<>();
@@ -317,11 +320,11 @@ public class MessagingLayout extends FrameLayout {
findGroups(historicMessages, messages, groups, senders);
// Let's now create the views and reorder them accordingly
- createGroupViews(groups, senders);
+ createGroupViews(groups, senders, showSpinner);
}
private void createGroupViews(List<List<MessagingMessage>> groups,
- List<Person> senders) {
+ List<Person> senders, boolean showSpinner) {
mGroups.clear();
for (int groupIndex = 0; groupIndex < groups.size(); groupIndex++) {
List<MessagingMessage> group = groups.get(groupIndex);
@@ -346,6 +349,7 @@ public class MessagingLayout extends FrameLayout {
nameOverride = mNameReplacement;
}
newGroup.setSender(sender, nameOverride);
+ newGroup.setSending(groupIndex == (groups.size() - 1) && showSpinner);
mGroups.add(newGroup);
if (mMessagingLinearLayout.indexOfChild(newGroup) != groupIndex) {
diff --git a/core/java/com/android/internal/widget/MessagingMessage.java b/core/java/com/android/internal/widget/MessagingMessage.java
index a2cc7cfb856c..f0b60685b70e 100644
--- a/core/java/com/android/internal/widget/MessagingMessage.java
+++ b/core/java/com/android/internal/widget/MessagingMessage.java
@@ -82,6 +82,9 @@ public interface MessagingMessage extends MessagingLinearLayout.MessagingChild {
if (!Objects.equals(message.getDataUri(), ownMessage.getDataUri())) {
return false;
}
+ if (message.isRemoteInputHistory() != ownMessage.isRemoteInputHistory()) {
+ return false;
+ }
return true;
}