diff options
| author | Selim Cinek <cinek@google.com> | 2018-05-21 22:06:43 -0700 |
|---|---|---|
| committer | Selim Cinek <cinek@google.com> | 2018-05-22 19:00:35 -0700 |
| commit | bee4e074bbb791f7696233ce43bcf28a75dd1d99 (patch) | |
| tree | 33c5bb9b456116dea84e29ff94c467e44ae0cdc1 /core/java | |
| parent | 645c8671ed6aa3f4c5b0d405aa5360b113b30f16 (diff) | |
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
Diffstat (limited to 'core/java')
| -rw-r--r-- | core/java/android/app/Notification.java | 62 |
1 files changed, 58 insertions, 4 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 526888d09772..ebd416c76e5b 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -4902,7 +4902,8 @@ 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])) { + && 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 @@ public class Notification implements Parcelable 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 @@ public class Notification implements Parcelable 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 @@ public class Notification implements Parcelable * 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 @@ public class Notification implements Parcelable * @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 @@ public class Notification implements Parcelable 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 @@ public class Notification implements Parcelable CharSequence title; CharSequence text; CharSequence headerTextSecondary; + int maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; boolean hideLargeIcon; boolean hideReplyIcon; @@ -9592,6 +9635,7 @@ public class Notification implements Parcelable title = null; text = null; headerTextSecondary = null; + maxRemoteInputHistory = Style.MAX_REMOTE_INPUT_HISTORY_LINES; return this; } @@ -9643,5 +9687,15 @@ public class Notification implements Parcelable 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; + } } } |
