summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author Jeff DeCew <jeffdq@google.com> 2021-02-26 19:17:38 +0000
committer Android (Google) Code Review <android-gerrit@google.com> 2021-02-26 19:17:38 +0000
commit8ceb0f52d16b9ff12964bdc02dcc9f14cd897488 (patch)
tree70ed45e5644a8d343e24bfd425745c2414323b7e
parentb06c496db77c48e95089be90f7c23a18122dcddf (diff)
parente28685630d9b72beeadd6a0691df6e9505924957 (diff)
Merge "Hide the snooze button from various notifications." into sc-dev
-rw-r--r--core/java/android/app/Notification.java35
-rw-r--r--packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java21
2 files changed, 38 insertions, 18 deletions
diff --git a/core/java/android/app/Notification.java b/core/java/android/app/Notification.java
index f7304fbee6d6..f8c9a9ecf4c8 100644
--- a/core/java/android/app/Notification.java
+++ b/core/java/android/app/Notification.java
@@ -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
- && (Settings.Secure.getInt(mContext.getContentResolver(),
- Settings.Secure.SHOW_NOTIFICATION_SNOOZE, 0) == 1);
- int bottomMarginDimen = snoozeEnabled ? 0 : R.dimen.notification_content_margin;
+ // This may get erased by bindSnoozeAction
big.setViewLayoutMarginDimen(R.id.notification_action_list_margin_target,
- RemoteViews.MARGIN_BOTTOM, bottomMarginDimen);
+ 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);
+ if (snoozeEnabled) {
+ big.setViewLayoutMarginDimen(R.id.notification_action_list_margin_target,
+ 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;
diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
index f427ba958b8f..76917612b910 100644
--- a/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
+++ b/packages/SystemUI/src/com/android/systemui/statusbar/notification/row/NotificationContentView.java
@@ -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(