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

Commit 418ba9fc authored by Lyn Han's avatar Lyn Han
Browse files

Add snooze button to notification guts

- Expandable* - inject guts manager for snooze setup
- NotifContentView - snooze setup

Bug: 171817112

Test: manual
1) Disable snooze, send notif => snooze button hidden
2) Enable snooze, send notif => snooze button shows
       bottom right for expanded / heads up notif
       left of bubble button for conversations
       hidden for minimized notifs
3) Tap snooze button => snooze guts shows and works as before

Change-Id: I825ded613ec9c987bd0f0c7210a81e80b6c7296f
parent 2601cf31
Loading
Loading
Loading
Loading
+11 −1
Original line number Diff line number Diff line
@@ -327,6 +327,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
    private boolean mShelfIconVisible;
    private boolean mAboveShelf;
    private OnUserInteractionCallback mOnUserInteractionCallback;
    private NotificationGutsManager mNotificationGutsManager;
    private boolean mIsLowPriority;
    private boolean mIsColorized;
    private boolean mUseIncreasedCollapsedHeight;
@@ -1089,6 +1090,13 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        };
    }

    /** The click listener for the snooze button. */
    public View.OnClickListener getSnoozeClickListener(MenuItem item) {
        return v -> {
            mNotificationGutsManager.openGuts(this, 0, 0, item);
        };
    }

    private void updateClickAndFocus() {
        boolean normalChild = !isChildInGroup() || isGroupExpanded();
        boolean clickable = mOnClickListener != null && normalChild;
@@ -1555,7 +1563,8 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
            StatusBarStateController statusBarStateController,
            PeopleNotificationIdentifier peopleNotificationIdentifier,
            OnUserInteractionCallback onUserInteractionCallback,
            Optional<BubblesManager> bubblesManagerOptional) {
            Optional<BubblesManager> bubblesManagerOptional,
            NotificationGutsManager gutsManager) {
        mEntry = entry;
        mAppName = appName;
        if (mMenuRow == null) {
@@ -1584,6 +1593,7 @@ public class ExpandableNotificationRow extends ActivatableNotificationView
        }
        mOnUserInteractionCallback = onUserInteractionCallback;
        mBubblesManagerOptional = bubblesManagerOptional;
        mNotificationGutsManager = gutsManager;

        cacheIsSystemNotification();
    }
+2 −1
Original line number Diff line number Diff line
@@ -154,7 +154,8 @@ public class ExpandableNotificationRowController implements NodeController {
                mStatusBarStateController,
                mPeopleNotificationIdentifier,
                mOnUserInteractionCallback,
                mBubblesManagerOptional
                mBubblesManagerOptional,
                mNotificationGutsManager
        );
        mView.setDescendantFocusability(ViewGroup.FOCUS_BLOCK_DESCENDANTS);
        if (mAllowLongPress) {
+55 −4
Original line number Diff line number Diff line
@@ -18,12 +18,14 @@ package com.android.systemui.statusbar.notification.row;


import static android.provider.Settings.Global.NOTIFICATION_BUBBLES;
import static android.provider.Settings.Secure.SHOW_NOTIFICATION_SNOOZE;

import android.annotation.NonNull;
import android.annotation.Nullable;
import android.app.Notification;
import android.app.PendingIntent;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Rect;
import android.graphics.drawable.Drawable;
import android.os.Build;
@@ -31,6 +33,7 @@ import android.provider.Settings;
import android.util.ArrayMap;
import android.util.AttributeSet;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.MotionEvent;
import android.view.NotificationHeaderView;
import android.view.View;
@@ -44,6 +47,7 @@ import com.android.internal.annotations.VisibleForTesting;
import com.android.internal.util.ContrastColorUtil;
import com.android.systemui.Dependency;
import com.android.systemui.R;
import com.android.systemui.plugins.statusbar.NotificationMenuRowPlugin;
import com.android.systemui.statusbar.RemoteInputController;
import com.android.systemui.statusbar.SmartReplyController;
import com.android.systemui.statusbar.TransformableView;
@@ -458,7 +462,7 @@ public class NotificationContentView extends FrameLayout {
        mExpandedWrapper = NotificationViewWrapper.wrap(getContext(), child,
                mContainingNotification);
        if (mContainingNotification != null) {
            applyBubbleAction(mExpandedChild, mContainingNotification.getEntry());
            applySystemActions(mExpandedChild, mContainingNotification.getEntry());
        }
    }

@@ -500,7 +504,7 @@ public class NotificationContentView extends FrameLayout {
        mHeadsUpWrapper = NotificationViewWrapper.wrap(getContext(), child,
                mContainingNotification);
        if (mContainingNotification != null) {
            applyBubbleAction(mHeadsUpChild, mContainingNotification.getEntry());
            applySystemActions(mHeadsUpChild, mContainingNotification.getEntry());
        }
    }

@@ -1161,8 +1165,8 @@ public class NotificationContentView extends FrameLayout {
        mForceSelectNextLayout = true;
        mPreviousExpandedRemoteInputIntent = null;
        mPreviousHeadsUpRemoteInputIntent = null;
        applyBubbleAction(mExpandedChild, entry);
        applyBubbleAction(mHeadsUpChild, entry);
        applySystemActions(mExpandedChild, entry);
        applySystemActions(mHeadsUpChild, entry);
    }

    private void updateAllSingleLineViews() {
@@ -1340,6 +1344,14 @@ public class NotificationContentView extends FrameLayout {
                NOTIFICATION_BUBBLES, 0) == 1;
    }

    /**
     * Setup icon buttons provided by System UI.
     */
    private void applySystemActions(View layout, NotificationEntry entry) {
        applySnoozeAction(layout);
        applyBubbleAction(layout, entry);
    }

    private void applyBubbleAction(View layout, NotificationEntry entry) {
        if (layout == null || mContainingNotification == null || mPeopleIdentifier == null) {
            return;
@@ -1387,6 +1399,45 @@ public class NotificationContentView extends FrameLayout {
        }
    }

    private void applySnoozeAction(View layout) {
        if (layout == null || mContainingNotification == null) {
            return;
        }
        ImageView snoozeButton = layout.findViewById(com.android.internal.R.id.snooze_button);
        View actionContainer = layout.findViewById(com.android.internal.R.id.actions_container);
        LinearLayout actionContainerLayout =
                layout.findViewById(com.android.internal.R.id.actions_container_layout);
        if (snoozeButton == null || actionContainer == null || actionContainerLayout == null) {
            return;
        }
        final boolean showSnooze = Settings.Secure.getInt(mContext.getContentResolver(),
                SHOW_NOTIFICATION_SNOOZE, 0) == 1;
        if (!showSnooze) {
            snoozeButton.setVisibility(GONE);
            return;
        }

        Resources res = mContext.getResources();
        Drawable snoozeDrawable = res.getDrawable(R.drawable.ic_snooze);
        mContainingNotification.updateNotificationColor();
        snoozeDrawable.setTint(mContainingNotification.getNotificationColor());
        snoozeButton.setImageDrawable(snoozeDrawable);

        final NotificationSnooze snoozeGuts = (NotificationSnooze) LayoutInflater.from(mContext)
                .inflate(R.layout.notification_snooze, null, false);
        final String snoozeDescription = res.getString(
                R.string.notification_menu_snooze_description);
        final NotificationMenuRowPlugin.MenuItem snoozeMenuItem =
                new NotificationMenuRow.NotificationMenuItem(
                        mContext, snoozeDescription, snoozeGuts, R.drawable.ic_snooze);
        snoozeButton.setContentDescription(
                mContext.getResources().getString(R.string.notification_menu_snooze_description));
        snoozeButton.setOnClickListener(
                mContainingNotification.getSnoozeClickListener(snoozeMenuItem));
        snoozeButton.setVisibility(VISIBLE);
        actionContainer.setVisibility(VISIBLE);
    }

    private void applySmartReplyView(
            SmartRepliesAndActions smartRepliesAndActions,
            NotificationEntry entry) {
+2 −1
Original line number Diff line number Diff line
@@ -432,7 +432,8 @@ public class NotificationTestHelper {
                mStatusBarStateController,
                mPeopleNotificationIdentifier,
                mock(OnUserInteractionCallback.class),
                Optional.of(mock(BubblesManager.class)));
                Optional.of(mock(BubblesManager.class)),
                mock(NotificationGutsManager.class));

        row.setAboveShelfChangedListener(aboveShelf -> { });
        mBindStage.getStageParams(entry).requireContentViews(extraInflationFlags);