From 33fbd2c9659d0560d3a310d0cd28f452d5a25cdb Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Fri, 27 May 2016 15:35:28 -0700 Subject: [PATCH] MessagingStyle: Generate EXTRA_TITLE and EXTRA_TEXT Generates an appropriate title and text for MessagingStyle Notifications, such that SystemUI can generate the appropriate oneline representation. Bug: 28934989 Change-Id: Ic23ed18bb9c4af21ad59626ca161ca7abb25a4e9 --- core/java/android/app/Notification.java | 33 +++++++++++++++++++++++++ core/res/res/values/strings.xml | 4 +++ core/res/res/values/symbols.xml | 1 + 3 files changed, 38 insertions(+) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index e108dd6e49660..83a20668b3b49 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -4479,6 +4479,35 @@ public class Notification implements Parcelable if (!mMessages.isEmpty()) { extras.putParcelableArray(EXTRA_MESSAGES, Message.getBundleArrayForMessages(mMessages)); } + + fixTitleAndTextExtras(extras); + } + + private void fixTitleAndTextExtras(Bundle extras) { + Message m = findLatestIncomingMessage(); + CharSequence text = (m == null) ? null : m.mText; + CharSequence sender = m == null ? null + : TextUtils.isEmpty(m.mSender) ? mUserDisplayName : m.mSender; + CharSequence title; + if (!TextUtils.isEmpty(mConversationTitle)) { + if (!TextUtils.isEmpty(sender)) { + BidiFormatter bidi = BidiFormatter.getInstance(); + title = mBuilder.mContext.getString( + com.android.internal.R.string.notification_messaging_title_template, + bidi.unicodeWrap(mConversationTitle), bidi.unicodeWrap(m.mSender)); + } else { + title = mConversationTitle; + } + } else { + title = sender; + } + + if (title != null) { + extras.putCharSequence(EXTRA_TITLE, title); + } + if (text != null) { + extras.putCharSequence(EXTRA_TEXT, text); + } } /** @@ -4524,6 +4553,10 @@ public class Notification implements Parcelable return m; } } + if (!mMessages.isEmpty()) { + // No incoming messages, fall back to outgoing message + return mMessages.get(mMessages.size() - 1); + } return null; } diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 3a288222c7055..dcd8d71472355 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -4289,6 +4289,10 @@ DO NOT TRANSLATE --> \u2026 + + %1$s: %2$s + + %1$d selected diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 9ab42a960c82e..02092ca55f9c2 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -2597,6 +2597,7 @@ +