summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorsadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-24 04:23:44 +0000
committersadrul@chromium.org <sadrul@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2014-06-24 04:23:44 +0000
commit7128d46156bfdea972539c6edf139f09eee6c364 (patch)
treee34a71f4022a77816a9642e89a1ad3a9833c54d3
parentb58fa31263e518d394ddae7659802ad24612ca1e (diff)
downloadchromium-7128d46156bfdea972539c6edf139f09eee6c364.tar.gz
chromium-7128d46156bfdea972539c6edf139f09eee6c364.tar.bz2
chromium-7128d46156bfdea972539c6edf139f09eee6c364.zip
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
-rw-r--r--athena/main/athena_main.cc2
-rw-r--r--athena/main/athena_main.gyp3
-rw-r--r--athena/main/debug/DEPS5
-rw-r--r--athena/main/debug/debug_window.cc221
-rw-r--r--athena/main/debug/debug_window.h10
5 files changed, 241 insertions, 0 deletions
diff --git a/athena/main/athena_main.cc b/athena/main/athena_main.cc
index 6968187f67b8..fea0fed02f4f 100644
--- a/athena/main/athena_main.cc
+++ b/athena/main/athena_main.cc
@@ -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(); }
diff --git a/athena/main/athena_main.gyp b/athena/main/athena_main.gyp
index 0b0e718a5d55..8d3e83b420fe 100644
--- a/athena/main/athena_main.gyp
+++ b/athena/main/athena_main.gyp
@@ -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',
diff --git a/athena/main/debug/DEPS b/athena/main/debug/DEPS
new file mode 100644
index 000000000000..10e4584b466a
--- /dev/null
+++ b/athena/main/debug/DEPS
@@ -0,0 +1,5 @@
+include_rules = [
+ "+chromeos",
+ "+ui/aura",
+ "+ui/views",
+]
diff --git a/athena/main/debug/debug_window.cc b/athena/main/debug/debug_window.cc
new file mode 100644
index 000000000000..3c9225a118ff
--- /dev/null
+++ b/athena/main/debug/debug_window.cc
@@ -0,0 +1,221 @@
+// 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();
+}
diff --git a/athena/main/debug/debug_window.h b/athena/main/debug/debug_window.h
new file mode 100644
index 000000000000..68c17ce2b1a9
--- /dev/null
+++ b/athena/main/debug/debug_window.h
@@ -0,0 +1,10 @@
+// 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_