Allowing the notification to be a bit bigger for the remote input history
This also fixed the squishing when heads-upped by only allowing
one remote input text to be visible when heads upped.
Change-Id: I0c77931233b452420dee4dcf4772092d96d214c9
Fixes: 78877946
Test: add inbox style with 6 entries, reply a few times, observe no squishing
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index 526888d..ebd416c 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -4902,7 +4902,8 @@
CharSequence[] replyText = mN.extras.getCharSequenceArray(EXTRA_REMOTE_INPUT_HISTORY);
if (!p.ambient && validRemoteInput && replyText != null
- && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])) {
+ && replyText.length > 0 && !TextUtils.isEmpty(replyText[0])
+ && p.maxRemoteInputHistory > 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,
@@ -4917,13 +4918,15 @@
ColorStateList.valueOf(
isColorized() ? getPrimaryTextColor() : resolveContrastColor()));
- if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])) {
+ if (replyText.length > 1 && !TextUtils.isEmpty(replyText[1])
+ && p.maxRemoteInputHistory > 1) {
big.setViewVisibility(R.id.notification_material_reply_text_2, View.VISIBLE);
big.setTextViewText(R.id.notification_material_reply_text_2,
processTextSpans(replyText[1]));
setTextViewColorSecondary(big, R.id.notification_material_reply_text_2);
- if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])) {
+ if (replyText.length > 2 && !TextUtils.isEmpty(replyText[2])
+ && p.maxRemoteInputHistory > 2) {
big.setViewVisibility(
R.id.notification_material_reply_text_3, View.VISIBLE);
big.setTextViewText(R.id.notification_material_reply_text_3,
@@ -5086,7 +5089,13 @@
return null;
}
- return applyStandardTemplateWithActions(getBigBaseLayoutResource(), null /* result */);
+ // We only want at most a single remote input history to be shown here, otherwise
+ // the content would become squished.
+ StandardTemplateParams p = mParams.reset().fillTextsFrom(this)
+ .setMaxRemoteInputHistory(1);
+ return applyStandardTemplateWithActions(getBigBaseLayoutResource(),
+ p,
+ null /* result */);
}
/**
@@ -5955,6 +5964,12 @@
* object.
*/
public static abstract class Style {
+
+ /**
+ * The number of items allowed simulatanously in the remote input history.
+ * @hide
+ */
+ static final int MAX_REMOTE_INPUT_HISTORY_LINES = 3;
private CharSequence mBigContentTitle;
/**
@@ -7414,6 +7429,11 @@
* @see Notification#bigContentView
*/
public static class InboxStyle extends Style {
+
+ /**
+ * The number of lines of remote input history allowed until we start reducing lines.
+ */
+ private static final int NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION = 1;
private ArrayList<CharSequence> mTexts = new ArrayList<CharSequence>(5);
public InboxStyle() {
@@ -7513,6 +7533,28 @@
if (mBuilder.mActions.size() > 0) {
maxRows--;
}
+ CharSequence[] remoteInputHistory = mBuilder.mN.extras.getCharSequenceArray(
+ EXTRA_REMOTE_INPUT_HISTORY);
+ if (remoteInputHistory != null
+ && remoteInputHistory.length > NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION) {
+ // Let's remove some messages to make room for the remote input history.
+ // 1 is always able to fit, but let's remove them if they are 2 or 3
+ int numRemoteInputs = Math.min(remoteInputHistory.length,
+ MAX_REMOTE_INPUT_HISTORY_LINES);
+ int totalNumRows = mTexts.size() + numRemoteInputs
+ - NUMBER_OF_HISTORY_ALLOWED_UNTIL_REDUCTION;
+ if (totalNumRows > maxRows) {
+ int overflow = totalNumRows - maxRows;
+ if (mTexts.size() > maxRows) {
+ // Heuristic: if the Texts don't fit anyway, we'll rather drop the last
+ // few messages, even with the remote input
+ maxRows -= overflow;
+ } else {
+ // otherwise we drop the first messages
+ i = overflow;
+ }
+ }
+ }
while (i < mTexts.size() && i < maxRows) {
CharSequence str = mTexts.get(i);
if (!TextUtils.isEmpty(str)) {
@@ -9583,6 +9625,7 @@
CharSequence title;
CharSequence text;
CharSequence headerTextSecondary;
+ int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES;
boolean hideLargeIcon;
boolean hideReplyIcon;
@@ -9592,6 +9635,7 @@
title = null;
text = null;
headerTextSecondary = null;
+ maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES;
return this;
}
@@ -9643,5 +9687,15 @@
this.text = b.processLegacyText(text, ambient);
return this;
}
+
+ /**
+ * Set the maximum lines of remote input history lines allowed.
+ * @param maxRemoteInputHistory The number of lines.
+ * @return The builder for method chaining.
+ */
+ public StandardTemplateParams setMaxRemoteInputHistory(int maxRemoteInputHistory) {
+ this.maxRemoteInputHistory = maxRemoteInputHistory;
+ return this;
+ }
}
}