Commit 7128d461 authored by sadrul@chromium.org's avatar sadrul@chromium.org

athena: Show network and battery status in the UI.

The status of network and battery is displayed in a text-only view in
this patch at the top-right corner of the screen.

BUG=387202, 387204
R=oshima@chromium.org

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@279312 0039d316-1c4b-4281-b951-d872f2087c98
parent b58fa312
......@@ -12,6 +12,7 @@
#include "athena/home/public/home_card.h"
#include "athena/main/athena_app_window_controller.h"
#include "athena/main/athena_launcher.h"
#include "athena/main/debug/debug_window.h"
#include "athena/main/placeholder.h"
#include "athena/main/url_search_provider.h"
#include "athena/virtual_keyboard/public/virtual_keyboard_bindings.h"
......@@ -61,6 +62,7 @@ class AthenaBrowserMainDelegate : public apps::ShellBrowserMainDelegate {
athena::VirtualKeyboardManager::Create(context);
CreateTestPages(context);
CreateDebugWindow();
}
virtual void Shutdown() OVERRIDE { athena::ShutdownAthena(); }
......
......@@ -14,6 +14,7 @@
'../athena.gyp:athena_lib',
'../athena.gyp:athena_content_lib',
'../../apps/shell/app_shell.gyp:app_shell_lib',
'../../chromeos/chromeos.gyp:power_manager_proto',
'../../skia/skia.gyp:skia',
'../../ui/accessibility/accessibility.gyp:ax_gen',
'../../ui/app_list/app_list.gyp:app_list',
......@@ -29,6 +30,8 @@
'athena_app_window_controller.h',
'athena_launcher.cc',
'athena_launcher.h',
'debug/debug_window.cc',
'debug/debug_window.h',
'url_search_provider.cc',
'url_search_provider.h',
'athena_main.cc',
......
include_rules = [
"+chromeos",
"+ui/aura",
"+ui/views",
]
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "athena/main/debug/debug_window.h"
#include "athena/screen/public/screen_manager.h"
#include "base/bind.h"
#include "base/macros.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
#include "chromeos/dbus/power_manager_client.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "chromeos/network/network_state_handler_observer.h"
#include "ui/aura/window.h"
#include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/label.h"
#include "ui/views/layout/box_layout.h"
#include "ui/views/view.h"
#include "ui/views/widget/widget.h"
namespace {
views::Label* CreateDebugLabel(const std::string& text) {
views::Label* label = new views::Label(base::UTF8ToUTF16(text));
label->SetEnabledColor(SK_ColorWHITE);
label->SetBackgroundColor(SK_ColorTRANSPARENT);
label->SetFontList(gfx::FontList().Derive(-2, gfx::Font::BOLD));
return label;
}
class PowerStatus : public chromeos::PowerManagerClient::Observer {
public:
PowerStatus(views::Label* label, const base::Closure& closure)
: label_(label), closure_(closure) {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->AddObserver(
this);
chromeos::DBusThreadManager::Get()
->GetPowerManagerClient()
->RequestStatusUpdate();
}
virtual ~PowerStatus() {
chromeos::DBusThreadManager::Get()->GetPowerManagerClient()->RemoveObserver(
this);
}
private:
// chromeos::PowerManagerClient::Observer:
virtual void PowerChanged(
const power_manager::PowerSupplyProperties& proto) OVERRIDE {
std::string output =
proto.is_calculating_battery_time()
? "Calculating..."
: base::StringPrintf("%.1lf%%", proto.battery_percent());
label_->SetText(base::UTF8ToUTF16(output));
if (!closure_.is_null())
closure_.Run();
}
views::Label* label_;
base::Closure closure_;
DISALLOW_COPY_AND_ASSIGN(PowerStatus);
};
class NetworkStatus : public chromeos::NetworkStateHandlerObserver {
public:
NetworkStatus(views::Label* label, const base::Closure& closure)
: label_(label), closure_(closure) {
chromeos::NetworkStateHandler* handler =
chromeos::NetworkHandler::Get()->network_state_handler();
handler->AddObserver(this, FROM_HERE);
}
virtual ~NetworkStatus() {
chromeos::NetworkStateHandler* handler =
chromeos::NetworkHandler::Get()->network_state_handler();
handler->RemoveObserver(this, FROM_HERE);
}
private:
void Update() {
std::string status = "<unknown>";
chromeos::NetworkStateHandler* handler =
chromeos::NetworkHandler::Get()->network_state_handler();
const chromeos::NetworkState* network = handler->DefaultNetwork();
if (network) {
status = base::StringPrintf(
"%s (%s)", network->ip_address().c_str(), network->name().c_str());
}
label_->SetText(base::UTF8ToUTF16(status));
if (!closure_.is_null())
closure_.Run();
}
// chromeos::NetworkStateHandlerObserver:
virtual void DefaultNetworkChanged(
const chromeos::NetworkState* network) OVERRIDE {
Update();
}
virtual void NetworkConnectionStateChanged(
const chromeos::NetworkState* network) OVERRIDE {
Update();
}
virtual void NetworkPropertiesUpdated(
const chromeos::NetworkState* network) OVERRIDE {
Update();
}
views::Label* label_;
base::Closure closure_;
};
class DebugWidget {
public:
DebugWidget() : container_(NULL), widget_(NULL) {
CreateContainer();
CreateWidget();
CreateBatteryView();
CreateNetworkView();
UpdateSize();
}
virtual ~DebugWidget() {}
private:
void CreateContainer() {
container_ =
athena::ScreenManager::Get()->CreateContainer("DebugContainer");
}
void CreateWidget() {
views::Widget::InitParams params;
params.type = views::Widget::InitParams::TYPE_WINDOW_FRAMELESS;
params.opacity = views::Widget::InitParams::TRANSLUCENT_WINDOW;
params.activatable = views::Widget::InitParams::ACTIVATABLE_NO;
params.accept_events = false;
params.bounds = gfx::Rect(200, 0, 100, 105);
params.parent = container_;
widget_ = new views::Widget();
widget_->Init(params);
const int kHorizontalSpacing = 10;
const int kBorderVerticalSpacing = 3;
const int kBetweenChildSpacing = 10;
const int kBackgroundColor = SkColorSetARGB(0x7f, 0, 0, 0);
views::View* container = new views::View;
container->SetLayoutManager(
new views::BoxLayout(views::BoxLayout::kHorizontal,
kHorizontalSpacing,
kBorderVerticalSpacing,
kBetweenChildSpacing));
container->set_background(
views::Background::CreateSolidBackground(kBackgroundColor));
container->SetBorder(views::Border::CreateSolidBorder(1, kBackgroundColor));
widget_->SetContentsView(container);
widget_->StackAtTop();
widget_->Show();
widget_->SetBounds(gfx::Rect(600, 0, 300, 25));
}
void CreateBatteryView() {
views::View* container = widget_->GetContentsView();
container->AddChildView(CreateDebugLabel("Battery:"));
views::Label* label = CreateDebugLabel(std::string());
container->AddChildView(label);
container->Layout();
power_status_.reset(new PowerStatus(
label, base::Bind(&DebugWidget::UpdateSize, base::Unretained(this))));
}
void CreateNetworkView() {
views::View* container = widget_->GetContentsView();
container->AddChildView(CreateDebugLabel("Network:"));
views::Label* label = CreateDebugLabel(std::string());
container->AddChildView(label);
container->Layout();
network_status_.reset(new NetworkStatus(
label, base::Bind(&DebugWidget::UpdateSize, base::Unretained(this))));
}
const gfx::Rect GetPositionForSize(const gfx::Size& size) {
int right = container_->bounds().right();
int x = right - size.width();
return gfx::Rect(x, 0, size.width(), size.height());
}
void UpdateSize() {
views::View* container = widget_->GetContentsView();
container->Layout();
gfx::Size size = container->GetPreferredSize();
widget_->SetBounds(GetPositionForSize(size));
}
aura::Window* container_;
views::Widget* widget_;
scoped_ptr<PowerStatus> power_status_;
scoped_ptr<NetworkStatus> network_status_;
DISALLOW_COPY_AND_ASSIGN(DebugWidget);
};
} // namespace
void CreateDebugWindow() {
new DebugWidget();
}
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ATHENA_MAIN_DEBUG_DEBUG_WINDOW_H_
#define ATHENA_MAIN_DEBUG_DEBUG_WINDOW_H_
void CreateDebugWindow();
#endif // ATHENA_MAIN_DEBUG_DEBUG_WINDOW_H_
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