diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index f8c9a9ecf4c83..7222e8650a088 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -5013,6 +5013,7 @@ public class Notification implements Parcelable
bindNotificationHeader(contentView, p);
bindLargeIconAndApplyMargin(contentView, p, result);
boolean showProgress = handleProgressBar(contentView, ex, p);
+ boolean hasSecondLine = showProgress;
if (p.hasTitle()) {
contentView.setViewVisibility(R.id.title, View.VISIBLE);
contentView.setTextViewText(R.id.title, processTextSpans(p.title));
@@ -5028,11 +5029,27 @@ public class Notification implements Parcelable
contentView.setTextViewText(textId, processTextSpans(p.text));
setTextViewColorSecondary(contentView, textId, p);
contentView.setViewVisibility(textId, View.VISIBLE);
+ hasSecondLine = true;
}
+ setHeaderlessVerticalMargins(contentView, p, hasSecondLine);
return contentView;
}
+ private static void setHeaderlessVerticalMargins(RemoteViews contentView,
+ StandardTemplateParams p, boolean hasSecondLine) {
+ if (!p.mHeaderless) {
+ return;
+ }
+ int marginDimen = hasSecondLine
+ ? R.dimen.notification_headerless_margin_twoline
+ : R.dimen.notification_headerless_margin_oneline;
+ contentView.setViewLayoutMarginDimen(R.id.notification_headerless_view_column,
+ RemoteViews.MARGIN_TOP, marginDimen);
+ contentView.setViewLayoutMarginDimen(R.id.notification_headerless_view_column,
+ RemoteViews.MARGIN_BOTTOM, marginDimen);
+ }
+
private CharSequence processTextSpans(CharSequence text) {
if (hasForegroundColor() || mInNightMode) {
return ContrastColorUtil.clearColorSpans(text);
@@ -6851,26 +6868,13 @@ public class Notification implements Parcelable
if (decorationType <= DevFlags.DECORATION_PARTIAL) {
template.removeFromParent(R.id.notification_top_line);
}
- if (decorationType != DevFlags.DECORATION_FULL_COMPATIBLE) {
- // Change the max content size from 60dp (the compatible size) to 48dp
- // (the constrained size). This is done by increasing the minimum margin
- // (implemented as top/bottom margins) and decreasing the extra margin
- // (implemented as the height of shrinkable top/bottom views in the column).
- template.setViewLayoutMarginDimen(
- R.id.notification_headerless_view_column,
- RemoteViews.MARGIN_TOP,
- R.dimen.notification_headerless_margin_constrained_minimum);
- template.setViewLayoutMarginDimen(
- R.id.notification_headerless_view_column,
- RemoteViews.MARGIN_BOTTOM,
- R.dimen.notification_headerless_margin_constrained_minimum);
- template.setViewLayoutHeightDimen(
- R.id.notification_headerless_margin_extra_top,
- R.dimen.notification_headerless_margin_constrained_extra);
- template.setViewLayoutHeightDimen(
- R.id.notification_headerless_margin_extra_bottom,
- R.dimen.notification_headerless_margin_constrained_extra);
- }
+ // The vertical margins are bigger in the "two-line" scenario than the "one-line"
+ // scenario, but the 'compatible' decoration state is intended to have 3 lines,
+ // (1 for the top line views and 2 for the custom views), so in that one case we
+ // use the smaller 1-line margins. This gives the compatible case 88-16*2=56 dp of
+ // height, 24dp of which goes to the top line, leaving 32dp for the custom view.
+ boolean hasSecondLine = decorationType != DevFlags.DECORATION_FULL_COMPATIBLE;
+ Builder.setHeaderlessVerticalMargins(template, p, hasSecondLine);
} else {
// also update the end margin to account for the large icon or expander
Resources resources = context.getResources();
diff --git a/core/java/com/android/internal/widget/NotificationVanishingFrameLayout.java b/core/java/com/android/internal/widget/NotificationVanishingFrameLayout.java
new file mode 100644
index 0000000000000..742bdfdde7560
--- /dev/null
+++ b/core/java/com/android/internal/widget/NotificationVanishingFrameLayout.java
@@ -0,0 +1,70 @@
+/*
+ * Copyright (C) 2021 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package com.android.internal.widget;
+
+import android.annotation.Nullable;
+import android.content.Context;
+import android.util.AttributeSet;
+import android.view.View;
+import android.widget.FrameLayout;
+import android.widget.RemoteViews;
+
+/**
+ * This view will measure itself as having 0 size if all of its children are {@link #GONE}.
+ * Otherwise it acts like a normal {@link FrameLayout}.
+ */
+@RemoteViews.RemoteView
+public class NotificationVanishingFrameLayout extends FrameLayout {
+ public NotificationVanishingFrameLayout(Context context) {
+ this(context, null, 0, 0);
+ }
+
+ public NotificationVanishingFrameLayout(Context context, @Nullable AttributeSet attrs) {
+ this(context, attrs, 0, 0);
+ }
+
+ public NotificationVanishingFrameLayout(Context context, @Nullable AttributeSet attrs,
+ int defStyleAttr) {
+ this(context, attrs, defStyleAttr, 0);
+ }
+
+ public NotificationVanishingFrameLayout(Context context, AttributeSet attrs, int defStyleAttr,
+ int defStyleRes) {
+ super(context, attrs, defStyleAttr, defStyleRes);
+ }
+
+ @Override
+ protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
+ if (allChildrenGone()) {
+ int zeroSpec = MeasureSpec.makeMeasureSpec(0, MeasureSpec.EXACTLY);
+ super.onMeasure(zeroSpec, zeroSpec);
+ } else {
+ super.onMeasure(widthMeasureSpec, heightMeasureSpec);
+ }
+ }
+
+ private boolean allChildrenGone() {
+ final int childCount = getChildCount();
+ for (int i = 0; i < childCount; i++) {
+ final View child = getChildAt(i);
+ if (child != null && child.getVisibility() != GONE) {
+ return false;
+ }
+ }
+ return true;
+ }
+}
diff --git a/core/res/res/layout/notification_template_material_base.xml b/core/res/res/layout/notification_template_material_base.xml
index d79cb74a3d534..b83611bcc1770 100644
--- a/core/res/res/layout/notification_template_material_base.xml
+++ b/core/res/res/layout/notification_template_material_base.xml
@@ -91,26 +91,11 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
- android:layout_marginBottom="@dimen/notification_headerless_margin_minimum"
- android:layout_marginTop="@dimen/notification_headerless_margin_minimum"
+ android:layout_marginBottom="@dimen/notification_headerless_margin_twoline"
+ android:layout_marginTop="@dimen/notification_headerless_margin_twoline"
android:orientation="vertical"
>
-
-
-
-
+ >
+
+
+
-
-
-
diff --git a/core/res/res/values/dimens.xml b/core/res/res/values/dimens.xml
index 695a831faf973..c2b6b99dcc1cf 100644
--- a/core/res/res/values/dimens.xml
+++ b/core/res/res/values/dimens.xml
@@ -319,26 +319,22 @@
1dp
-
- 8dp
+
+
+ 16dp
-
- 10dp
-
-
- 14dp
-
-
- 4dp
+
+
+ 20dp
- 20sp
+ 24dp
56dp
- 76dp
+ 88dp
64dp
@@ -738,10 +734,11 @@
280dp
- 52dp
+ 48dp
- 12dp
+ 20dp
+
16dp
@dimen/notification_icon_circle_size
diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml
index 7ad05de1bdd0a..a4dec227ad9ab 100644
--- a/core/res/res/values/symbols.xml
+++ b/core/res/res/values/symbols.xml
@@ -2895,8 +2895,6 @@
-
-
@@ -2918,8 +2916,8 @@
-
-
+
+