Add snooze settings layout in Ash notifications
[Chrome rendered ARC notifications] This CL adds snooze settings layout in Ash notifications to match the Android notification snooze settings. Each button in the snooze settings layout will be wired up to the ARC side through mojo methods. The snooze settings layout is disabled until the mojo callbacks are added in both Chrome and ARC side. More details in this doc: go/snooze-chrome-rendered-arc-notifications Bug: b/298216201 Test: manual with Notify1.apk Change-Id: If6337034262c519ac95fe7b0989a01aab0ca2bd2 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4860011 Commit-Queue: Shuming Hao <shuminghao@google.com> Reviewed-by: Ahmed Mehfooz <amehfooz@chromium.org> Cr-Commit-Position: refs/heads/main@{#1198723}
This commit is contained in:

committed by
Chromium LUCI CQ

parent
f5118d522c
commit
bd61b9d585
ash
ash_strings.grd
ash_strings_grd
IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_15_MINUTES_TEXT.png.sha1IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_1_HOUR_TEXT.png.sha1IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_2_HOURS_TEXT.png.sha1IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_30_MINUTES_TEXT.png.sha1IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_UNDO_SNOOZE_TEXT.png.sha1
system
message_center
ui/message_center/views
@ -5069,6 +5069,21 @@ Some features are limited to increase battery life.
|
||||
<message name="IDS_ASH_NOTIFICATION_INLINE_SETTINGS_CANCEL_BUTTON_TEXT" desc="The text for cancel button in settings, return to the main UI.">
|
||||
Cancel
|
||||
</message>
|
||||
<message name="IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_1_HOUR_TEXT" desc="The text for snooze notification for 1 hour in snooze settings.">
|
||||
1h
|
||||
</message>
|
||||
<message name="IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_15_MINUTES_TEXT" desc="The text for snooze notification for 15 minutes in snooze settings.">
|
||||
15min
|
||||
</message>
|
||||
<message name="IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_30_MINUTES_TEXT" desc="The text for snooze notification for 30 minutes in snooze settings.">
|
||||
30min
|
||||
</message>
|
||||
<message name="IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_2_HOURS_TEXT" desc="The text for snooze notification for 2 hours in snooze settings.">
|
||||
2h
|
||||
</message>
|
||||
<message name="IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_UNDO_SNOOZE_TEXT" desc="The text for undo snooze notification in snooze settings.">
|
||||
Undo
|
||||
</message>
|
||||
|
||||
<message name="IDS_ASH_DIALOG_DONT_SHOW_AGAIN" desc="Label for checkbox dismissing show of a dialog.">
|
||||
Don't show again
|
||||
|
1
ash/ash_strings_grd/IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_15_MINUTES_TEXT.png.sha1
Normal file
1
ash/ash_strings_grd/IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_15_MINUTES_TEXT.png.sha1
Normal file
@ -0,0 +1 @@
|
||||
6e09cd4134e335fbd0a62ee08abc35ca66b02b13
|
@ -0,0 +1 @@
|
||||
2f380d4f1ee6bffc74ed70cc1862da97325b95cb
|
@ -0,0 +1 @@
|
||||
26b640c73129a8bce6f197b9d38f66f942d6e1d5
|
1
ash/ash_strings_grd/IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_30_MINUTES_TEXT.png.sha1
Normal file
1
ash/ash_strings_grd/IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_30_MINUTES_TEXT.png.sha1
Normal file
@ -0,0 +1 @@
|
||||
476dc9b114de6d81bb739ff2581c0d6603a81328
|
@ -0,0 +1 @@
|
||||
55946a75f44f3dcba4bf19215223b4ee0c23102b
|
@ -593,6 +593,7 @@ AshNotificationView::AshNotificationView(
|
||||
// consider making changes to this code when the bug is fixed.
|
||||
.SetMaximumWidth(GetExpandedMessageLabelWidth()))
|
||||
.AddChild(CreateInlineSettingsBuilder())
|
||||
.AddChild(CreateSnoozeSettingsBuilder())
|
||||
.AddChild(CreateImageContainerBuilder().SetProperty(
|
||||
views::kMarginsKey, kImageContainerPadding));
|
||||
|
||||
@ -1375,6 +1376,58 @@ void AshNotificationView::CreateOrUpdateInlineSettingsViews(
|
||||
std::move(inline_settings_cancel_button));
|
||||
}
|
||||
|
||||
void AshNotificationView::CreateOrUpdateSnoozeSettingsViews(
|
||||
const message_center::Notification& notification) {
|
||||
// TODO(b/298216201): Enable snooze settings after adding mojo callbacks in
|
||||
// the snooze settings layout.
|
||||
|
||||
if (!snooze_settings_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
snooze_settings_row()->SetLayoutManager(std::make_unique<views::BoxLayout>(
|
||||
views::BoxLayout::Orientation::kHorizontal));
|
||||
auto snooze_notification_1_hour_button = GenerateNotificationLabelButton(
|
||||
base::BindRepeating(&AshNotificationView::DisableNotification,
|
||||
base::Unretained(this)),
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_1_HOUR_TEXT));
|
||||
snooze_settings_row()->AddChildView(
|
||||
std::move(snooze_notification_1_hour_button));
|
||||
|
||||
auto snooze_notification_15_minutes_button = GenerateNotificationLabelButton(
|
||||
base::BindRepeating(&AshNotificationView::DisableNotification,
|
||||
base::Unretained(this)),
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_15_MINUTES_TEXT));
|
||||
snooze_settings_row()->AddChildView(
|
||||
std::move(snooze_notification_15_minutes_button));
|
||||
|
||||
auto snooze_notification_30_minutes_button = GenerateNotificationLabelButton(
|
||||
base::BindRepeating(&AshNotificationView::DisableNotification,
|
||||
base::Unretained(this)),
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_30_MINUTES_TEXT));
|
||||
snooze_settings_row()->AddChildView(
|
||||
std::move(snooze_notification_30_minutes_button));
|
||||
|
||||
auto snooze_notification_2_hours_button = GenerateNotificationLabelButton(
|
||||
base::BindRepeating(&AshNotificationView::DisableNotification,
|
||||
base::Unretained(this)),
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_SNOOZE_2_HOURS_TEXT));
|
||||
snooze_settings_row()->AddChildView(
|
||||
std::move(snooze_notification_2_hours_button));
|
||||
|
||||
auto undo_snooze_notification_button = GenerateNotificationLabelButton(
|
||||
base::BindRepeating(&AshNotificationView::ToggleSnoozeSettings,
|
||||
base::Unretained(this)),
|
||||
l10n_util::GetStringUTF16(
|
||||
IDS_ASH_NOTIFICATION_SNOOZE_SETTINGS_UNDO_SNOOZE_TEXT));
|
||||
snooze_settings_row()->AddChildView(
|
||||
std::move(undo_snooze_notification_button));
|
||||
}
|
||||
|
||||
void AshNotificationView::CreateOrUpdateCompactTitleMessageView(
|
||||
const message_center::Notification& notification) {
|
||||
// No CompactTitleMessageView required. It is only used for progress
|
||||
@ -1566,6 +1619,21 @@ void AshNotificationView::ToggleInlineSettings(const ui::Event& event) {
|
||||
PreferredSizeChanged();
|
||||
}
|
||||
|
||||
void AshNotificationView::ToggleSnoozeSettings(const ui::Event& event) {
|
||||
if (!snooze_settings_enabled()) {
|
||||
return;
|
||||
}
|
||||
|
||||
bool should_show_snooze_settings = !snooze_settings_row()->GetVisible();
|
||||
|
||||
NotificationViewBase::ToggleSnoozeSettings(event);
|
||||
|
||||
left_content()->SetVisible(!should_show_snooze_settings);
|
||||
right_content()->SetVisible(!should_show_snooze_settings);
|
||||
|
||||
PreferredSizeChanged();
|
||||
}
|
||||
|
||||
void AshNotificationView::OnInlineReplyUpdated() {
|
||||
DCHECK(inline_reply() && inline_reply()->GetVisible());
|
||||
// Fade out actions button and then fade in inline reply.
|
||||
|
@ -118,6 +118,8 @@ class ASH_EXPORT AshNotificationView
|
||||
const message_center::Notification& notification) override;
|
||||
void CreateOrUpdateInlineSettingsViews(
|
||||
const message_center::Notification& notification) override;
|
||||
void CreateOrUpdateSnoozeSettingsViews(
|
||||
const message_center::Notification& notification) override;
|
||||
void CreateOrUpdateCompactTitleMessageView(
|
||||
const message_center::Notification& notification) override;
|
||||
void CreateOrUpdateProgressViews(
|
||||
@ -137,6 +139,7 @@ class ASH_EXPORT AshNotificationView
|
||||
gfx::Size GetIconViewSize() const override;
|
||||
int GetLargeImageViewMaxWidth() const override;
|
||||
void ToggleInlineSettings(const ui::Event& event) override;
|
||||
void ToggleSnoozeSettings(const ui::Event& event) override;
|
||||
void OnInlineReplyUpdated() override;
|
||||
|
||||
void set_is_animating(bool is_animating) { is_animating_ = is_animating; }
|
||||
|
@ -303,6 +303,7 @@ NotificationView::NotificationView(
|
||||
.SetBorder(views::CreateEmptyBorder(kLargeImageContainerPadding))
|
||||
.Build());
|
||||
AddChildView(CreateInlineSettingsBuilder().Build());
|
||||
AddChildView(CreateSnoozeSettingsBuilder().Build());
|
||||
AddChildView(CreateActionsRow());
|
||||
|
||||
CreateOrUpdateViews(notification);
|
||||
@ -471,6 +472,11 @@ void NotificationView::CreateOrUpdateInlineSettingsViews(
|
||||
inline_settings_row()->AddChildView(std::move(settings_button_row));
|
||||
}
|
||||
|
||||
void NotificationView::CreateOrUpdateSnoozeSettingsViews(
|
||||
const Notification& notification) {
|
||||
// Not implemented by default.
|
||||
}
|
||||
|
||||
std::unique_ptr<views::LabelButton>
|
||||
NotificationView::GenerateNotificationLabelButton(
|
||||
views::Button::PressedCallback callback,
|
||||
@ -561,6 +567,10 @@ void NotificationView::ToggleInlineSettings(const ui::Event& event) {
|
||||
MessageCenter::Get()->DisableNotification(notification_id());
|
||||
}
|
||||
|
||||
void NotificationView::ToggleSnoozeSettings(const ui::Event& event) {
|
||||
// Not implemented by default.
|
||||
}
|
||||
|
||||
bool NotificationView::IsExpandable() const {
|
||||
// Inline settings can not be expanded.
|
||||
if (GetMode() == Mode::SETTING)
|
||||
|
@ -40,6 +40,8 @@ class MESSAGE_CENTER_EXPORT NotificationView : public NotificationViewBase {
|
||||
void CreateOrUpdateSmallIconView(const Notification& notification) override;
|
||||
void CreateOrUpdateInlineSettingsViews(
|
||||
const Notification& notification) override;
|
||||
void CreateOrUpdateSnoozeSettingsViews(
|
||||
const Notification& notification) override;
|
||||
std::unique_ptr<views::LabelButton> GenerateNotificationLabelButton(
|
||||
views::Button::PressedCallback callback,
|
||||
const std::u16string& label) override;
|
||||
@ -49,6 +51,7 @@ class MESSAGE_CENTER_EXPORT NotificationView : public NotificationViewBase {
|
||||
void OnThemeChanged() override;
|
||||
void UpdateCornerRadius(int top_radius, int bottom_radius) override;
|
||||
void ToggleInlineSettings(const ui::Event& event) override;
|
||||
void ToggleSnoozeSettings(const ui::Event& event) override;
|
||||
bool IsExpandable() const override;
|
||||
void AddLayerToRegion(ui::Layer* layer, views::LayerRegion region) override;
|
||||
void RemoveLayerFromRegions(ui::Layer* layer) override;
|
||||
|
@ -209,6 +209,7 @@ void NotificationViewBase::CreateOrUpdateViews(
|
||||
CreateOrUpdateSmallIconView(notification);
|
||||
CreateOrUpdateImageView(notification);
|
||||
CreateOrUpdateInlineSettingsViews(notification);
|
||||
CreateOrUpdateSnoozeSettingsViews(notification);
|
||||
UpdateViewForExpandedState(expanded_);
|
||||
// Should be called at the last because SynthesizeMouseMoveEvent() requires
|
||||
// everything is in the right location when called.
|
||||
@ -400,6 +401,14 @@ NotificationViewBase::CreateInlineSettingsBuilder() {
|
||||
.SetVisible(false);
|
||||
}
|
||||
|
||||
views::Builder<views::BoxLayoutView>
|
||||
NotificationViewBase::CreateSnoozeSettingsBuilder() {
|
||||
CHECK(!snooze_row_);
|
||||
return views::Builder<views::BoxLayoutView>()
|
||||
.CopyAddressTo(&snooze_row_)
|
||||
.SetVisible(false);
|
||||
}
|
||||
|
||||
views::Builder<views::View>
|
||||
NotificationViewBase::CreateImageContainerBuilder() {
|
||||
DCHECK(!image_container_view_);
|
||||
@ -825,6 +834,24 @@ void NotificationViewBase::ToggleInlineSettings(const ui::Event& event) {
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationViewBase::ToggleSnoozeSettings(const ui::Event& event) {
|
||||
bool snooze_settings_visible = !snooze_row_->GetVisible();
|
||||
|
||||
snooze_row_->SetVisible(snooze_settings_visible);
|
||||
|
||||
SetSettingMode(snooze_settings_visible);
|
||||
|
||||
// Grab a weak pointer before calling SetExpanded() as it might cause |this|
|
||||
// to be deleted.
|
||||
{
|
||||
auto weak_ptr = weak_ptr_factory_.GetWeakPtr();
|
||||
SetExpanded(!snooze_settings_visible);
|
||||
if (!weak_ptr) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
NotificationControlButtonsView* NotificationViewBase::GetControlButtonsView()
|
||||
const {
|
||||
return control_buttons_view_;
|
||||
@ -863,6 +890,18 @@ void NotificationViewBase::OnSettingsButtonPressed(const ui::Event& event) {
|
||||
MessageView::OnSettingsButtonPressed(event);
|
||||
}
|
||||
|
||||
void NotificationViewBase::OnSnoozeButtonPressed(const ui::Event& event) {
|
||||
for (auto& observer : *observers()) {
|
||||
observer.OnSnoozeButtonPressed(notification_id());
|
||||
}
|
||||
|
||||
if (snooze_settings_enabled_) {
|
||||
ToggleSnoozeSettings(event);
|
||||
} else {
|
||||
MessageView::OnSnoozeButtonPressed(event);
|
||||
}
|
||||
}
|
||||
|
||||
void NotificationViewBase::Activate() {
|
||||
GetWidget()->widget_delegate()->SetCanActivate(true);
|
||||
GetWidget()->Activate();
|
||||
|
@ -110,6 +110,7 @@ class MESSAGE_CENTER_EXPORT NotificationViewBase
|
||||
bool IsManuallyExpandedOrCollapsed() const override;
|
||||
void SetManuallyExpandedOrCollapsed(ExpandState state) override;
|
||||
void OnSettingsButtonPressed(const ui::Event& event) override;
|
||||
void OnSnoozeButtonPressed(const ui::Event& event) override;
|
||||
|
||||
// views::InkDropObserver:
|
||||
void InkDropAnimationStarted() override;
|
||||
@ -149,6 +150,9 @@ class MESSAGE_CENTER_EXPORT NotificationViewBase
|
||||
// Inline settings view contains inline settings.
|
||||
views::Builder<views::BoxLayoutView> CreateInlineSettingsBuilder();
|
||||
|
||||
// Snooze settings view contains snooze settings.
|
||||
views::Builder<views::BoxLayoutView> CreateSnoozeSettingsBuilder();
|
||||
|
||||
// Actions row contains inline action buttons and inline textfield. Use the
|
||||
// given layout manager for the actions row.
|
||||
std::unique_ptr<views::View> CreateActionsRow(
|
||||
@ -191,6 +195,9 @@ class MESSAGE_CENTER_EXPORT NotificationViewBase
|
||||
virtual void CreateOrUpdateInlineSettingsViews(
|
||||
const Notification& notification) = 0;
|
||||
|
||||
virtual void CreateOrUpdateSnoozeSettingsViews(
|
||||
const Notification& notification) = 0;
|
||||
|
||||
// Add view to `left_content_` in its appropriate position according to
|
||||
// `left_content_count_`. Return a pointer to added view.
|
||||
template <typename T>
|
||||
@ -202,10 +209,14 @@ class MESSAGE_CENTER_EXPORT NotificationViewBase
|
||||
// Reorder the view in `left_content_` according to `left_content_count_`.
|
||||
void ReorderViewInLeftContent(views::View* view);
|
||||
|
||||
// Thic function is called when the UI changes from notification view to
|
||||
// This function is called when the UI changes from notification view to
|
||||
// inline settings or vice versa.
|
||||
virtual void ToggleInlineSettings(const ui::Event& event);
|
||||
|
||||
// This function is called when the UI changes from notification view to
|
||||
// snooze settings or vice versa.
|
||||
virtual void ToggleSnoozeSettings(const ui::Event& event);
|
||||
|
||||
// Called when a user clicks on a notification action button, identified by
|
||||
// `index`.
|
||||
virtual void ActionButtonPressed(size_t index, const ui::Event& event);
|
||||
@ -235,6 +246,9 @@ class MESSAGE_CENTER_EXPORT NotificationViewBase
|
||||
views::View* inline_settings_row() { return settings_row_; }
|
||||
const views::View* inline_settings_row() const { return settings_row_; }
|
||||
|
||||
views::View* snooze_settings_row() { return snooze_row_; }
|
||||
const views::View* snooze_settings_row() const { return snooze_row_; }
|
||||
|
||||
views::View* image_container_view() { return image_container_view_; }
|
||||
const views::View* image_container_view() const {
|
||||
return image_container_view_;
|
||||
@ -260,6 +274,11 @@ class MESSAGE_CENTER_EXPORT NotificationViewBase
|
||||
inline_settings_enabled_ = inline_settings_enabled;
|
||||
}
|
||||
|
||||
bool snooze_settings_enabled() const { return snooze_settings_enabled_; }
|
||||
void set_snooze_settings_enabled(bool snooze_settings_enabled) {
|
||||
snooze_settings_enabled_ = snooze_settings_enabled;
|
||||
}
|
||||
|
||||
bool hide_icon_on_expanded() const { return hide_icon_on_expanded_; }
|
||||
|
||||
virtual bool IsExpandable() const = 0;
|
||||
@ -348,11 +367,15 @@ class MESSAGE_CENTER_EXPORT NotificationViewBase
|
||||
// Describes whether the view can display inline settings or not.
|
||||
bool inline_settings_enabled_ = false;
|
||||
|
||||
// Describes whether the view can display snooze settings or not.
|
||||
bool snooze_settings_enabled_ = false;
|
||||
|
||||
// Container views directly attached to this view.
|
||||
raw_ptr<NotificationHeaderView> header_row_ = nullptr;
|
||||
raw_ptr<views::View> content_row_ = nullptr;
|
||||
raw_ptr<views::View> actions_row_ = nullptr;
|
||||
raw_ptr<views::View> settings_row_ = nullptr;
|
||||
raw_ptr<views::View> snooze_row_ = nullptr;
|
||||
|
||||
// Containers for left and right side on |content_row_|
|
||||
raw_ptr<views::View> left_content_ = nullptr;
|
||||
|
@ -96,6 +96,11 @@ class TestNotificationView : public NotificationViewBase {
|
||||
notification.rich_notification_data().settings_button_handler ==
|
||||
message_center::SettingsButtonHandler::INLINE);
|
||||
}
|
||||
void CreateOrUpdateSnoozeSettingsViews(
|
||||
const Notification& notification) override {
|
||||
set_snooze_settings_enabled(notification.notifier_id().type ==
|
||||
message_center::NotifierType::ARC_APPLICATION);
|
||||
}
|
||||
bool IsExpandable() const override { return true; }
|
||||
std::unique_ptr<views::LabelButton> GenerateNotificationLabelButton(
|
||||
views::Button::PressedCallback callback,
|
||||
|
Reference in New Issue
Block a user