Migrated the systemUI based notification header
Previously the notification header had a seperate implementation
in SystemUI from which the platform implementation was derived.
Now that everything is in the framework, we’re migrating the
implementation for notification groups.ß
Change-Id: Ia61a75bd6c85e1805d4364a9e7e4587a020c1271
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index f49c77d..6c0c3e8 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -58,7 +58,6 @@
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.reflect.Constructor;
-import java.text.NumberFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
@@ -2986,7 +2985,7 @@
}
private void resetStandardTemplate(RemoteViews contentView) {
- resetHeader(contentView);
+ resetNotificationHeader(contentView);
resetContentMargins(contentView);
contentView.setViewVisibility(R.id.right_icon, View.GONE);
contentView.setTextViewText(R.id.title, null);
@@ -2996,7 +2995,10 @@
contentView.setViewVisibility(R.id.progress, View.GONE);
}
- private void resetHeader(RemoteViews contentView) {
+ /**
+ * Resets the notification header to its original state
+ */
+ private void resetNotificationHeader(RemoteViews contentView) {
contentView.setImageViewResource(R.id.icon, 0);
contentView.setTextViewText(R.id.app_name_text, null);
contentView.setViewVisibility(R.id.chronometer, View.GONE);
@@ -3091,6 +3093,7 @@
private void bindNotificationHeader(RemoteViews contentView) {
bindSmallIcon(contentView);
+ bindChildCountColor(contentView);
bindHeaderAppName(contentView);
bindHeaderSubText(contentView);
bindContentInfo(contentView);
@@ -3098,6 +3101,10 @@
bindExpandButton(contentView);
}
+ private void bindChildCountColor(RemoteViews contentView) {
+ contentView.setTextColor(R.id.number_of_children, resolveColor());
+ }
+
private void bindContentInfo(RemoteViews contentView) {
boolean visible = false;
if (mN.extras.getCharSequence(EXTRA_INFO_TEXT) != null) {
@@ -3251,6 +3258,19 @@
return result;
}
+ /**
+ * Construct a RemoteViews for the final notification header only
+ *
+ * @hide
+ */
+ public RemoteViews makeNotificationHeader() {
+ RemoteViews header = new BuilderRemoteViews(mContext.getApplicationInfo(),
+ R.layout.notification_template_header);
+ resetNotificationHeader(header);
+ bindNotificationHeader(header);
+ return header;
+ }
+
private void hideLine1Text(RemoteViews result) {
result.setViewVisibility(R.id.text_line_1, View.GONE);
}
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java
index 46cd7ae..82f6c7f 100644
--- a/core/java/android/view/NotificationHeaderView.java
+++ b/core/java/android/view/NotificationHeaderView.java
@@ -23,6 +23,7 @@
import android.util.AttributeSet;
import android.widget.LinearLayout;
import android.widget.RemoteViews;
+import android.widget.TextView;
import java.util.ArrayList;
@@ -40,6 +41,7 @@
private HeaderTouchListener mTouchListener = new HeaderTouchListener();
private View mExpandButton;
private View mIcon;
+ private TextView mChildCount;
public NotificationHeaderView(Context context) {
this(context, null);
@@ -66,6 +68,7 @@
mSubTextView = findViewById(com.android.internal.R.id.header_sub_text);
mExpandButton = findViewById(com.android.internal.R.id.expand_button);
mIcon = findViewById(com.android.internal.R.id.icon);
+ mChildCount = (TextView) findViewById(com.android.internal.R.id.number_of_children);
}
@Override
@@ -132,6 +135,17 @@
updateTouchListener();
}
+ public void setChildCount(int childCount) {
+ if (childCount > 0) {
+ mChildCount.setText(getContext().getString(
+ com.android.internal.R.string.notification_children_count_bracketed,
+ childCount));
+ mChildCount.setVisibility(VISIBLE);
+ } else {
+ mChildCount.setVisibility(GONE);
+ }
+ }
+
public class HeaderTouchListener implements View.OnTouchListener {
private final ArrayList<Rect> mTouchRects = new ArrayList<>();
diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml
index 08e6d61..d6dd842 100644
--- a/core/res/res/values/strings.xml
+++ b/core/res/res/values/strings.xml
@@ -531,6 +531,9 @@
[CHAR LIMIT=4] -->
<string name="status_bar_notification_info_overflow">999+</string>
+ <!-- The number of notifications in the notification header. An example would be (2) or (12) -->
+ <string name="notification_children_count_bracketed">(<xliff:g id="notificationCount" example="1">%d</xliff:g>)</string>
+
<!-- The divider symbol between different parts of the notification header. not translatable [CHAR LIMIT=1] -->
<string name="notification_header_divider_symbol" translatable="false">•</string>
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 7be697a..9dbdaaa 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2345,6 +2345,7 @@
<java-symbol type="id" name="addToDictionaryButton" />
<java-symbol type="id" name="deleteButton" />
+ <java-symbol type="string" name="notification_children_count_bracketed" />
<java-symbol type="id" name="app_name_text" />
<java-symbol type="id" name="number_of_children" />
<java-symbol type="id" name="header_sub_text" />
@@ -2356,6 +2357,7 @@
<java-symbol type="id" name="content_info_divider" />
<java-symbol type="id" name="text_line_1" />
<java-symbol type="drawable" name="ic_arrow_up_14dp" />
+ <java-symbol type="dimen" name="notification_header_height" />
<java-symbol type="dimen" name="notification_big_picture_content_min_height_with_picture" />
<java-symbol type="dimen" name="notification_header_shrink_min_width" />
<java-symbol type="dimen" name="notification_content_margin_start" />