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

Commit 0ca9aab2 authored by Shuming Hao's avatar Shuming Hao
Browse files

Add notification close button on click listener

This CL adds on click listener to close each notification for notification close buttons.

Flag: NONE only shown with config_notificationCloseButtonSupported
enabled on PC emualtor
Bug: 338456215
Test: manual with Notify1.apk
Change-Id: I17caaf0e197472da545d1353e43666688b5e4ec1
(cherry picked from commit d0cddb85a33fd177e2f43ab4bafad57366a0f650)
parent 8a1da514
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -2011,6 +2011,21 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        };
    }

    /**
     * Retrieves an OnClickListener for the close button of a notification, which when invoked,
     * dismisses the notificationc represented by the given ExpandableNotificationRow.
     *
     * @param row The ExpandableNotificationRow representing the notification to be dismissed.
     * @return An OnClickListener instance that dismisses the notification(s) when invoked.
     */
    public View.OnClickListener getCloseButtonOnClickListener(ExpandableNotificationRow row) {
        return v -> {
            if (row != null) {
                row.performDismiss(false);
            }
        };
    }

    @Override
    protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
        Trace.beginSection(appendTraceStyleTag("ExpNotRow#onMeasure"));
+11 −0
Original line number Diff line number Diff line
@@ -36,6 +36,7 @@ import androidx.annotation.Nullable;

import com.android.app.animation.Interpolators;
import com.android.internal.widget.CachingIconView;
import com.android.internal.widget.NotificationCloseButton;
import com.android.internal.widget.NotificationExpandButton;
import com.android.systemui.res.R;
import com.android.systemui.statusbar.TransformableView;
@@ -60,6 +61,7 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper imple
            = new PathInterpolator(0.4f, 0f, 0.7f, 1f);
    protected final ViewTransformationHelper mTransformationHelper;
    private CachingIconView mIcon;
    private NotificationCloseButton mCloseButton;
    private NotificationExpandButton mExpandButton;
    private View mAltExpandTarget;
    private View mIconContainer;
@@ -112,6 +114,7 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper imple
                TRANSFORMING_VIEW_TITLE);
        resolveHeaderViews();
        addFeedbackOnClickListener(row);
        addCloseButtonOnClickListener(row);
    }

    @Override
@@ -150,6 +153,7 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper imple
        mNotificationTopLine = mView.findViewById(com.android.internal.R.id.notification_top_line);
        mAudiblyAlertedIcon = mView.findViewById(com.android.internal.R.id.alerted_icon);
        mFeedbackIcon = mView.findViewById(com.android.internal.R.id.feedback);
        mCloseButton = mView.findViewById(com.android.internal.R.id.close_button);
    }

    private void addFeedbackOnClickListener(ExpandableNotificationRow row) {
@@ -179,6 +183,13 @@ public class NotificationHeaderViewWrapper extends NotificationViewWrapper imple
        }
    }

    private void addCloseButtonOnClickListener(ExpandableNotificationRow row) {
        View.OnClickListener listener = row.getCloseButtonOnClickListener(row);
        if (mCloseButton != null && listener != null) {
            mCloseButton.setOnClickListener(listener);
        }
    }

    @Override
    public void onContentUpdated(ExpandableNotificationRow row) {
        super.onContentUpdated(row);