diff options
| author | 2017-11-02 20:54:16 +0000 | |
|---|---|---|
| committer | 2017-11-02 20:54:16 +0000 | |
| commit | 46fabf34ea9bca85188efc47b6b1f4b5d25c852f (patch) | |
| tree | ef3fb561ecf486d1df166065d67b9a739a50c58e | |
| parent | c10dcf2f3f44499897d9c9b6bd0b5c6a9966ee55 (diff) | |
| parent | bd9798f617c179a89cff51b4b79ab04996c62df7 (diff) | |
Merge "Center align AoD2 notifications"
| -rw-r--r-- | core/java/android/view/NotificationHeaderView.java | 14 | ||||
| -rw-r--r-- | core/java/com/android/internal/widget/NotificationActionListLayout.java | 30 | ||||
| -rw-r--r-- | core/res/res/layout/notification_template_header.xml | 1 | ||||
| -rw-r--r-- | core/res/res/layout/notification_template_material_ambient.xml | 23 | ||||
| -rw-r--r-- | core/res/res/values/attrs.xml | 8 | ||||
| -rw-r--r-- | core/res/res/values/styles_material.xml | 5 | ||||
| -rw-r--r-- | core/res/res/values/themes_material.xml | 3 |
7 files changed, 73 insertions, 11 deletions
diff --git a/core/java/android/view/NotificationHeaderView.java b/core/java/android/view/NotificationHeaderView.java index 580456023d68..ab0b3eec8753 100644 --- a/core/java/android/view/NotificationHeaderView.java +++ b/core/java/android/view/NotificationHeaderView.java @@ -20,6 +20,7 @@ import android.annotation.Nullable; import android.app.Notification; import android.content.Context; import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.Canvas; import android.graphics.Outline; import android.graphics.Rect; @@ -43,6 +44,7 @@ public class NotificationHeaderView extends ViewGroup { public static final int NO_COLOR = Notification.COLOR_INVALID; private final int mChildMinWidth; private final int mContentEndMargin; + private final int mGravity; private View mAppName; private View mHeaderText; private OnClickListener mExpandClickListener; @@ -50,7 +52,6 @@ public class NotificationHeaderView extends ViewGroup { private ImageView mExpandButton; private CachingIconView mIcon; private View mProfileBadge; - private View mInfo; private int mIconColor; private int mOriginalNotificationColor; private boolean mExpanded; @@ -61,6 +62,7 @@ public class NotificationHeaderView extends ViewGroup { private boolean mEntireHeaderClickable; private boolean mExpandOnlyOnButton; private boolean mAcceptAllTouches; + private int mTotalWidth; ViewOutlineProvider mProvider = new ViewOutlineProvider() { @Override @@ -92,6 +94,11 @@ public class NotificationHeaderView extends ViewGroup { mHeaderBackgroundHeight = res.getDimensionPixelSize( R.dimen.notification_header_background_height); mEntireHeaderClickable = res.getBoolean(R.bool.config_notificationHeaderClickableForExpand); + + int[] attrIds = { android.R.attr.gravity }; + TypedArray ta = context.obtainStyledAttributes(attrs, attrIds, defStyleAttr, defStyleRes); + mGravity = ta.getInt(0, 0); + ta.recycle(); } @Override @@ -146,6 +153,7 @@ public class NotificationHeaderView extends ViewGroup { mHeaderText.measure(childWidthSpec, wrapContentHeightSpec); } } + mTotalWidth = Math.min(totalWidth, givenWidth); setMeasuredDimension(givenWidth, givenHeight); } @@ -153,6 +161,10 @@ public class NotificationHeaderView extends ViewGroup { protected void onLayout(boolean changed, int l, int t, int r, int b) { int left = getPaddingStart(); int end = getMeasuredWidth(); + final boolean centerAligned = (mGravity & Gravity.CENTER_HORIZONTAL) != 0; + if (centerAligned) { + left += getMeasuredWidth() / 2 - mTotalWidth / 2; + } int childCount = getChildCount(); int ownHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom(); for (int i = 0; i < childCount; i++) { diff --git a/core/java/com/android/internal/widget/NotificationActionListLayout.java b/core/java/com/android/internal/widget/NotificationActionListLayout.java index 073aac542e31..26023b499919 100644 --- a/core/java/com/android/internal/widget/NotificationActionListLayout.java +++ b/core/java/com/android/internal/widget/NotificationActionListLayout.java @@ -16,7 +16,10 @@ package com.android.internal.widget; +import android.annotation.Nullable; import android.content.Context; +import android.content.res.Resources; +import android.content.res.TypedArray; import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Pair; @@ -37,6 +40,7 @@ import java.util.Comparator; @RemoteViews.RemoteView public class NotificationActionListLayout extends LinearLayout { + private final int mGravity; private int mTotalWidth = 0; private ArrayList<Pair<Integer, TextView>> mMeasureOrderTextViews = new ArrayList<>(); private ArrayList<View> mMeasureOrderOther = new ArrayList<>(); @@ -45,7 +49,20 @@ public class NotificationActionListLayout extends LinearLayout { private Drawable mDefaultBackground; public NotificationActionListLayout(Context context, AttributeSet attrs) { - super(context, attrs); + this(context, attrs, 0); + } + + public NotificationActionListLayout(Context context, AttributeSet attrs, int defStyleAttr) { + this(context, attrs, defStyleAttr, 0); + } + + public NotificationActionListLayout(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) { + super(context, attrs, defStyleAttr, defStyleRes); + + int[] attrIds = { android.R.attr.gravity }; + TypedArray ta = context.obtainStyledAttributes(attrs, attrIds, defStyleAttr, defStyleRes); + mGravity = ta.getInt(0, 0); + ta.recycle(); } @Override @@ -95,6 +112,7 @@ public class NotificationActionListLayout extends LinearLayout { final boolean constrained = MeasureSpec.getMode(widthMeasureSpec) != MeasureSpec.UNSPECIFIED; + final boolean centerAligned = (mGravity & Gravity.CENTER_HORIZONTAL) != 0; final int innerWidth = MeasureSpec.getSize(widthMeasureSpec) - mPaddingLeft - mPaddingRight; final int otherSize = mMeasureOrderOther.size(); @@ -137,7 +155,7 @@ public class NotificationActionListLayout extends LinearLayout { // Make sure to measure the last child full-width if we didn't use up the entire width, // or we didn't measure yet because there's just one child. - if (lastNotGoneChild != null && (constrained && usedWidth < innerWidth + if (lastNotGoneChild != null && !centerAligned && (constrained && usedWidth < innerWidth || notGoneChildren == 1)) { MarginLayoutParams lp = (MarginLayoutParams) lastNotGoneChild.getLayoutParams(); if (notGoneChildren > 1) { @@ -201,9 +219,10 @@ public class NotificationActionListLayout extends LinearLayout { } final boolean isLayoutRtl = isLayoutRtl(); final int paddingTop = mPaddingTop; + final boolean centerAligned = (mGravity & Gravity.CENTER_HORIZONTAL) != 0; int childTop; - int childLeft; + int childLeft = centerAligned ? left + (right - left) / 2 - mTotalWidth / 2 : 0; // Where bottom of child should go final int height = bottom - top; @@ -216,13 +235,12 @@ public class NotificationActionListLayout extends LinearLayout { final int layoutDirection = getLayoutDirection(); switch (Gravity.getAbsoluteGravity(Gravity.START, layoutDirection)) { case Gravity.RIGHT: - // mTotalWidth contains the padding already - childLeft = mPaddingLeft + right - left - mTotalWidth; + childLeft += mPaddingLeft + right - left - mTotalWidth; break; case Gravity.LEFT: default: - childLeft = mPaddingLeft; + childLeft += mPaddingLeft; break; } diff --git a/core/res/res/layout/notification_template_header.xml b/core/res/res/layout/notification_template_header.xml index f0c980c703cc..3a28f4d76f7c 100644 --- a/core/res/res/layout/notification_template_header.xml +++ b/core/res/res/layout/notification_template_header.xml @@ -37,6 +37,7 @@ android:textAppearance="?attr/notificationHeaderTextAppearance" android:layout_marginStart="@dimen/notification_header_app_name_margin_start" android:layout_marginEnd="@dimen/notification_header_separating_margin" + android:visibility="?attr/notificationHeaderAppNameVisibility" android:singleLine="true" /> <TextView diff --git a/core/res/res/layout/notification_template_material_ambient.xml b/core/res/res/layout/notification_template_material_ambient.xml index ee5c758cc130..865685ff26f5 100644 --- a/core/res/res/layout/notification_template_material_ambient.xml +++ b/core/res/res/layout/notification_template_material_ambient.xml @@ -23,8 +23,8 @@ android:paddingStart="@dimen/notification_extra_margin_ambient" android:paddingEnd="@dimen/notification_extra_margin_ambient" > - <include layout="@layout/notification_template_header" - android:theme="@style/Theme.Material.Notification.Ambient" /> + <include layout="@layout/notification_template_ambient_header" + android:theme="@style/Theme.Material.Notification.Ambient" /> <LinearLayout android:id="@+id/notification_action_list_margin_target" @@ -53,6 +53,7 @@ android:textAppearance="@style/TextAppearance.Material.Notification.Title" android:layout_width="wrap_content" android:layout_height="wrap_content" + android:gravity="top|center_horizontal" android:singleLine="true" android:ellipsize="marquee" android:fadingEdge="horizontal" @@ -65,7 +66,7 @@ android:textAppearance="@style/TextAppearance.Material.Notification" android:singleLine="false" android:layout_weight="1" - android:gravity="top" + android:gravity="top|center_horizontal" android:visibility="gone" android:textSize="16sp" android:textColor="#eeffffff" @@ -75,5 +76,19 @@ /> </LinearLayout> </LinearLayout> - <include layout="@layout/notification_material_action_list" /> + <FrameLayout android:id="@+id/actions_container" + android:layout_width="match_parent" + android:layout_height="wrap_content" + android:layout_gravity="bottom"> + <com.android.internal.widget.NotificationActionListLayout + android:id="@+id/actions" + android:layout_width="match_parent" + android:layout_height="@dimen/notification_action_list_height" + android:paddingEnd="4dp" + android:orientation="horizontal" + android:gravity="center" + android:visibility="gone" + android:background="@color/notification_action_list" + /> + </FrameLayout> </FrameLayout> diff --git a/core/res/res/values/attrs.xml b/core/res/res/values/attrs.xml index 5e8e80944d44..0eefec91e390 100644 --- a/core/res/res/values/attrs.xml +++ b/core/res/res/values/attrs.xml @@ -8715,6 +8715,14 @@ <attr name="notificationHeaderStyle" format="reference" /> <attr name="notificationHeaderTextAppearance" format="reference" /> <attr name="notificationHeaderIconSize" format="dimension" /> + <attr name="notificationHeaderAppNameVisibility" format="enum"> + <!-- Visible on screen; the default value. --> + <enum name="visible" value="0" /> + <!-- Not displayed, but taken into account during layout (space is left for it). --> + <enum name="invisible" value="1" /> + <!-- Completely hidden, as if the view had not been added. --> + <enum name="gone" value="2" /> + </attr> </declare-styleable> <attr name="lockPatternStyle" format="reference" /> diff --git a/core/res/res/values/styles_material.xml b/core/res/res/values/styles_material.xml index 470ac522aa33..cddf99a2df23 100644 --- a/core/res/res/values/styles_material.xml +++ b/core/res/res/values/styles_material.xml @@ -1296,6 +1296,11 @@ please see styles_device_defaults.xml. <item name="layout_marginBottom">@dimen/notification_header_margin_bottom</item> <item name="paddingStart">@dimen/notification_content_margin_start</item> <item name="paddingEnd">16dp</item> + <item name="gravity">top</item> + </style> + + <style name="Notification.Header.Ambient"> + <item name="gravity">top|center_horizontal</item> </style> </resources> diff --git a/core/res/res/values/themes_material.xml b/core/res/res/values/themes_material.xml index 9f858c8ee62e..c31712136eed 100644 --- a/core/res/res/values/themes_material.xml +++ b/core/res/res/values/themes_material.xml @@ -1327,12 +1327,15 @@ please see themes_device_defaults.xml. <style name="Theme.Material.Notification" parent=""> <item name="notificationHeaderStyle">@style/Notification.Header</item> <item name="notificationHeaderTextAppearance">@style/TextAppearance.Material.Notification.Info</item> + <item name="notificationHeaderAppNameVisibility">visible</item> <item name="notificationHeaderIconSize">@dimen/notification_header_icon_size</item> </style> <!-- Theme for inflating ambient notification --> <style name="Theme.Material.Notification.Ambient"> + <item name="notificationHeaderStyle">@style/Notification.Header.Ambient</item> <item name="notificationHeaderTextAppearance">@style/TextAppearance.Material.Notification.Info.Ambient</item> + <item name="notificationHeaderAppNameVisibility">gone</item> <item name="notificationHeaderIconSize">@dimen/notification_header_icon_size_ambient</item> </style> |