Commit 4e5bd297 authored by Andre Le's avatar Andre Le Committed by Commit Bot

[CrOS PhoneHub] Add "From Phone" label to CrOS PhoneHub Notification.

- Add customized notification view to phone hub notification controller.
- Add "From Phone" to the notification's header.
- Add IDs to NotificationViewMD to access the header in the view.

Screenshot: https://screenshot.googleplex.com/3kW99Ch5wGvVrGz

BUG=1106937,1126208

Change-Id: I0d0726d0d05c967384db702a557ba7a2895d77c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2464163
Commit-Queue: Andre Le <leandre@chromium.org>
Reviewed-by: default avatarTim Song <tengs@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Cr-Commit-Position: refs/heads/master@{#816646}
parent b5e4f7f7
...@@ -1100,6 +1100,9 @@ This file contains the strings for ash. ...@@ -1100,6 +1100,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_PHONE_HUB_BLUETOOTH_DISABLED_DIALOG_LEARN_MORE_BUTTON" desc="Learn more button on the bluetooth disabled dialog to show more related information."> <message name="IDS_ASH_PHONE_HUB_BLUETOOTH_DISABLED_DIALOG_LEARN_MORE_BUTTON" desc="Learn more button on the bluetooth disabled dialog to show more related information.">
Learn more Learn more
</message> </message>
<message name="IDS_ASH_PHONE_HUB_NOTIFICATION_FROM_PHONE_TITLE" desc="The title at the header of PhoneHub notification, indicating that this notification was coming from the connected phone.">
From Phone
</message>
<message name="IDS_ASH_PHONE_HUB_NOTIFICATION_INLINE_REPLY_BUTTON" desc="Label for the inline reply button inside a PhoneHub notification."> <message name="IDS_ASH_PHONE_HUB_NOTIFICATION_INLINE_REPLY_BUTTON" desc="Label for the inline reply button inside a PhoneHub notification.">
Reply Reply
</message> </message>
......
9cc1f57092e64a415e36c5a377cdba7216e3a31b
\ No newline at end of file
...@@ -9,6 +9,7 @@ ...@@ -9,6 +9,7 @@
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/model/system_tray_model.h" #include "ash/system/model/system_tray_model.h"
#include "ash/system/tray/tray_popup_utils.h" #include "ash/system/tray/tray_popup_utils.h"
#include "base/bind.h"
#include "base/logging.h" #include "base/logging.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/strings/strcat.h" #include "base/strings/strcat.h"
...@@ -19,14 +20,35 @@ ...@@ -19,14 +20,35 @@
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/message_center/public/cpp/notification.h" #include "ui/message_center/public/cpp/notification.h"
#include "ui/message_center/public/cpp/notification_delegate.h" #include "ui/message_center/public/cpp/notification_delegate.h"
#include "ui/message_center/views/message_view_factory.h"
#include "ui/message_center/views/notification_header_view.h"
#include "ui/message_center/views/notification_view_md.h"
namespace ash { namespace ash {
namespace { namespace {
const char kNotifierId[] = "chrome://phonehub"; const char kNotifierId[] = "chrome://phonehub";
const char kNotifierIdSeparator[] = "-"; const char kNotifierIdSeparator[] = "-";
const char kNotificationCustomViewType[] = "phonehub";
const int kReplyButtonIndex = 0; const int kReplyButtonIndex = 0;
const int kCancelButtonIndex = 1; const int kCancelButtonIndex = 1;
std::unique_ptr<message_center::MessageView> CreateCustomNotificationView(
const message_center::Notification& notification) {
DCHECK_EQ(kNotificationCustomViewType, notification.custom_view_type());
std::unique_ptr<message_center::NotificationViewMD> notification_view =
std::make_unique<message_center::NotificationViewMD>(notification);
message_center::NotificationHeaderView* header_row =
static_cast<message_center::NotificationHeaderView*>(
notification_view->GetViewByID(
message_center::NotificationViewMD::kHeaderRow));
header_row->SetSummaryText(l10n_util::GetStringUTF16(
IDS_ASH_PHONE_HUB_NOTIFICATION_FROM_PHONE_TITLE));
return notification_view;
}
} // namespace } // namespace
// Delegate for the displayed ChromeOS notification. // Delegate for the displayed ChromeOS notification.
...@@ -101,7 +123,11 @@ class PhoneHubNotificationController::NotificationDelegate ...@@ -101,7 +123,11 @@ class PhoneHubNotificationController::NotificationDelegate
base::WeakPtrFactory<NotificationDelegate> weak_ptr_factory_{this}; base::WeakPtrFactory<NotificationDelegate> weak_ptr_factory_{this};
}; };
PhoneHubNotificationController::PhoneHubNotificationController() = default; PhoneHubNotificationController::PhoneHubNotificationController() {
message_center::MessageViewFactory::SetCustomNotificationViewFactory(
kNotificationCustomViewType,
base::BindRepeating(&CreateCustomNotificationView));
}
PhoneHubNotificationController::~PhoneHubNotificationController() { PhoneHubNotificationController::~PhoneHubNotificationController() {
if (manager_) if (manager_)
...@@ -178,6 +204,7 @@ void PhoneHubNotificationController::CreateOrUpdateNotification( ...@@ -178,6 +204,7 @@ void PhoneHubNotificationController::CreateOrUpdateNotification(
NotificationDelegate* delegate = notification_map_[phone_hub_id].get(); NotificationDelegate* delegate = notification_map_[phone_hub_id].get();
auto cros_notification = CreateNotification(notification, cros_id, delegate); auto cros_notification = CreateNotification(notification, cros_id, delegate);
cros_notification->set_custom_view_type(kNotificationCustomViewType);
auto* message_center = message_center::MessageCenter::Get(); auto* message_center = message_center::MessageCenter::Get();
if (notification_already_exists) if (notification_already_exists)
...@@ -194,7 +221,7 @@ PhoneHubNotificationController::CreateNotification( ...@@ -194,7 +221,7 @@ PhoneHubNotificationController::CreateNotification(
message_center::NotifierId notifier_id( message_center::NotifierId notifier_id(
message_center::NotifierType::SYSTEM_COMPONENT, kNotifierId); message_center::NotifierType::SYSTEM_COMPONENT, kNotifierId);
auto notification_type = message_center::NOTIFICATION_TYPE_SIMPLE; auto notification_type = message_center::NOTIFICATION_TYPE_CUSTOM;
base::string16 title = notification->title().value_or(base::string16()); base::string16 title = notification->title().value_or(base::string16());
base::string16 message = base::string16 message =
...@@ -208,10 +235,8 @@ PhoneHubNotificationController::CreateNotification( ...@@ -208,10 +235,8 @@ PhoneHubNotificationController::CreateNotification(
optional_fields.timestamp = notification->timestamp(); optional_fields.timestamp = notification->timestamp();
auto shared_image = notification->shared_image(); auto shared_image = notification->shared_image();
if (shared_image.has_value()) { if (shared_image.has_value())
optional_fields.image = shared_image.value(); optional_fields.image = shared_image.value();
notification_type = message_center::NOTIFICATION_TYPE_IMAGE;
}
const gfx::Image& icon = notification->contact_image().value_or(gfx::Image()); const gfx::Image& icon = notification->contact_image().value_or(gfx::Image());
......
...@@ -600,6 +600,7 @@ NotificationViewMD::NotificationViewMD(const Notification& notification) ...@@ -600,6 +600,7 @@ NotificationViewMD::NotificationViewMD(const Notification& notification)
header_row_ = new NotificationHeaderView(this); header_row_ = new NotificationHeaderView(this);
header_row_->SetPreferredSize(header_row_->GetPreferredSize() - header_row_->SetPreferredSize(header_row_->GetPreferredSize() -
gfx::Size(GetInsets().width(), 0)); gfx::Size(GetInsets().width(), 0));
header_row_->SetID(kHeaderRow);
control_buttons_view_ = header_row_->AddChildView( control_buttons_view_ = header_row_->AddChildView(
std::make_unique<NotificationControlButtonsView>(this)); std::make_unique<NotificationControlButtonsView>(this));
AddChildView(header_row_); AddChildView(header_row_);
......
...@@ -168,6 +168,13 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD ...@@ -168,6 +168,13 @@ class MESSAGE_CENTER_EXPORT NotificationViewMD
public NotificationInputDelegate, public NotificationInputDelegate,
public views::ButtonListener { public views::ButtonListener {
public: public:
// This defines an enumeration of IDs that can uniquely identify a view within
// the scope of NotificationViewMD.
enum ViewId {
// We start from 1 because 0 is the default view ID.
kHeaderRow = 1,
};
explicit NotificationViewMD(const Notification& notification); explicit NotificationViewMD(const Notification& notification);
~NotificationViewMD() override; ~NotificationViewMD() override;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment