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

Commit 0f6e96c1 authored by Anthony Chen's avatar Anthony Chen
Browse files

Modifications to allow notification header to be customized.

Changes include:
- Allowing the margins between header items to be customized.
- Allow expand button to be laid out at the end of the header view.
- Ensure the media header height can be customized.
- Allow entire header to be clicked to expand the notification rather
than just the notification button.

Also, fix how the color is resolved from the header. It currently checks
the color directly on the expand button. However, this color can simply
be retrieved by the header's getOriginalNotificationColor() method.

Test: booted on phone and Android Auto headunit
Bug: 33210494
Change-Id: I4bb3ff42d23b44de28dc1196799a7c3bda40bbac
parent 1469e575
Loading
Loading
Loading
Loading
+44 −20
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package android.view;
import android.annotation.Nullable;
import android.app.Notification;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Outline;
import android.graphics.Rect;
@@ -27,6 +28,7 @@ import android.util.AttributeSet;
import android.widget.ImageView;
import android.widget.RemoteViews;

import com.android.internal.R;
import com.android.internal.widget.CachingIconView;

import java.util.ArrayList;
@@ -52,9 +54,12 @@ public class NotificationHeaderView extends ViewGroup {
    private int mIconColor;
    private int mOriginalNotificationColor;
    private boolean mExpanded;
    private boolean mShowExpandButtonAtEnd;
    private boolean mShowWorkBadgeAtEnd;
    private Drawable mBackground;
    private int mHeaderBackgroundHeight;
    private boolean mEntireHeaderClickable;
    private boolean mAcceptAllTouches;

    ViewOutlineProvider mProvider = new ViewOutlineProvider() {
        @Override
@@ -65,7 +70,6 @@ public class NotificationHeaderView extends ViewGroup {
            }
        }
    };
    private boolean mAcceptAllTouches;

    public NotificationHeaderView(Context context) {
        this(context, null);
@@ -81,12 +85,12 @@ public class NotificationHeaderView extends ViewGroup {

    public NotificationHeaderView(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
        mChildMinWidth = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_header_shrink_min_width);
        mContentEndMargin = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_content_margin_end);
        mHeaderBackgroundHeight = getResources().getDimensionPixelSize(
                com.android.internal.R.dimen.notification_header_background_height);
        Resources res = getResources();
        mChildMinWidth = res.getDimensionPixelSize(R.dimen.notification_header_shrink_min_width);
        mContentEndMargin = res.getDimensionPixelSize(R.dimen.notification_content_margin_end);
        mHeaderBackgroundHeight = res.getDimensionPixelSize(
                R.dimen.notification_header_background_height);
        mEntireHeaderClickable = res.getBoolean(R.bool.config_notificationHeaderClickableForExpand);
    }

    @Override
@@ -147,8 +151,9 @@ public class NotificationHeaderView extends ViewGroup {
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        int left = getPaddingStart();
        int end = getMeasuredWidth();
        int childCount = getChildCount();
        int ownHeight = getHeight() - getPaddingTop() - getPaddingBottom();
        int ownHeight = getMeasuredHeight() - getPaddingTop() - getPaddingBottom();
        for (int i = 0; i < childCount; i++) {
            View child = getChildAt(i);
            if (child.getVisibility() == GONE) {
@@ -162,13 +167,17 @@ public class NotificationHeaderView extends ViewGroup {
            int bottom = top + childHeight;
            int layoutLeft = left;
            int layoutRight = right;
            if (child == mExpandButton && mShowExpandButtonAtEnd) {
                layoutRight = end - mContentEndMargin;
                end = layoutLeft = layoutRight - child.getMeasuredWidth();
            }
            if (child == mProfileBadge) {
                int paddingEnd = getPaddingEnd();
                if (mShowWorkBadgeAtEnd) {
                    paddingEnd = mContentEndMargin;
                }
                layoutRight = getWidth() - paddingEnd;
                layoutLeft = layoutRight - child.getMeasuredWidth();
                layoutRight = end - paddingEnd;
                end = layoutLeft = layoutRight - child.getMeasuredWidth();
            }
            if (getLayoutDirection() == LAYOUT_DIRECTION_RTL) {
                int ltrLeft = layoutLeft;
@@ -265,13 +274,11 @@ public class NotificationHeaderView extends ViewGroup {
        int drawableId;
        int contentDescriptionId;
        if (mExpanded) {
            drawableId = com.android.internal.R.drawable.ic_collapse_notification;
            contentDescriptionId
                    = com.android.internal.R.string.expand_button_content_description_expanded;
            drawableId = R.drawable.ic_collapse_notification;
            contentDescriptionId = R.string.expand_button_content_description_expanded;
        } else {
            drawableId = com.android.internal.R.drawable.ic_expand_notification;
            contentDescriptionId
                    = com.android.internal.R.string.expand_button_content_description_collapsed;
            drawableId = R.drawable.ic_expand_notification;
            contentDescriptionId = R.string.expand_button_content_description_collapsed;
        }
        mExpandButton.setImageDrawable(getContext().getDrawable(drawableId));
        mExpandButton.setColorFilter(mOriginalNotificationColor);
@@ -285,6 +292,18 @@ public class NotificationHeaderView extends ViewGroup {
        }
    }

    /**
     * Sets whether or not the expand button appears at the end of the NotificationHeaderView. If
     * both this and {@link #setShowWorkBadgeAtEnd(boolean)} have been set to true, then the
     * expand button will appear closer to the end than the work badge.
     */
    public void setShowExpandButtonAtEnd(boolean showExpandButtonAtEnd) {
        if (showExpandButtonAtEnd != mShowExpandButtonAtEnd) {
            setClipToPadding(!showExpandButtonAtEnd);
            mShowExpandButtonAtEnd = showExpandButtonAtEnd;
        }
    }

    public View getWorkProfileIcon() {
        return mProfileBadge;
    }
@@ -306,8 +325,8 @@ public class NotificationHeaderView extends ViewGroup {

        public void bindTouchRects() {
            mTouchRects.clear();
            addRectAroundViewView(mIcon);
            addRectAroundViewView(mExpandButton);
            addRectAroundView(mIcon);
            addRectAroundView(mExpandButton);
            addWidthRect();
            mTouchSlop = ViewConfiguration.get(getContext()).getScaledTouchSlop();
        }
@@ -321,7 +340,7 @@ public class NotificationHeaderView extends ViewGroup {
            mTouchRects.add(r);
        }

        private void addRectAroundViewView(View view) {
        private void addRectAroundView(View view) {
            final Rect r = getRectAroundView(view);
            mTouchRects.add(r);
        }
@@ -412,8 +431,13 @@ public class NotificationHeaderView extends ViewGroup {
        return mTouchListener.isInside(x, y);
    }

    /**
     * Sets whether or not all touches to this header view will register as a click. Note that
     * if the config value for {@code config_notificationHeaderClickableForExpand} is {@code true},
     * then calling this method with {@code false} will not override that configuration.
     */
    @RemotableViewMethod
    public void setAcceptAllTouches(boolean acceptAllTouches) {
        mAcceptAllTouches = acceptAllTouches;
        mAcceptAllTouches = mEntireHeaderClickable || acceptAllTouches;
    }
}
+18 −17
Original line number Diff line number Diff line
@@ -28,15 +28,15 @@
        android:id="@+id/icon"
        android:layout_width="?attr/notificationHeaderIconSize"
        android:layout_height="?attr/notificationHeaderIconSize"
        android:layout_marginEnd="3dp"
        android:layout_marginEnd="@dimen/notification_header_icon_margin_end"
        />
    <TextView
        android:id="@+id/app_name_text"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?attr/notificationHeaderTextAppearance"
        android:layout_marginStart="3dp"
        android:layout_marginEnd="2dp"
        android:layout_marginStart="@dimen/notification_header_app_name_margin_start"
        android:layout_marginEnd="@dimen/notification_header_separating_margin"
        android:singleLine="true"
        />
    <TextView
@@ -44,8 +44,8 @@
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?attr/notificationHeaderTextAppearance"
        android:layout_marginStart="2dp"
        android:layout_marginEnd="2dp"
        android:layout_marginStart="@dimen/notification_header_separating_margin"
        android:layout_marginEnd="@dimen/notification_header_separating_margin"
        android:text="@string/notification_header_divider_symbol"
        android:visibility="gone"/>
    <TextView
@@ -53,8 +53,8 @@
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?attr/notificationHeaderTextAppearance"
        android:layout_marginStart="2dp"
        android:layout_marginEnd="2dp"
        android:layout_marginStart="@dimen/notification_header_separating_margin"
        android:layout_marginEnd="@dimen/notification_header_separating_margin"
        android:visibility="gone"
        android:singleLine="true"/>
    <TextView
@@ -62,8 +62,8 @@
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textAppearance="?attr/notificationHeaderTextAppearance"
        android:layout_marginStart="2dp"
        android:layout_marginEnd="2dp"
        android:layout_marginStart="@dimen/notification_header_separating_margin"
        android:layout_marginEnd="@dimen/notification_header_separating_margin"
        android:text="@string/notification_header_divider_symbol"
        android:singleLine="true"
        android:visibility="gone"/>
@@ -73,8 +73,8 @@
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginStart="2dp"
        android:layout_marginEnd="2dp"
        android:layout_marginStart="@dimen/notification_header_separating_margin"
        android:layout_marginEnd="@dimen/notification_header_separating_margin"
        android:showRelative="true"
        android:singleLine="true"
        android:visibility="gone" />
@@ -82,21 +82,22 @@
        android:id="@+id/chronometer"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginStart="2dp"
        android:layout_marginEnd="2dp"
        android:layout_marginStart="@dimen/notification_header_separating_margin"
        android:layout_marginEnd="@dimen/notification_header_separating_margin"
        android:layout="@layout/notification_template_part_chronometer"
        android:visibility="gone"
        />
    <com.android.internal.widget.NotificationExpandButton
        android:id="@+id/expand_button"
        android:background="@null"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:paddingTop="1dp"
        android:layout_width="@dimen/notification_header_expand_icon_size"
        android:layout_height="@dimen/notification_header_expand_icon_size"
        android:paddingTop="@dimen/notification_expand_button_padding_top"
        android:visibility="gone"
        android:contentDescription="@string/expand_button_content_description_collapsed"
        />
    <ImageView android:id="@+id/profile_badge"
    <ImageView
        android:id="@+id/profile_badge"
        android:layout_width="@dimen/notification_badge_size"
        android:layout_height="@dimen/notification_badge_size"
        android:layout_gravity="center"
+3 −2
Original line number Diff line number Diff line
@@ -16,7 +16,8 @@
  -->

<!-- Layout for the expanded media notification -->
<com.android.internal.widget.MediaNotificationView xmlns:android="http://schemas.android.com/apk/res/android"
<com.android.internal.widget.MediaNotificationView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/status_bar_latest_event_content"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
@@ -25,7 +26,7 @@
    >
    <include layout="@layout/notification_template_header"
        android:layout_width="match_parent"
        android:layout_height="53dp"
        android:layout_height="@dimen/media_notification_header_height"
        android:layout_gravity="start"/>
    <LinearLayout
        android:layout_width="match_parent"
+2 −2
Original line number Diff line number Diff line
@@ -24,8 +24,8 @@
    android:tag="media"
    >
    <include layout="@layout/notification_template_header"
        android:layout_width="fill_parent"
        android:layout_height="53dp" />
        android:layout_width="match_parent"
        android:layout_height="@dimen/media_notification_header_height" />
    <LinearLayout
        android:id="@+id/notification_main_column"
        android:layout_width="match_parent"
+5 −0
Original line number Diff line number Diff line
@@ -2838,4 +2838,9 @@

    <!-- Whether the device uses the default focus highlight when focus state isn't specified. -->
    <bool name="config_useDefaultFocusHighlight">true</bool>

    <!-- Flag indicating that the entire notification header can be clicked to expand the
         notification. If false, then the expand icon has to be clicked in order for the expand
         to occur. The expand button will have increased touch boundaries to accomodate this. -->
    <bool name="config_notificationHeaderClickableForExpand">false</bool>
</resources>
Loading