Commit 9c8d4962 authored by pkotwicz's avatar pkotwicz Committed by Commit bot

[Athena] Add status icons and system time to the centered home card

BUG=404156
TEST=Manual, see bug

Review URL: https://codereview.chromium.org/483033003

Cr-Commit-Position: refs/heads/master@{#293042}
parent 6e1f2a87
......@@ -3,6 +3,7 @@ include_rules = [
"+athena/env/public",
"+athena/input/public",
"+athena/screen/public",
"+athena/system/public",
"+athena/wm/public",
"+third_party/skia/include",
"+ui/aura",
......
......@@ -5,6 +5,7 @@
#include "athena/home/athena_start_page_view.h"
#include "athena/home/home_card_constants.h"
#include "athena/system/public/system_ui.h"
#include "base/bind.h"
#include "base/strings/string_util.h"
#include "third_party/skia/include/core/SkPaint.h"
......@@ -155,7 +156,8 @@ namespace athena {
const char AthenaStartPageView::kViewClassName[] = "AthenaStartPageView";
AthenaStartPageView::LayoutData::LayoutData()
: logo_opacity(1.0f),
: system_info_opacity(1.0f),
logo_opacity(1.0f),
background_opacity(1.0f) {
}
......@@ -171,6 +173,12 @@ AthenaStartPageView::AthenaStartPageView(
background_->SetFillsBoundsOpaquely(false);
AddChildView(background_);
system_info_view_ =
SystemUI::Get()->CreateSystemInfoView(SystemUI::COLOR_SCHEME_DARK);
system_info_view_->SetPaintToLayer(true);
system_info_view_->SetFillsBoundsOpaquely(false);
AddChildView(system_info_view_);
logo_ = view_delegate->CreateStartPageWebView(
gfx::Size(kWebViewWidth, kWebViewHeight));
logo_->SetPaintToLayer(true);
......@@ -234,6 +242,8 @@ void AthenaStartPageView::SetLayoutState(float layout_state) {
}
void AthenaStartPageView::SetLayoutStateWithAnimation(float layout_state) {
ui::ScopedLayerAnimationSettings system_info(
system_info_view_->layer()->GetAnimator());
ui::ScopedLayerAnimationSettings logo(logo_->layer()->GetAnimator());
ui::ScopedLayerAnimationSettings search_box(
search_box_container_->layer()->GetAnimator());
......@@ -242,6 +252,7 @@ void AthenaStartPageView::SetLayoutStateWithAnimation(float layout_state) {
ui::ScopedLayerAnimationSettings controls(
control_icon_container_->layer()->GetAnimator());
system_info.SetTweenType(gfx::Tween::EASE_IN_OUT);
logo.SetTweenType(gfx::Tween::EASE_IN_OUT);
search_box.SetTweenType(gfx::Tween::EASE_IN_OUT);
icons.SetTweenType(gfx::Tween::EASE_IN_OUT);
......@@ -268,6 +279,7 @@ AthenaStartPageView::LayoutData AthenaStartPageView::CreateBottomBounds(
state.search_box.set_x((width - state.search_box.width()) / 2);
state.search_box.set_y((kHomeCardHeight - state.search_box.height()) / 2);
state.system_info_opacity = 0.0f;
state.logo_opacity = 0.0f;
state.background_opacity = 0.9f;
return state;
......@@ -289,6 +301,7 @@ AthenaStartPageView::LayoutData AthenaStartPageView::CreateCenteredBounds(
state.controls.set_x(width / 2 + kIconMargin / 2 + kIconMargin % 2);
state.controls.set_y(state.icons.y());
state.system_info_opacity = 1.0f;
state.logo_opacity = 1.0f;
state.background_opacity = 1.0f;
return state;
......@@ -364,6 +377,10 @@ void AthenaStartPageView::OnSearchResultLayoutAnimationCompleted(
void AthenaStartPageView::Layout() {
search_results_view_->SetVisible(false);
system_info_view_->SetBounds(
0, 0, width(), system_info_view_->GetPreferredSize().height());
gfx::Rect logo_bounds(x() + width() / 2 - kWebViewWidth / 2, y() + kTopMargin,
kWebViewWidth, kWebViewHeight);
logo_->SetBoundsRect(logo_bounds);
......@@ -371,6 +388,12 @@ void AthenaStartPageView::Layout() {
LayoutData bottom_bounds = CreateBottomBounds(width());
LayoutData centered_bounds = CreateCenteredBounds(width());
system_info_view_->layer()->SetOpacity(gfx::Tween::FloatValueBetween(
gfx::Tween::CalculateValue(gfx::Tween::EASE_IN_2, layout_state_),
bottom_bounds.system_info_opacity, centered_bounds.system_info_opacity));
system_info_view_->SetVisible(
system_info_view_->layer()->GetTargetOpacity() != 0.0f);
logo_->layer()->SetOpacity(gfx::Tween::FloatValueBetween(
gfx::Tween::CalculateValue(gfx::Tween::EASE_IN_2, layout_state_),
bottom_bounds.logo_opacity, centered_bounds.logo_opacity));
......
......@@ -45,6 +45,7 @@ class ATHENA_EXPORT AthenaStartPageView
gfx::Rect search_box;
gfx::Rect icons;
gfx::Rect controls;
float system_info_opacity;
float logo_opacity;
float background_opacity;
......@@ -76,6 +77,7 @@ class ATHENA_EXPORT AthenaStartPageView
app_list::AppListViewDelegate* delegate_;
// Views are owned through its hierarchy.
views::View* system_info_view_;
views::View* app_icon_container_;
views::View* search_box_container_;
views::View* control_icon_container_;
......
......@@ -5,7 +5,7 @@
#include "athena/home/athena_start_page_view.h"
#include "athena/home/home_card_constants.h"
#include "base/command_line.h"
#include "athena/test/athena_test_base.h"
#include "base/format_macros.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
......@@ -16,7 +16,6 @@
#include "ui/app_list/views/search_box_view.h"
#include "ui/gfx/geometry/rect.h"
#include "ui/views/controls/textfield/textfield.h"
#include "ui/views/test/views_test_base.h"
namespace athena {
......@@ -41,16 +40,14 @@ class AthenaTestViewDelegate : public app_list::test::AppListTestViewDelegate {
DISALLOW_COPY_AND_ASSIGN(AthenaTestViewDelegate);
};
class AthenaStartPageViewTest : public views::ViewsTestBase {
class AthenaStartPageViewTest : public test::AthenaTestBase {
public:
AthenaStartPageViewTest() {}
virtual ~AthenaStartPageViewTest() {}
// testing::Test:
virtual void SetUp() OVERRIDE {
views::ViewsTestBase::SetUp();
base::CommandLine::ForCurrentProcess()->AppendSwitch(
app_list::switches::kEnableExperimentalAppList);
test::AthenaTestBase::SetUp();
app_list::test::AppListTestModel* model = view_delegate_.GetTestModel();
for (size_t i = 0; i < kNumApps; ++i) {
model->AddItem(new app_list::test::AppListTestModel::AppListTestItem(
......@@ -62,7 +59,7 @@ class AthenaStartPageViewTest : public views::ViewsTestBase {
}
virtual void TearDown() OVERRIDE {
view_.reset();
views::ViewsTestBase::TearDown();
test::AthenaTestBase::TearDown();
}
protected:
......
......@@ -16,11 +16,10 @@ namespace athena {
class BackgroundView : public views::View {
public:
BackgroundView()
: time_view_(SystemUI::Get()->CreateTimeView()),
status_icon_view_(SystemUI::Get()->CreateStatusIconView()) {
AddChildView(time_view_);
AddChildView(status_icon_view_);
BackgroundView() : system_info_view_(NULL) {
system_info_view_ =
SystemUI::Get()->CreateSystemInfoView(SystemUI::COLOR_SCHEME_LIGHT);
AddChildView(system_info_view_);
}
virtual ~BackgroundView() {}
......@@ -31,18 +30,8 @@ class BackgroundView : public views::View {
// views::View:
virtual void Layout() OVERRIDE {
time_view_->SetBoundsRect(gfx::Rect(time_view_->GetPreferredSize()));
gfx::Size status_icon_preferred_size =
status_icon_view_->GetPreferredSize();
status_icon_view_->SetBounds(width() - status_icon_preferred_size.width(),
0,
status_icon_preferred_size.width(),
status_icon_preferred_size.height());
}
virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE {
// Relayout when |status_icon_view_| changes its preferred size.
Layout();
system_info_view_->SetBounds(
0, 0, width(), system_info_view_->GetPreferredSize().height());
}
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
......@@ -60,8 +49,7 @@ class BackgroundView : public views::View {
private:
gfx::ImageSkia image_;
views::View* time_view_;
views::View* status_icon_view_;
views::View* system_info_view_;
DISALLOW_COPY_AND_ASSIGN(BackgroundView);
};
......
......@@ -24,6 +24,11 @@ namespace athena {
class ATHENA_EXPORT SystemUI {
public:
enum ColorScheme {
COLOR_SCHEME_LIGHT,
COLOR_SCHEME_DARK
};
// Creates and deletes the singleton object of the SystemUI implementation.
static SystemUI* Create(scoped_refptr<base::TaskRunner> io_task_runner);
static SystemUI* Get();
......@@ -34,11 +39,9 @@ class ATHENA_EXPORT SystemUI {
// Sets the background image.
virtual void SetBackgroundImage(const gfx::ImageSkia& image) = 0;
// Creates a view which displays the time.
virtual views::View* CreateTimeView() = 0;
// Creates a view which displays status icons and debug information.
virtual views::View* CreateStatusIconView() = 0;
// Creates a view which displays the time, status icons, and debug
// information.
virtual views::View* CreateSystemInfoView(ColorScheme color_scheme) = 0;
};
} // namespace athena
......
......@@ -31,10 +31,14 @@
namespace athena {
namespace {
views::Label* CreateLabel(const std::string& text) {
views::Label* CreateLabel(SystemUI::ColorScheme color_scheme,
const std::string& text) {
views::Label* label = new views::Label(base::UTF8ToUTF16(text));
label->SetEnabledColor(SK_ColorWHITE);
label->SetEnabledColor((color_scheme == SystemUI::COLOR_SCHEME_LIGHT)
? SK_ColorWHITE
: SK_ColorDKGRAY);
label->SetAutoColorReadabilityEnabled(false);
label->SetSubpixelRenderingEnabled(false);
label->SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD));
return label;
}
......@@ -44,7 +48,10 @@ views::Label* CreateLabel(const std::string& text) {
class StatusIconContainerView::PowerStatus
: public chromeos::PowerManagerClient::Observer {
public:
explicit PowerStatus(views::ImageView* icon) : icon_(icon) {
PowerStatus(SystemUI::ColorScheme color_scheme,
views::ImageView* icon)
: color_scheme_(color_scheme),
icon_(icon) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
chromeos::DBusThreadManager::Get()
......@@ -68,7 +75,9 @@ class StatusIconContainerView::PowerStatus
const int kNumPowerImages = 15;
gfx::Image all = ui::ResourceBundle::GetSharedInstance().GetImageNamed(
IDR_AURA_UBER_TRAY_POWER_SMALL);
(color_scheme_ == SystemUI::COLOR_SCHEME_LIGHT)
? IDR_AURA_UBER_TRAY_POWER_SMALL
: IDR_AURA_UBER_TRAY_POWER_SMALL_DARK);
int horiz_offset = IsCharging(proto) ? 1 : 0;
int vert_offset = -1;
if (proto.battery_percent() >= 100) {
......@@ -96,6 +105,7 @@ class StatusIconContainerView::PowerStatus
icon_->SetImage(GetPowerIcon(proto));
}
SystemUI::ColorScheme color_scheme_;
views::ImageView* icon_;
DISALLOW_COPY_AND_ASSIGN(PowerStatus);
......@@ -162,7 +172,9 @@ void StartUpdateCallback(
class StatusIconContainerView::UpdateStatus
: public chromeos::UpdateEngineClient::Observer {
public:
explicit UpdateStatus(views::ImageView* icon) : icon_(icon) {
UpdateStatus(SystemUI::ColorScheme color_scheme, views::ImageView* icon)
: color_scheme_(color_scheme),
icon_(icon) {
chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->AddObserver(
this);
chromeos::DBusThreadManager::Get()->GetUpdateEngineClient()->
......@@ -181,17 +193,22 @@ class StatusIconContainerView::UpdateStatus
chromeos::UpdateEngineClient::UPDATE_STATUS_UPDATED_NEED_REBOOT) {
return;
}
icon_->SetImage(ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(
IDR_AURA_UBER_TRAY_UPDATE));
int image_id = (color_scheme_ == SystemUI::COLOR_SCHEME_LIGHT)
? IDR_AURA_UBER_TRAY_UPDATE
: IDR_AURA_UBER_TRAY_UPDATE_DARK;
icon_->SetImage(
ui::ResourceBundle::GetSharedInstance().GetImageSkiaNamed(image_id));
}
private:
SystemUI::ColorScheme color_scheme_;
views::ImageView* icon_;
DISALLOW_COPY_AND_ASSIGN(UpdateStatus);
};
StatusIconContainerView::StatusIconContainerView(
SystemUI::ColorScheme color_scheme,
aura::Window* system_modal_container)
: system_modal_container_(system_modal_container) {
const int kHorizontalSpacing = 10;
......@@ -204,20 +221,20 @@ StatusIconContainerView::StatusIconContainerView(
std::string version_text =
base::StringPrintf("%s (Build %s)", PRODUCT_VERSION, LAST_CHANGE);
AddChildView(CreateLabel(version_text));
AddChildView(CreateLabel(color_scheme, version_text));
AddChildView(CreateLabel("Network:"));
views::Label* network_label = CreateLabel(std::string());
AddChildView(CreateLabel(color_scheme, "Network:"));
views::Label* network_label = CreateLabel(color_scheme, std::string());
AddChildView(network_label);
network_status_.reset(new NetworkStatus(network_label));
views::ImageView* battery_view = new views::ImageView();
AddChildView(battery_view);
power_status_.reset(new PowerStatus(battery_view));
power_status_.reset(new PowerStatus(color_scheme, battery_view));
views::ImageView* update_view = new views::ImageView();
AddChildView(update_view);
update_status_.reset(new UpdateStatus(update_view));
update_status_.reset(new UpdateStatus(color_scheme, update_view));
}
StatusIconContainerView::~StatusIconContainerView() {
......
......@@ -18,7 +18,8 @@ namespace athena {
// View which displays the system tray icons.
class StatusIconContainerView : public views::View {
public:
explicit StatusIconContainerView(aura::Window* system_modal_container);
StatusIconContainerView(SystemUI::ColorScheme color_scheme,
aura::Window* popup_container);
virtual ~StatusIconContainerView();
private:
......
......@@ -17,12 +17,62 @@
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "ui/aura/window.h"
#include "ui/views/view.h"
namespace athena {
namespace {
SystemUI* instance = NULL;
// View which positions the TimeView on the left and the StatusIconView on the
// right.
class SystemInfoView : public views::View {
public:
SystemInfoView(SystemUI::ColorScheme color_scheme,
aura::Window* system_modal_container)
: time_view_(new TimeView(color_scheme)),
status_icon_view_(
new StatusIconContainerView(color_scheme, system_modal_container)) {
AddChildView(time_view_);
AddChildView(status_icon_view_);
}
virtual ~SystemInfoView() {
}
// views::View:
virtual gfx::Size GetPreferredSize() const OVERRIDE {
// The view should be as wide as its parent view.
return gfx::Size(0,
std::max(time_view_->GetPreferredSize().height(),
status_icon_view_->GetPreferredSize().height()));
}
virtual void Layout() OVERRIDE {
time_view_->SetBoundsRect(gfx::Rect(time_view_->GetPreferredSize()));
gfx::Size status_icon_preferred_size =
status_icon_view_->GetPreferredSize();
status_icon_view_->SetBoundsRect(
gfx::Rect(width() - status_icon_preferred_size.width(),
0,
status_icon_preferred_size.width(),
status_icon_preferred_size.height()));
}
virtual void ChildPreferredSizeChanged(views::View* child) OVERRIDE {
// Relayout to take into account changes in |status_icon_view_|'s width.
// Assume that |time_view_|'s and |status_icon_view_|'s preferred height
// does not change.
Layout();
}
private:
views::View* time_view_;
views::View* status_icon_view_;
DISALLOW_COPY_AND_ASSIGN(SystemInfoView);
};
class SystemUIImpl : public SystemUI {
public:
SystemUIImpl(scoped_refptr<base::TaskRunner> file_task_runner)
......@@ -58,12 +108,8 @@ class SystemUIImpl : public SystemUI {
background_controller_->SetImage(image);
}
virtual views::View* CreateTimeView() OVERRIDE {
return new TimeView;
}
virtual views::View* CreateStatusIconView() OVERRIDE {
return new StatusIconContainerView(system_modal_container_);
virtual views::View* CreateSystemInfoView(ColorScheme color_scheme) OVERRIDE {
return new SystemInfoView(color_scheme, system_modal_container_);
}
private:
......
......@@ -17,11 +17,14 @@ const int kTimerSlopSeconds = 1;
} // namespace
TimeView::TimeView() {
TimeView::TimeView(SystemUI::ColorScheme color_scheme) {
SetHorizontalAlignment(gfx::ALIGN_LEFT);
SetEnabledColor(SK_ColorWHITE);
SetEnabledColor((color_scheme == SystemUI::COLOR_SCHEME_LIGHT)
? SK_ColorWHITE
: SK_ColorDKGRAY);
SetAutoColorReadabilityEnabled(false);
SetFontList(gfx::FontList().DeriveWithStyle(gfx::Font::BOLD));
SetSubpixelRenderingEnabled(false);
const int kHorizontalSpacing = 10;
const int kVerticalSpacing = 3;
......
......@@ -15,7 +15,7 @@ namespace athena {
// View which displays the current time.
class TimeView : public views::Label {
public:
TimeView();
explicit TimeView(SystemUI::ColorScheme color_scheme);
virtual ~TimeView();
private:
......
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