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

Commit e2868563 authored by Jeff DeCew's avatar Jeff DeCew
Browse files

Hide the snooze button from various notifications.

* Foreground service notifications.
* Colorized notifications (where the snooze button's color would be wrong).
* FullScreenIntent notifications, which are timely.
* HUNs, since the expanded state could have the button.

Bug: 179178086
Test: manual
Change-Id: I3fa46d6493c14ddf7e9b9e28afb7de15b1ddd89a
parent 0dae8f70
Loading
Loading
Loading
Loading
+30 −5
Original line number Diff line number Diff line
@@ -5494,12 +5494,28 @@ public class Notification implements Parcelable
            big.setViewVisibility(R.id.notification_material_reply_text_3, View.GONE);
            big.setTextViewText(R.id.notification_material_reply_text_3, null);

            final boolean snoozeEnabled = mContext.getContentResolver() != null
            // This may get erased by bindSnoozeAction
            big.setViewLayoutMarginDimen(R.id.notification_action_list_margin_target,
                    RemoteViews.MARGIN_BOTTOM, R.dimen.notification_content_margin);
        }

        private void bindSnoozeAction(RemoteViews big, StandardTemplateParams p) {
            boolean hideSnoozeButton = mN.isForegroundService() || mN.fullScreenIntent != null
                    || isColorized(p) || p.mViewType == StandardTemplateParams.VIEW_TYPE_HEADS_UP;
            big.setBoolean(R.id.snooze_button, "setEnabled", !hideSnoozeButton);
            if (hideSnoozeButton) {
                // Only hide; NotificationContentView will show it when it adds the click listener
                big.setViewVisibility(R.id.snooze_button, View.GONE);
            }

            final boolean snoozeEnabled = !hideSnoozeButton
                    && mContext.getContentResolver() != null
                    && (Settings.Secure.getInt(mContext.getContentResolver(),
                    Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0) == 1);
            int bottomMarginDimen = snoozeEnabled ? 0 : R.dimen.notification_content_margin;
            if (snoozeEnabled) {
                big.setViewLayoutMarginDimen(R.id.notification_action_list_margin_target,
                    RemoteViews.MARGIN_BOTTOM, bottomMarginDimen);
                        RemoteViews.MARGIN_BOTTOM, 0);
            }
        }

        /**
@@ -5521,6 +5537,7 @@ public class Notification implements Parcelable
            RemoteViews big = applyStandardTemplate(layoutId, p, result);

            resetStandardTemplateWithActions(big);
            bindSnoozeAction(big, p);

            boolean validRemoteInput = false;

@@ -9358,6 +9375,7 @@ public class Notification implements Parcelable

            // Bind actions.
            mBuilder.resetStandardTemplateWithActions(contentView);
            mBuilder.bindSnoozeAction(contentView, p);
            bindCallActions(contentView, p);

            // Bind some extra conversation-specific header fields.
@@ -11998,6 +12016,7 @@ public class Notification implements Parcelable
        boolean mHideTitle;
        boolean mHideActions;
        boolean mHideProgress;
        boolean mHideSnoozeButton;
        boolean mPromotePicture;
        boolean mAllowActionIcons;
        CharSequence title;
@@ -12015,6 +12034,7 @@ public class Notification implements Parcelable
            mHideTitle = false;
            mHideActions = false;
            mHideProgress = false;
            mHideSnoozeButton = false;
            mPromotePicture = false;
            mAllowActionIcons = false;
            title = null;
@@ -12061,6 +12081,11 @@ public class Notification implements Parcelable
            return this;
        }

        final StandardTemplateParams hideSnoozeButton(boolean hideSnoozeButton) {
            this.mHideSnoozeButton = hideSnoozeButton;
            return this;
        }

        final StandardTemplateParams promotePicture(boolean promotePicture) {
            this.mPromotePicture = promotePicture;
            return this;
+8 −13
Original line number Diff line number Diff line
@@ -17,15 +17,11 @@
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;
@@ -1317,7 +1313,7 @@ public class NotificationContentView extends FrameLayout {

    private boolean isBubblesEnabled() {
        return Settings.Global.getInt(mContext.getContentResolver(),
                NOTIFICATION_BUBBLES, 0) == 1;
                Settings.Global.NOTIFICATION_BUBBLES, 0) == 1;
    }

    /**
@@ -1373,27 +1369,26 @@ public class NotificationContentView extends FrameLayout {
        }
        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) {
        if (snoozeButton == null || actionContainer == null) {
            return;
        }
        final boolean showSnooze = Settings.Secure.getInt(mContext.getContentResolver(),
                SHOW_NOTIFICATION_SNOOZE, 0) == 1;
        if (!showSnooze) {
                Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0) == 1;
        // Notification.Builder can 'disable' the snooze button to prevent it from being shown here
        boolean snoozeDisabled = !snoozeButton.isEnabled();
        if (!showSnooze || snoozeDisabled) {
            snoozeButton.setVisibility(GONE);
            return;
        }

        Resources res = mContext.getResources();
        Drawable snoozeDrawable = res.getDrawable(R.drawable.ic_snooze);
        Drawable snoozeDrawable = mContext.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(
        final String snoozeDescription = mContext.getString(
                R.string.notification_menu_snooze_description);
        final NotificationMenuRowPlugin.MenuItem snoozeMenuItem =
                new NotificationMenuRow.NotificationMenuItem(