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

Commit 528faaec authored by Shuming Hao's avatar Shuming Hao Committed by Android (Google) Code Review
Browse files

Merge changes from topic "add-notification-close-button-main" into main

* changes:
  Add close button in conversation notifications
  Add notification close button on click listener
  Hide notification close button behind a config
  Add close button on notifications
parents bd084283 8cd34aa2
Loading
Loading
Loading
Loading
+10 −0
Original line number Diff line number Diff line
@@ -6050,6 +6050,7 @@ public class Notification implements Parcelable
            bindProfileBadge(contentView, p);
            bindAlertedIcon(contentView, p);
            bindExpandButton(contentView, p);
            bindCloseButton(contentView, p);
            mN.mUsesStandardHeader = true;
        }
@@ -6071,6 +6072,15 @@ public class Notification implements Parcelable
            contentView.setInt(R.id.expand_button, "setHighlightPillColor", pillColor);
        }
        private void bindCloseButton(RemoteViews contentView, StandardTemplateParams p) {
            // set default colors
            int bgColor = getBackgroundColor(p);
            int backgroundColor = Colors.flattenAlpha(getColors(p).getProtectionColor(), bgColor);
            int foregroundColor = Colors.flattenAlpha(getPrimaryTextColor(p), backgroundColor);
            contentView.setInt(R.id.close_button, "setForegroundColor", foregroundColor);
            contentView.setInt(R.id.close_button, "setBackgroundColor", backgroundColor);
        }
        private void bindHeaderChronometerAndTime(RemoteViews contentView,
                StandardTemplateParams p, boolean hasTextToLeft) {
            if (!p.mHideTime && showsTimeOrChronometer()) {
+103 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2024 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.ColorInt;
import android.annotation.Nullable;
import android.content.Context;
import android.content.res.ColorStateList;
import android.content.res.Resources;
import android.util.AttributeSet;
import android.view.RemotableViewMethod;
import android.view.View;
import android.view.accessibility.AccessibilityNodeInfo;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.RemoteViews;

import com.android.internal.R;

/**
 * A close button in a notification
 */
@RemoteViews.RemoteView
public class NotificationCloseButton extends ImageView {

    @ColorInt private int mBackgroundColor;
    @ColorInt private int mForegroundColor;

    public NotificationCloseButton(Context context) {
        this(context, null, 0, 0);
    }

    public NotificationCloseButton(Context context, @Nullable AttributeSet attrs) {
        this(context, attrs, 0, 0);
    }

    public NotificationCloseButton(Context context, @Nullable AttributeSet attrs,
            int defStyleAttr) {
        this(context, attrs, defStyleAttr, 0);
    }

    public NotificationCloseButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr,
            int defStyleRes) {
        super(context, attrs, defStyleAttr, defStyleRes);
    }

    @Override
    protected void onFinishInflate() {
        super.onFinishInflate();
        setContentDescription(mContext.getText(R.string.close_button_text));
        boolean notificationCloseButtonSupported = Resources.getSystem().getBoolean(
                com.android.internal.R.bool.config_notificationCloseButtonSupported);
        this.setVisibility(notificationCloseButtonSupported ? View.VISIBLE : View.GONE);
    }

    @Override
    public void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info) {
        super.onInitializeAccessibilityNodeInfo(info);
        info.setClassName(Button.class.getName());
    }


    private void updateColors() {
        if (mBackgroundColor != 0) {
            this.setBackgroundTintList(ColorStateList.valueOf(mBackgroundColor));
        }
        if (mForegroundColor != 0) {
            this.setImageTintList(ColorStateList.valueOf(mForegroundColor));
        }
    }

    /**
     * Set the color used for the foreground.
     */
    @RemotableViewMethod
    public void setForegroundColor(@ColorInt int color) {
        mForegroundColor = color;
        updateColors();
    }

    /**
     * Sets the color used for the background.
     */
    @RemotableViewMethod
    public void setBackgroundColor(@ColorInt int color) {
        mBackgroundColor = color;
        updateColors();
    }
}
+28 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?>
<!--
  ~ Copyright (C) 2024 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.
  -->

<vector xmlns:android="http://schemas.android.com/apk/res/android"
        android:width="@dimen/notification_close_button_size"
        android:height="@dimen/notification_close_button_size"
        android:viewportWidth="16.0"
        android:viewportHeight="16.0">
<path
    android:fillColor="#FF000000"
    android:pathData="M 12.6667 4.2733 L 11.7267 3.3333 L 8 7.06 L 4.2734 3.3333 L 3.3334
4.2733 L 7.06 8 L 3.3334 11.7267 L 4.2734 12.6667 L 8 8.94 L 11.7267 12.6667 L 12.6667
11.7267 L 8.94 8 L 12.6667 4.2733 Z"/>
</vector>
 No newline at end of file
+30 −0
Original line number Diff line number Diff line
<?xml version="1.0" encoding="utf-8"?><!--
  ~ Copyright (C) 2024 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
  -->

<com.android.internal.widget.NotificationCloseButton
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/close_button"
    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:scaleType="fitCenter"
    android:importantForAccessibility="no"
    >
</com.android.internal.widget.NotificationCloseButton>
+20 −3
Original line number Diff line number Diff line
@@ -83,6 +83,21 @@
        android:focusable="false"
        />

    <LinearLayout
        android:id="@+id/notification_buttons_column"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentEnd="true"
        android:orientation="vertical"
        >

        <include layout="@layout/notification_close_button"
            android:layout_width="@dimen/notification_close_button_size"
            android:layout_height="@dimen/notification_close_button_size"
            android:layout_gravity="end"
            android:layout_marginEnd="20dp"
            />

        <include layout="@layout/notification_expand_button"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
@@ -90,4 +105,6 @@
            android:layout_centerVertical="true"
            />

    </LinearLayout>

</NotificationHeaderView>
Loading