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

Commit 88f9dd39 authored by andrewxu's avatar andrewxu Committed by Andrew Xu
Browse files

Add notification close button background

This CL adds a colored background to the notification close button.

BUG: 365585705
Flag: com.android.systemui.notification_add_x_on_hover_to_dismiss
Change-Id: I519452b29fd20d4dabc6445c4f609f450eb1485e
parent 277d34d5
Loading
Loading
Loading
Loading
+12 −1
Original line number Diff line number Diff line
@@ -21,6 +21,8 @@ import android.annotation.Nullable;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.graphics.drawable.Drawable;
import android.graphics.drawable.LayerDrawable;
import android.util.AttributeSet;
import android.view.RemotableViewMethod;
import android.view.View;
@@ -40,6 +42,8 @@ public class NotificationCloseButton extends ImageView {
    @ColorInt private int mBackgroundColor;
    @ColorInt private int mForegroundColor;

    private Drawable mPillDrawable;

    public NotificationCloseButton(Context context) {
        this(context, null, 0, 0);
    }
@@ -62,6 +66,10 @@ public class NotificationCloseButton extends ImageView {
    protected void onFinishInflate() {
        super.onFinishInflate();
        setContentDescription(mContext.getText(R.string.close_button_text));

        final LayerDrawable layeredPill = (LayerDrawable) this.getBackground();
        mPillDrawable = layeredPill.findDrawableByLayerId(R.id.close_button_pill_colorized_layer);

        boolean notificationCloseButtonSupported = Resources.getSystem().getBoolean(
                com.android.internal.R.bool.config_notificationCloseButtonSupported);
        this.setVisibility(notificationCloseButtonSupported ? View.VISIBLE : View.GONE);
@@ -76,8 +84,11 @@ public class NotificationCloseButton extends ImageView {

    private void updateColors() {
        if (mBackgroundColor != 0) {
            this.setBackgroundTintList(ColorStateList.valueOf(mBackgroundColor));
            // TODO(http://b/365585705): Ensure this close button compatible with the ongoing effort
            // that makes notification rows partially-transparent.
            this.mPillDrawable.setTintList(ColorStateList.valueOf(mBackgroundColor));
        }

        if (mForegroundColor != 0) {
            this.setImageTintList(ColorStateList.valueOf(mForegroundColor));
        }
+19 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2025 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, softwarere
  ~ 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.
  -->

<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:color="@color/notification_expand_button_state_tint" />
</selector>
 No newline at end of file
+30 −0
Original line number Diff line number Diff line
<!--
  ~ Copyright (C) 2025 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.
  -->

<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:id="@+id/close_button_pill_colorized_layer">
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <corners android:radius="@dimen/notification_close_button_size" />
            <solid android:color="@android:color/white" />
        </shape>
    </item>
    <item>
        <shape xmlns:android="http://schemas.android.com/apk/res/android">
            <corners android:radius="@dimen/notification_close_button_size" />
            <solid android:color="@color/notification_close_button_state_tint" />
        </shape>
    </item>
</layer-list>
 No newline at end of file
+2 −1
Original line number Diff line number Diff line
@@ -17,13 +17,14 @@
<com.android.internal.widget.NotificationCloseButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/close_button"
    android:background="@drawable/close_button_bg"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_gravity="top|end"
    android:contentDescription="@string/close_button_text"
    android:visibility="gone"
    android:src="@drawable/notification_close_button_icon"
    android:padding="2dp"
    android:padding="@dimen/notification_close_button_padding"
    android:scaleType="fitCenter"
    android:importantForAccessibility="no"
    >
+2 −0
Original line number Diff line number Diff line
@@ -445,6 +445,8 @@
    <!-- the size of the notification close button -->
    <dimen name="notification_close_button_size">16dp</dimen>

    <dimen name="notification_close_button_padding">2dp</dimen>

    <!-- Margin for all notification content -->
    <dimen name="notification_2025_margin">16dp</dimen>

Loading