From 457a10d29c151664fc274c06be7e44f813b12767 Mon Sep 17 00:00:00 2001 From: Jorim Jaggi Date: Mon, 8 Sep 2014 16:18:23 +0200 Subject: Restrict line count for BigTextStyle Also fixes paddings for the first line for InboxStyle notifications. Bug: 17161340 Change-Id: I00a92f256d9ccad7cfbcecb591e84bb0d68ba635 --- core/java/android/app/Notification.java | 36 ++++++++++++++++++++-- .../notification_template_material_inbox.xml | 2 +- 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 10839433e327..c831c25ae4a8 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -3386,8 +3386,16 @@ public class Notification implements Parcelable */ public static abstract class Style { private CharSequence mBigContentTitle; - private CharSequence mSummaryText = null; - private boolean mSummaryTextSet = false; + + /** + * @hide + */ + protected CharSequence mSummaryText = null; + + /** + * @hide + */ + protected boolean mSummaryTextSet = false; protected Builder mBuilder; @@ -3679,6 +3687,11 @@ public class Notification implements Parcelable * @see Notification#bigContentView */ public static class BigTextStyle extends Style { + + private static final int MAX_LINES = 13; + private static final int LINES_CONSUMED_BY_ACTIONS = 3; + private static final int LINES_CONSUMED_BY_SUMMARY = 2; + private CharSequence mBigText; public BigTextStyle() { @@ -3745,6 +3758,7 @@ public class Notification implements Parcelable contentView.setTextViewText(R.id.big_text, mBuilder.processLegacyText(mBigText)); contentView.setViewVisibility(R.id.big_text, View.VISIBLE); + contentView.setInt(R.id.big_text, "setMaxLines", calculateMaxLines()); contentView.setViewVisibility(R.id.text2, View.GONE); applyTopPadding(contentView); @@ -3756,6 +3770,24 @@ public class Notification implements Parcelable return contentView; } + private int calculateMaxLines() { + int lineCount = MAX_LINES; + boolean hasActions = mBuilder.mActions.size() > 0; + boolean hasSummary = (mSummaryTextSet ? mSummaryText : mBuilder.mSubText) != null; + if (hasActions) { + lineCount -= LINES_CONSUMED_BY_ACTIONS; + } + if (hasSummary) { + lineCount -= LINES_CONSUMED_BY_SUMMARY; + } + + // If we have less top padding at the top, we can fit less lines. + if (!mBuilder.mHasThreeLines) { + lineCount--; + } + return lineCount; + } + /** * @hide */ diff --git a/core/res/res/layout/notification_template_material_inbox.xml b/core/res/res/layout/notification_template_material_inbox.xml index 2382d1892c5a..8a66c3f36e2d 100644 --- a/core/res/res/layout/notification_template_material_inbox.xml +++ b/core/res/res/layout/notification_template_material_inbox.xml @@ -44,6 +44,7 @@ android:layout_width="match_parent" android:layout_weight="1" android:layout_height="0dp" + android:layout_marginEnd="8dp" android:orientation="horizontal" > -- cgit v1.2.3-59-g8ed1b