Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 46fabf34 authored by TreeHugger Robot's avatar TreeHugger Robot Committed by Android (Google) Code Review
Browse files

Merge "Center align AoD2 notifications"

parents c10dcf2f bd9798f6
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -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++) {
+24 −6
Original line number Diff line number Diff line
@@ -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;
        }

+1 −0
Original line number Diff line number Diff line
@@ -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
+19 −4
Original line number Diff line number Diff line
@@ -23,7 +23,7 @@
    android:paddingStart="@dimen/notification_extra_margin_ambient"
    android:paddingEnd="@dimen/notification_extra_margin_ambient"
    >
    <include layout="@layout/notification_template_header"
    <include layout="@layout/notification_template_ambient_header"
             android:theme="@style/Theme.Material.Notification.Ambient" />

    <LinearLayout
@@ -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>
+8 −0
Original line number Diff line number Diff line
@@ -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" />
Loading