diff --git a/api/current.txt b/api/current.txt index e11b38925cbd6..70348b2845177 100644 --- a/api/current.txt +++ b/api/current.txt @@ -4979,7 +4979,7 @@ package android.app { field public int ledARGB; field public int ledOffMS; field public int ledOnMS; - field public int number; + field public deprecated int number; field public int priority; field public android.app.Notification publicVersion; field public android.net.Uri sound; @@ -5072,7 +5072,7 @@ package android.app { method public android.app.Notification.Builder setChronometerCountsDown(boolean); method public android.app.Notification.Builder setColor(int); method public deprecated android.app.Notification.Builder setContent(android.widget.RemoteViews); - method public android.app.Notification.Builder setContentInfo(java.lang.CharSequence); + method public deprecated android.app.Notification.Builder setContentInfo(java.lang.CharSequence); method public android.app.Notification.Builder setContentIntent(android.app.PendingIntent); method public android.app.Notification.Builder setContentText(java.lang.CharSequence); method public android.app.Notification.Builder setContentTitle(java.lang.CharSequence); @@ -5089,7 +5089,7 @@ package android.app { method public android.app.Notification.Builder setLargeIcon(android.graphics.drawable.Icon); method public android.app.Notification.Builder setLights(int, int, int); method public android.app.Notification.Builder setLocalOnly(boolean); - method public android.app.Notification.Builder setNumber(int); + method public deprecated android.app.Notification.Builder setNumber(int); method public android.app.Notification.Builder setOngoing(boolean); method public android.app.Notification.Builder setOnlyAlertOnce(boolean); method public android.app.Notification.Builder setPriority(int); diff --git a/api/system-current.txt b/api/system-current.txt index 98f70e29d1f9d..d6154b51b81cc 100644 --- a/api/system-current.txt +++ b/api/system-current.txt @@ -5112,7 +5112,7 @@ package android.app { field public int ledARGB; field public int ledOffMS; field public int ledOnMS; - field public int number; + field public deprecated int number; field public int priority; field public android.app.Notification publicVersion; field public android.net.Uri sound; @@ -5205,7 +5205,7 @@ package android.app { method public android.app.Notification.Builder setChronometerCountsDown(boolean); method public android.app.Notification.Builder setColor(int); method public deprecated android.app.Notification.Builder setContent(android.widget.RemoteViews); - method public android.app.Notification.Builder setContentInfo(java.lang.CharSequence); + method public deprecated android.app.Notification.Builder setContentInfo(java.lang.CharSequence); method public android.app.Notification.Builder setContentIntent(android.app.PendingIntent); method public android.app.Notification.Builder setContentText(java.lang.CharSequence); method public android.app.Notification.Builder setContentTitle(java.lang.CharSequence); @@ -5222,7 +5222,7 @@ package android.app { method public android.app.Notification.Builder setLargeIcon(android.graphics.drawable.Icon); method public android.app.Notification.Builder setLights(int, int, int); method public android.app.Notification.Builder setLocalOnly(boolean); - method public android.app.Notification.Builder setNumber(int); + method public deprecated android.app.Notification.Builder setNumber(int); method public android.app.Notification.Builder setOngoing(boolean); method public android.app.Notification.Builder setOnlyAlertOnce(boolean); method public android.app.Notification.Builder setPriority(int); diff --git a/api/test-current.txt b/api/test-current.txt index 11abb4c2b5256..3a20a04e62f68 100644 --- a/api/test-current.txt +++ b/api/test-current.txt @@ -4979,7 +4979,7 @@ package android.app { field public int ledARGB; field public int ledOffMS; field public int ledOnMS; - field public int number; + field public deprecated int number; field public int priority; field public android.app.Notification publicVersion; field public android.net.Uri sound; @@ -5072,7 +5072,7 @@ package android.app { method public android.app.Notification.Builder setChronometerCountsDown(boolean); method public android.app.Notification.Builder setColor(int); method public deprecated android.app.Notification.Builder setContent(android.widget.RemoteViews); - method public android.app.Notification.Builder setContentInfo(java.lang.CharSequence); + method public deprecated android.app.Notification.Builder setContentInfo(java.lang.CharSequence); method public android.app.Notification.Builder setContentIntent(android.app.PendingIntent); method public android.app.Notification.Builder setContentText(java.lang.CharSequence); method public android.app.Notification.Builder setContentTitle(java.lang.CharSequence); @@ -5089,7 +5089,7 @@ package android.app { method public android.app.Notification.Builder setLargeIcon(android.graphics.drawable.Icon); method public android.app.Notification.Builder setLights(int, int, int); method public android.app.Notification.Builder setLocalOnly(boolean); - method public android.app.Notification.Builder setNumber(int); + method public deprecated android.app.Notification.Builder setNumber(int); method public android.app.Notification.Builder setOngoing(boolean); method public android.app.Notification.Builder setOnlyAlertOnce(boolean); method public android.app.Notification.Builder setPriority(int); diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java index 8423de8827822..22562dd290e9a 100644 --- a/core/java/android/app/Notification.java +++ b/core/java/android/app/Notification.java @@ -206,6 +206,8 @@ public class Notification implements Parcelable * {@link Notification.Builder} has displayed the number in the expanded notification view. * * If the number is 0 or negative, it is never shown. + * + * @deprecated this number is not shown anymore */ public int number; @@ -2304,9 +2306,22 @@ public class Notification implements Parcelable } /** - * Set the third line of text in the platform notification template. - * Don't use if you're also using {@link #setProgress(int, int, boolean)}; they occupy the - * same location in the standard template. + * This provides some additional information that is displayed in the notification. No + * guarantees are given where exactly it is displayed. + * + *

This information should only be provided if it provides an essential + * benefit to the understanding of the notification. The more text you provide the + * less readable it becomes. For example, an email client should only provide the account + * name here if more than one email account has been added.

+ * + *

As of {@link android.os.Build.VERSION_CODES#N} this information is displayed in the + * notification header area. + * + * On Android versions before {@link android.os.Build.VERSION_CODES#N} + * this will be shown in the third line of text in the platform notification template. + * You should not be using {@link #setProgress(int, int, boolean)} at the + * same time on those versions; they occupy the same place. + *

*/ public Builder setSubText(CharSequence text) { mN.extras.putCharSequence(EXTRA_SUB_TEXT, safeCharSequence(text)); @@ -2345,6 +2360,8 @@ public class Notification implements Parcelable * Set the large number at the right-hand side of the notification. This is * equivalent to setContentInfo, although it might show the number in a different * font size for readability. + * + * @deprecated this number is not shown anywhere anymore */ public Builder setNumber(int number) { mN.number = number; @@ -2356,6 +2373,10 @@ public class Notification implements Parcelable * * The platform template will draw this on the last line of the notification, at the far * right (to the right of a smallIcon if it has been placed there). + * + * @deprecated use {@link #setSubText(CharSequence)} instead to set a text in the header. + * For legacy apps targeting a version below {@link android.os.Build.VERSION_CODES#N} this + * field will still show up, but the subtext will take precedence. */ public Builder setContentInfo(CharSequence info) { mN.extras.putCharSequence(EXTRA_INFO_TEXT, safeCharSequence(info)); @@ -3009,10 +3030,8 @@ public class Notification implements Parcelable contentView.setBoolean(R.id.notification_header, "setExpanded", false); contentView.setTextViewText(R.id.app_name_text, null); contentView.setViewVisibility(R.id.chronometer, View.GONE); - contentView.setViewVisibility(R.id.header_sub_text, View.GONE); - contentView.setViewVisibility(R.id.header_content_info, View.GONE); - contentView.setViewVisibility(R.id.sub_text_divider, View.GONE); - contentView.setViewVisibility(R.id.content_info_divider, View.GONE); + contentView.setViewVisibility(R.id.header_text, View.GONE); + contentView.setViewVisibility(R.id.header_text_divider, View.GONE); contentView.setViewVisibility(R.id.time_divider, View.GONE); contentView.setImageViewIcon(R.id.profile_badge, null); contentView.setViewVisibility(R.id.profile_badge, View.GONE); @@ -3112,39 +3131,12 @@ public class Notification implements Parcelable private void bindNotificationHeader(RemoteViews contentView) { bindSmallIcon(contentView); bindHeaderAppName(contentView); - bindHeaderSubText(contentView); - bindContentInfo(contentView); + bindHeaderText(contentView); bindHeaderChronometerAndTime(contentView); bindExpandButton(contentView); bindProfileBadge(contentView); } - private void bindContentInfo(RemoteViews contentView) { - boolean visible = false; - if (mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { - contentView.setTextViewText(R.id.header_content_info, - processLegacyText(mN.extras.getCharSequence(EXTRA_INFO_TEXT))); - contentView.setViewVisibility(R.id.header_content_info, View.VISIBLE); - visible = true; - } else if (mN.number > 0) { - final int tooBig = mContext.getResources().getInteger( - R.integer.status_bar_notification_info_maxnum); - if (mN.number > tooBig) { - contentView.setTextViewText(R.id.header_content_info, processLegacyText( - mContext.getResources().getString( - R.string.status_bar_notification_info_overflow))); - } else { - contentView.setTextViewText(R.id.header_content_info, - processLegacyText(String.valueOf(mN.number))); - } - contentView.setViewVisibility(R.id.header_content_info, View.VISIBLE); - visible = true; - } - if (visible) { - contentView.setViewVisibility(R.id.content_info_divider, View.VISIBLE); - } - } - private void bindExpandButton(RemoteViews contentView) { contentView.setDrawableParameters(R.id.expand_button, false, -1, resolveContrastColor(), PorterDuff.Mode.SRC_ATOP, -1); @@ -3169,17 +3161,22 @@ public class Notification implements Parcelable } } - private void bindHeaderSubText(RemoteViews contentView) { - CharSequence subText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); - if (subText == null && mStyle != null && mStyle.mSummaryTextSet + private void bindHeaderText(RemoteViews contentView) { + CharSequence headerText = mN.extras.getCharSequence(EXTRA_SUB_TEXT); + if (headerText == null && mStyle != null && mStyle.mSummaryTextSet && mStyle.hasSummaryInHeader()) { - subText = mStyle.mSummaryText; + headerText = mStyle.mSummaryText; } - if (subText != null) { + if (headerText == null + && mContext.getApplicationInfo().targetSdkVersion < Build.VERSION_CODES.N + && mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) { + headerText = mN.extras.getCharSequence(EXTRA_INFO_TEXT); + } + if (headerText != null) { // TODO: Remove the span entirely to only have the string with propper formating. - contentView.setTextViewText(R.id.header_sub_text, processLegacyText(subText)); - contentView.setViewVisibility(R.id.header_sub_text, View.VISIBLE); - contentView.setViewVisibility(R.id.sub_text_divider, View.VISIBLE); + contentView.setTextViewText(R.id.header_text, processLegacyText(headerText)); + contentView.setViewVisibility(R.id.header_text, View.VISIBLE); + contentView.setViewVisibility(R.id.header_text_divider, View.VISIBLE); } } diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index cff9d8e93c98a..37da8695a1ad9 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -22,7 +22,6 @@ import android.graphics.Rect; import android.util.AttributeSet; import android.widget.ImageView; import android.widget.RemoteViews; -import android.widget.TextView; import java.util.ArrayList; @@ -37,7 +36,7 @@ public class NotificationHeaderView extends ViewGroup { private final int mChildMinWidth; private final int mContentEndMargin; private View mAppName; - private View mSubTextView; + private View mHeaderText; private OnClickListener mExpandClickListener; private HeaderTouchListener mTouchListener = new HeaderTouchListener(); private ImageView mExpandButton; @@ -73,11 +72,10 @@ public class NotificationHeaderView extends ViewGroup { protected void onFinishInflate() { super.onFinishInflate(); mAppName = findViewById(com.android.internal.R.id.app_name_text); - mSubTextView = findViewById(com.android.internal.R.id.header_sub_text); + mHeaderText = findViewById(com.android.internal.R.id.header_text); mExpandButton = (ImageView) findViewById(com.android.internal.R.id.expand_button); mIcon = findViewById(com.android.internal.R.id.icon); mProfileBadge = findViewById(com.android.internal.R.id.profile_badge); - mInfo = findViewById(com.android.internal.R.id.header_content_info); } @Override @@ -105,15 +103,7 @@ public class NotificationHeaderView extends ViewGroup { } if (totalWidth > givenWidth) { int overFlow = totalWidth - givenWidth; - // We are overflowing, lets shrink the info first - final int infoWidth = mInfo.getMeasuredWidth(); - if (mInfo.getVisibility() != GONE && infoWidth > mChildMinWidth) { - int newSize = infoWidth - Math.min(infoWidth - mChildMinWidth, overFlow); - int childWidthSpec = MeasureSpec.makeMeasureSpec(newSize, MeasureSpec.AT_MOST); - mInfo.measure(childWidthSpec, wrapContentHeightSpec); - overFlow -= infoWidth - newSize; - } - // still overflowing, lets shrink the app name now + // We are overflowing, lets shrink the app name first final int appWidth = mAppName.getMeasuredWidth(); if (overFlow > 0 && mAppName.getVisibility() != GONE && appWidth > mChildMinWidth) { int newSize = appWidth - Math.min(appWidth - mChildMinWidth, overFlow); @@ -121,13 +111,13 @@ public class NotificationHeaderView extends ViewGroup { mAppName.measure(childWidthSpec, wrapContentHeightSpec); overFlow -= appWidth - newSize; } - // still overflowing, finaly we shrink the subtext - if (overFlow > 0 && mSubTextView.getVisibility() != GONE) { + // still overflowing, finaly we shrink the header text + if (overFlow > 0 && mHeaderText.getVisibility() != GONE) { // we're still too big - final int subTextWidth = mSubTextView.getMeasuredWidth(); - int newSize = Math.max(0, subTextWidth - overFlow); + final int textWidth = mHeaderText.getMeasuredWidth(); + int newSize = Math.max(0, textWidth - overFlow); int childWidthSpec = MeasureSpec.makeMeasureSpec(newSize, MeasureSpec.AT_MOST); - mSubTextView.measure(childWidthSpec, wrapContentHeightSpec); + mHeaderText.measure(childWidthSpec, wrapContentHeightSpec); } } setMeasuredDimension(givenWidth, givenHeight); diff --git a/core/res/res/layout/notification_template_header.xml b/core/res/res/layout/notification_template_header.xml index 0bbaa24a9ad4b..992e88e22ad9f 100644 --- a/core/res/res/layout/notification_template_header.xml +++ b/core/res/res/layout/notification_template_header.xml @@ -42,7 +42,7 @@ android:singleLine="true" /> - - - + - - - + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java index c70aad2d41988..06d79a7f91248 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/NotificationHeaderUtil.java @@ -131,11 +131,8 @@ public class NotificationHeaderUtil { mComparators.add(HeaderProcessor.forTextView(mRow, com.android.internal.R.id.app_name_text)); mComparators.add(HeaderProcessor.forTextView(mRow, - com.android.internal.R.id.header_sub_text)); - mComparators.add(HeaderProcessor.forTextView(mRow, - com.android.internal.R.id.header_content_info)); - mDividers.add(com.android.internal.R.id.sub_text_divider); - mDividers.add(com.android.internal.R.id.content_info_divider); + com.android.internal.R.id.header_text)); + mDividers.add(com.android.internal.R.id.header_text_divider); mDividers.add(com.android.internal.R.id.time_divider); } diff --git a/services/core/java/com/android/server/LockSettingsService.java b/services/core/java/com/android/server/LockSettingsService.java index ed16af51c7eb0..ab0f55ebb9656 100644 --- a/services/core/java/com/android/server/LockSettingsService.java +++ b/services/core/java/com/android/server/LockSettingsService.java @@ -254,7 +254,7 @@ public class LockSettingsService extends ILockSettings.Stub { com.android.internal.R.color.system_notification_accent_color)) .setContentTitle(title) .setContentText(message) - .setContentInfo(detail) + .setSubText(detail) .setVisibility(Notification.VISIBILITY_PUBLIC) .setContentIntent(intent) .build();