summaryrefslogtreecommitdiff
path: root/core/java/android/app/Notification.java
diff options
context:
space:
mode:
authorSteve Elliott <steell@google.com>2020-03-17 11:04:09 -0400
committerSteve Elliott <steell@google.com>2020-03-18 13:23:51 -0400
commit46bb2a10a2275518fcc5fb5ec06d879b94eb91de (patch)
treea8f87dcee27d407b722f811d899574e80fc7a9bc /core/java/android/app/Notification.java
parentd955807e7a55e3f81b7746c296b744f1775fe63c (diff)
Populate conversation notifs from shortcut info
Fixes: 151330577 Test: manual Change-Id: Ib7b7037155fc1891935fcbe89ced9f1639378ba0
Diffstat (limited to 'core/java/android/app/Notification.java')
-rw-r--r--core/java/android/app/Notification.java99
1 files changed, 87 insertions, 12 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 864af3d4ae4d..1320d1d89566 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -21,7 +21,6 @@ import static android.graphics.drawable.Icon.TYPE_URI;
import static android.graphics.drawable.Icon.TYPE_URI_ADAPTIVE_BITMAP;
import static com.android.internal.util.ContrastColorUtil.satisfiesTextContrast;
-import static com.android.internal.widget.ConversationLayout.CONVERSATION_LAYOUT_ENABLED;
import android.annotation.ColorInt;
import android.annotation.DimenRes;
@@ -1229,6 +1228,9 @@ public class Notification implements Parcelable
*/
public static final String EXTRA_CONVERSATION_TITLE = "android.conversationTitle";
+ /** @hide */
+ public static final String EXTRA_CONVERSATION_ICON = "android.conversationIcon";
+
/**
* {@link #extras} key: an array of {@link android.app.Notification.MessagingStyle.Message}
* bundles provided by a
@@ -3576,7 +3578,6 @@ public class Notification implements Parcelable
}
}
}
-
}
}
@@ -6118,9 +6119,11 @@ public class Notification implements Parcelable
}
private int getMessagingLayoutResource() {
- return CONVERSATION_LAYOUT_ENABLED
- ? R.layout.notification_template_material_conversation
- : R.layout.notification_template_material_messaging;
+ return R.layout.notification_template_material_messaging;
+ }
+
+ private int getConversationLayoutResource() {
+ return R.layout.notification_template_material_conversation;
}
private int getActionLayoutResource() {
@@ -7078,11 +7081,28 @@ public class Notification implements Parcelable
*/
public static final int MAXIMUM_RETAINED_MESSAGES = 25;
+
+ /** @hide */
+ public static final int CONVERSATION_TYPE_LEGACY = 0;
+ /** @hide */
+ public static final int CONVERSATION_TYPE_NORMAL = 1;
+ /** @hide */
+ public static final int CONVERSATION_TYPE_IMPORTANT = 2;
+
+ /** @hide */
+ @IntDef(prefix = {"CONVERSATION_TYPE_"}, value = {
+ CONVERSATION_TYPE_LEGACY, CONVERSATION_TYPE_NORMAL, CONVERSATION_TYPE_IMPORTANT
+ })
+ @Retention(RetentionPolicy.SOURCE)
+ public @interface ConversationType {}
+
@NonNull Person mUser;
@Nullable CharSequence mConversationTitle;
+ @Nullable Icon mShortcutIcon;
List<Message> mMessages = new ArrayList<>();
List<Message> mHistoricMessages = new ArrayList<>();
boolean mIsGroupConversation;
+ @ConversationType int mConversationType = CONVERSATION_TYPE_LEGACY;
MessagingStyle() {
}
@@ -7160,6 +7180,11 @@ public class Notification implements Parcelable
/**
* Sets the title to be displayed on this conversation. May be set to {@code null}.
*
+ * <p>Starting in {@link Build.VERSION_CODES#R, this conversation title will be ignored if a
+ * valid shortcutId is added via {@link Notification.Builder#setShortcutId(String)}. In this
+ * case, {@link ShortcutInfo#getShortLabel()} will be shown as the conversation title
+ * instead.
+ *
* <p>This API's behavior was changed in SDK version {@link Build.VERSION_CODES#P}. If your
* application's target version is less than {@link Build.VERSION_CODES#P}, setting a
* conversation title to a non-null value will make {@link #isGroupConversation()} return
@@ -7184,6 +7209,46 @@ public class Notification implements Parcelable
}
/**
+ * Sets the icon to be displayed on the conversation, derived from the shortcutId.
+ *
+ * @hide
+ */
+ public MessagingStyle setShortcutIcon(@Nullable Icon conversationIcon) {
+ mShortcutIcon = conversationIcon;
+ return this;
+ }
+
+ /**
+ * Return the icon to be displayed on this conversation, derived from the shortcutId. May
+ * return {@code null}.
+ *
+ * @hide
+ */
+ @Nullable
+ public Icon getShortcutIcon() {
+ return mShortcutIcon;
+ }
+
+ /**
+ * Sets the conversation type of this MessageStyle notification.
+ * {@link #CONVERSATION_TYPE_LEGACY} will use the "older" layout from pre-R,
+ * {@link #CONVERSATION_TYPE_NORMAL} will use the new "conversation" layout, and
+ * {@link #CONVERSATION_TYPE_IMPORTANT} will add additional "important" treatments.
+ *
+ * @hide
+ */
+ public MessagingStyle setConversationType(@ConversationType int conversationType) {
+ mConversationType = conversationType;
+ return this;
+ }
+
+ /** @hide */
+ @ConversationType
+ public int getConversationType() {
+ return mConversationType;
+ }
+
+ /**
* Adds a message for display by this notification. Convenience call for a simple
* {@link Message} in {@link #addMessage(Notification.MessagingStyle.Message)}.
* @param text A {@link CharSequence} to be displayed as the message content
@@ -7334,6 +7399,9 @@ public class Notification implements Parcelable
if (!mHistoricMessages.isEmpty()) { extras.putParcelableArray(EXTRA_HISTORIC_MESSAGES,
Message.getBundleArrayForMessages(mHistoricMessages));
}
+ if (mShortcutIcon != null) {
+ extras.putParcelable(EXTRA_CONVERSATION_ICON, mShortcutIcon);
+ }
fixTitleAndTextExtras(extras);
extras.putBoolean(EXTRA_IS_GROUP_CONVERSATION, mIsGroupConversation);
@@ -7515,24 +7583,31 @@ public class Notification implements Parcelable
} else {
isOneToOne = !isGroupConversation();
}
+ boolean isConversationLayout = mConversationType != CONVERSATION_TYPE_LEGACY;
+ Icon largeIcon = isConversationLayout ? mShortcutIcon : mBuilder.mN.mLargeIcon;
TemplateBindResult bindResult = new TemplateBindResult();
- StandardTemplateParams p = mBuilder.mParams.reset().hasProgress(false).title(
- conversationTitle).text(null)
+ StandardTemplateParams p = mBuilder.mParams.reset()
+ .hasProgress(false)
+ .title(conversationTitle)
+ .text(null)
.hideLargeIcon(hideRightIcons || isOneToOne)
.hideReplyIcon(hideRightIcons)
.headerTextSecondary(conversationTitle);
RemoteViews contentView = mBuilder.applyStandardTemplateWithActions(
- mBuilder.getMessagingLayoutResource(),
+ isConversationLayout
+ ? mBuilder.getConversationLayoutResource()
+ : mBuilder.getMessagingLayoutResource(),
p,
bindResult);
addExtras(mBuilder.mN.extras);
- if (!CONVERSATION_LAYOUT_ENABLED) {
+ if (!isConversationLayout) {
// also update the end margin if there is an image
contentView.setViewLayoutMarginEnd(R.id.notification_messaging,
bindResult.getIconMarginEnd());
}
contentView.setInt(R.id.status_bar_latest_event_content, "setLayoutColor",
- mBuilder.isColorized(p) ? mBuilder.getPrimaryTextColor(p)
+ mBuilder.isColorized(p)
+ ? mBuilder.getPrimaryTextColor(p)
: mBuilder.resolveContrastColor(p));
contentView.setInt(R.id.status_bar_latest_event_content, "setSenderTextColor",
mBuilder.getPrimaryTextColor(p));
@@ -7552,7 +7627,7 @@ public class Notification implements Parcelable
contentView.setCharSequence(R.id.status_bar_latest_event_content,
"setConversationTitle", conversationTitle);
contentView.setIcon(R.id.status_bar_latest_event_content, "setLargeIcon",
- mBuilder.mN.mLargeIcon);
+ largeIcon);
contentView.setBundle(R.id.status_bar_latest_event_content, "setData",
mBuilder.mN.extras);
return contentView;
@@ -7615,7 +7690,7 @@ public class Notification implements Parcelable
public RemoteViews makeHeadsUpContentView(boolean increasedHeight) {
RemoteViews remoteViews = makeMessagingView(true /* isCollapsed */,
true /* hideLargeIcon */);
- if (!CONVERSATION_LAYOUT_ENABLED) {
+ if (mConversationType == CONVERSATION_TYPE_LEGACY) {
remoteViews.setInt(R.id.notification_messaging, "setMaxDisplayedLines", 1);
}
return remoteViews;