Commit 50d8a729 authored by Meilin Wang's avatar Meilin Wang Committed by Commit Bot

[CrOS PhoneHub] Add phone status view for edge case UIs.

This CL moves the existing |PhoneStatusView| out of the |PhoneHubView|
and adds it as a separate child view of the bubble, so that it can always
show on top of UIs and display available phone information and the
settings icon.

Misc: remove unnecessary header files.

Screenshot: https://screenshot.googleplex.com/6DXqin6MZPcTVVj.png

BUG=1106937,1126208

Change-Id: I321d0511874cfa95dcbb8276fedf41b14e0f684b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2429390Reviewed-by: default avatarTim Song <tengs@chromium.org>
Reviewed-by: default avatarKyle Horimoto <khorimoto@chromium.org>
Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Reviewed-by: default avatarMeilin Wang <meilinw@chromium.org>
Commit-Queue: Meilin Wang <meilinw@chromium.org>
Cr-Commit-Position: refs/heads/master@{#810830}
parent 30dea2af
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define ASH_SYSTEM_PHONEHUB_BLUETOOTH_DISABLED_VIEW_H_ #define ASH_SYSTEM_PHONEHUB_BLUETOOTH_DISABLED_VIEW_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/system/phonehub/phone_hub_interstitial_view.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
namespace ash { namespace ash {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define ASH_SYSTEM_PHONEHUB_CONNECTION_ERROR_VIEW_H_ #define ASH_SYSTEM_PHONEHUB_CONNECTION_ERROR_VIEW_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/system/phonehub/phone_hub_interstitial_view.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
namespace ash { namespace ash {
......
...@@ -6,7 +6,6 @@ ...@@ -6,7 +6,6 @@
#define ASH_SYSTEM_PHONEHUB_INITIAL_CONNECTING_VIEW_H_ #define ASH_SYSTEM_PHONEHUB_INITIAL_CONNECTING_VIEW_H_
#include "ash/ash_export.h" #include "ash/ash_export.h"
#include "ash/system/phonehub/phone_hub_interstitial_view.h"
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/metadata/metadata_header_macros.h" #include "ui/views/metadata/metadata_header_macros.h"
......
...@@ -33,7 +33,7 @@ constexpr int kGetStartedTag = 2; ...@@ -33,7 +33,7 @@ constexpr int kGetStartedTag = 2;
OnboardingView::OnboardingView() { OnboardingView::OnboardingView() {
SetLayoutManager(std::make_unique<views::FillLayout>()); SetLayoutManager(std::make_unique<views::FillLayout>());
content_view_ = AddChildView( content_view_ = AddChildView(
std::make_unique<PhoneHubInterstitialView>(/*show_progress=*/true)); std::make_unique<PhoneHubInterstitialView>(/*show_progress=*/false));
// TODO(crbug.com/1127996): Replace PNG file with vector icon. // TODO(crbug.com/1127996): Replace PNG file with vector icon.
gfx::ImageSkia* image = gfx::ImageSkia* image =
......
...@@ -48,8 +48,8 @@ constexpr gfx::Insets kBubblePadding(4, 16); ...@@ -48,8 +48,8 @@ constexpr gfx::Insets kBubblePadding(4, 16);
constexpr int kBubbleWidth = 400; constexpr int kBubbleWidth = 400;
constexpr int kPaddingBetweenTitleAndSeparator = 3; constexpr int kPaddingBetweenTitleAndSeparator = 3;
// A view of the Phone Hub panel, displaying phone status and utility actions // A content view of the Phone Hub panel, displaying utility actions
// such as phone status, task continuation, etc. // such as quick actions, task continuation, etc.
class PhoneHubView : public views ::View { class PhoneHubView : public views ::View {
public: public:
explicit PhoneHubView(TrayBubbleView* bubble_view, explicit PhoneHubView(TrayBubbleView* bubble_view,
...@@ -60,14 +60,6 @@ class PhoneHubView : public views ::View { ...@@ -60,14 +60,6 @@ class PhoneHubView : public views ::View {
view->layer()->SetFillsBoundsOpaquely(false); view->layer()->SetFillsBoundsOpaquely(false);
}; };
chromeos::phonehub::PhoneModel* phone_model =
phone_hub_manager->GetPhoneModel();
if (phone_model) {
setup_layered_view(bubble_view->AddChildView(
std::make_unique<PhoneStatusView>(phone_model)));
}
AddSeparator(); AddSeparator();
// TODO(meilinw): handle the case when the user has dismissed this opt in // TODO(meilinw): handle the case when the user has dismissed this opt in
...@@ -83,6 +75,9 @@ class PhoneHubView : public views ::View { ...@@ -83,6 +75,9 @@ class PhoneHubView : public views ::View {
AddSeparator(); AddSeparator();
chromeos::phonehub::PhoneModel* phone_model =
phone_hub_manager->GetPhoneModel();
if (phone_model) { if (phone_model) {
setup_layered_view(bubble_view->AddChildView( setup_layered_view(bubble_view->AddChildView(
std::make_unique<TaskContinuationView>(phone_model))); std::make_unique<TaskContinuationView>(phone_model)));
...@@ -218,6 +213,20 @@ void PhoneHubTray::ShowBubble(bool show_by_click) { ...@@ -218,6 +213,20 @@ void PhoneHubTray::ShowBubble(bool show_by_click) {
bubble_view->set_margins(GetSecondaryBubbleInsets()); bubble_view->set_margins(GetSecondaryBubbleInsets());
bubble_view->SetBorder(views::CreateEmptyBorder(kBubblePadding)); bubble_view->SetBorder(views::CreateEmptyBorder(kBubblePadding));
// We will always have this phone status view on top of the bubble view
// to display any available phone status and the settings icon.
chromeos::phonehub::PhoneModel* phone_model =
phone_hub_manager_->GetPhoneModel();
if (phone_model) {
auto* phone_status = bubble_view->AddChildView(
std::make_unique<PhoneStatusView>(phone_model));
phone_status->SetPaintToLayer();
phone_status->layer()->SetFillsBoundsOpaquely(false);
}
// Other contents, i.e. the connected view and the interstitial views,
// will be positioned underneath the phone status view and updated based
// on the current mode.
bubble_view->AddChildView( bubble_view->AddChildView(
std::make_unique<PhoneHubView>(bubble_view, phone_hub_manager_)); std::make_unique<PhoneHubView>(bubble_view, phone_hub_manager_));
......
...@@ -13,9 +13,11 @@ ...@@ -13,9 +13,11 @@
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_item_style.h" #include "ash/system/tray/tray_popup_item_style.h"
#include "base/i18n/number_formatting.h" #include "base/i18n/number_formatting.h"
#include "base/strings/string16.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/color_utils.h" #include "ui/gfx/color_utils.h"
#include "ui/gfx/geometry/insets.h" #include "ui/gfx/geometry/insets.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
...@@ -119,8 +121,12 @@ void PhoneStatusView::Update() { ...@@ -119,8 +121,12 @@ void PhoneStatusView::Update() {
phone_name_label_->SetText( phone_name_label_->SetText(
phone_model_->phone_name().value_or(base::string16())); phone_model_->phone_name().value_or(base::string16()));
if (!phone_model_->phone_status_model()) // Clear the phone status if the status model returns null when the phone is
// disconnected.
if (!phone_model_->phone_status_model()) {
ClearExistingStatus();
return; return;
}
UpdateMobileStatus(); UpdateMobileStatus();
UpdateBatteryStatus(); UpdateBatteryStatus();
...@@ -207,6 +213,16 @@ PowerStatus::BatteryImageInfo PhoneStatusView::CalculateBatteryInfo() { ...@@ -207,6 +213,16 @@ PowerStatus::BatteryImageInfo PhoneStatusView::CalculateBatteryInfo() {
return info; return info;
} }
void PhoneStatusView::ClearExistingStatus() {
// Clear mobile status.
signal_icon_->SetImage(gfx::ImageSkia());
mobile_provider_label_->SetText(base::string16());
// Clear battery status.
battery_icon_->SetImage(gfx::ImageSkia());
battery_label_->SetText(base::string16());
}
void PhoneStatusView::ConfigureTriViewContainer(TriView::Container container) { void PhoneStatusView::ConfigureTriViewContainer(TriView::Container container) {
std::unique_ptr<views::BoxLayout> layout; std::unique_ptr<views::BoxLayout> layout;
......
...@@ -48,6 +48,9 @@ class ASH_EXPORT PhoneStatusView ...@@ -48,6 +48,9 @@ class ASH_EXPORT PhoneStatusView
void UpdateBatteryStatus(); void UpdateBatteryStatus();
PowerStatus::BatteryImageInfo CalculateBatteryInfo(); PowerStatus::BatteryImageInfo CalculateBatteryInfo();
// Clear the existing labels and icons for the phone status.
void ClearExistingStatus();
void ConfigureTriViewContainer(TriView::Container container); void ConfigureTriViewContainer(TriView::Container container);
chromeos::phonehub::PhoneModel* phone_model_ = nullptr; chromeos::phonehub::PhoneModel* phone_model_ = nullptr;
......
...@@ -5,10 +5,12 @@ ...@@ -5,10 +5,12 @@
#include "ash/system/phonehub/phone_status_view.h" #include "ash/system/phonehub/phone_status_view.h"
#include "ash/test/ash_test_base.h" #include "ash/test/ash_test_base.h"
#include "base/optional.h"
#include "base/strings/utf_string_conversions.h" #include "base/strings/utf_string_conversions.h"
#include "base/test/scoped_feature_list.h" #include "base/test/scoped_feature_list.h"
#include "chromeos/components/phonehub/mutable_phone_model.h" #include "chromeos/components/phonehub/mutable_phone_model.h"
#include "chromeos/constants/chromeos_features.h" #include "chromeos/constants/chromeos_features.h"
#include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
namespace ash { namespace ash {
...@@ -113,6 +115,15 @@ TEST_F(PhoneStatusViewTest, PhoneStatusLabelsContent) { ...@@ -113,6 +115,15 @@ TEST_F(PhoneStatusViewTest, PhoneStatusLabelsContent) {
EXPECT_EQ(expected_provider_text, EXPECT_EQ(expected_provider_text,
status_view()->mobile_provider_label_->GetText()); status_view()->mobile_provider_label_->GetText());
EXPECT_EQ(expected_battery_text, status_view()->battery_label_->GetText()); EXPECT_EQ(expected_battery_text, status_view()->battery_label_->GetText());
// Simulate phone disconnected with a null |PhoneStatusModel| returned.
phone_model()->SetPhoneStatusModel(base::nullopt);
// Existing phone status will be cleared to reflect the model change.
EXPECT_TRUE(status_view()->mobile_provider_label_->GetText().empty());
EXPECT_TRUE(status_view()->battery_label_->GetText().empty());
EXPECT_TRUE(status_view()->battery_icon_->GetImage().isNull());
EXPECT_TRUE(status_view()->signal_icon_->GetImage().isNull());
} }
} // namespace ash } // namespace ash
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