Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1442)

Unified Diff: ash/system/bluetooth/tray_bluetooth.cc

Issue 9753019: ash: Add a bluetooth entry in the uber tray. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comment Created 8 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ash/system/bluetooth/tray_bluetooth.cc
diff --git a/ash/system/bluetooth/tray_bluetooth.cc b/ash/system/bluetooth/tray_bluetooth.cc
new file mode 100644
index 0000000000000000000000000000000000000000..2f371e67b2c90e190fe45ba0c3dce5e46528bb3a
--- /dev/null
+++ b/ash/system/bluetooth/tray_bluetooth.cc
@@ -0,0 +1,209 @@
+// Copyright (c) 2012 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 "ash/system/bluetooth/tray_bluetooth.h"
+
+#include "ash/shell.h"
+#include "ash/system/tray/system_tray.h"
+#include "ash/system/tray/system_tray_delegate.h"
+#include "ash/system/tray/tray_constants.h"
+#include "ash/system/tray/tray_item_more.h"
+#include "ash/system/tray/tray_utils.h"
+#include "grit/ash_strings.h"
+#include "grit/ui_resources.h"
+#include "ui/base/resource/resource_bundle.h"
+#include "ui/gfx/image/image.h"
+#include "ui/views/controls/image_view.h"
+#include "ui/views/controls/label.h"
+#include "ui/views/layout/box_layout.h"
+
+namespace ash {
+namespace internal {
+
+namespace tray {
+
+class BluetoothDefaultView : public TrayItemMore {
+ public:
+ explicit BluetoothDefaultView(SystemTrayItem* owner)
+ : TrayItemMore(owner) {
+ SetLayoutManager(new views::BoxLayout(views::BoxLayout::kHorizontal,
+ kTrayPopupPaddingHorizontal, 0, kTrayPopupPaddingBetweenItems));
+ ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance();
+
+ views::ImageView* icon = new views::ImageView;
+ icon->SetImage(bundle.GetImageNamed(
+ IDR_AURA_UBER_TRAY_BLUETOOTH_LARGE).ToSkBitmap());
+ AddChildView(icon);
+
+ // TODO(sad): Use the correct label depending on the status.
+ label_ = new views::Label;
+ AddChildView(label_);
+ UpdateLabel();
+
+ AddMore();
+ }
+
+ virtual ~BluetoothDefaultView() {}
+
+ void UpdateLabel() {
+ ash::SystemTrayDelegate* delegate =
+ ash::Shell::GetInstance()->tray_delegate();
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ label_->SetText(rb.GetLocalizedString(delegate->GetBluetoothEnabled() ?
+ IDS_ASH_STATUS_TRAY_BLUETOOTH_CONNECTED :
+ IDS_ASH_STATUS_TRAY_BLUETOOTH_DISABLED));
+ }
+
+ private:
+ views::Label* label_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothDefaultView);
+};
+
+class BluetoothDetailedView : public views::View,
+ public ViewClickListener {
+ public:
+ BluetoothDetailedView()
+ : header_(NULL),
+ add_device_(NULL),
+ toggle_bluetooth_(NULL) {
+ SetLayoutManager(new views::BoxLayout(
+ views::BoxLayout::kVertical, 1, 1, 1));
+ set_background(views::Background::CreateSolidBackground(kBackgroundColor));
+ Update();
+ }
+
+ virtual ~BluetoothDetailedView() {}
+
+ void Update() {
+ RemoveAllChildViews(true);
+
+ header_ = NULL;
+ add_device_ = NULL;
+ toggle_bluetooth_ = NULL;
+
+ AppendHeaderEntry();
+ AppendDeviceList();
+ AppendSettingsEntries();
+
+ Layout();
+ }
+
+ private:
+ void AppendHeaderEntry() {
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ HoverHighlightView* container = new HoverHighlightView(this);
+ container->SetLayoutManager(new
+ views::BoxLayout(views::BoxLayout::kHorizontal, 0, 3, 5));
+ views::ImageView* back = new FixedWidthImageView;
+ back->SetImage(rb.GetImageNamed(IDR_AURA_UBER_TRAY_LESS).ToSkBitmap());
+ container->AddChildView(back);
+ views::Label* header = new views::Label(rb.GetLocalizedString(
+ IDS_ASH_STATUS_TRAY_BLUETOOTH));
+ header->SetHorizontalAlignment(views::Label::ALIGN_LEFT);
+ header->SetFont(header->font().DeriveFont(4));
+ container->AddChildView(header);
+ AddChildView(container);
+ header_ = container;
+ }
+
+ void AppendDeviceList() {
+ }
+
+ void AppendSettingsEntries() {
+ ash::SystemTrayDelegate* delegate =
+ ash::Shell::GetInstance()->tray_delegate();
+ HoverHighlightView* container = new HoverHighlightView(this);
+ ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
+ container->AddLabel(rb.GetLocalizedString(
+ delegate->GetBluetoothEnabled() ?
+ IDS_ASH_STATUS_TRAY_DISABLE_BLUETOOTH :
+ IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH));
+ AddChildView(container);
+ toggle_bluetooth_ = container;
+
+ container = new HoverHighlightView(this);
+ container->AddLabel(rb.GetLocalizedString(
+ IDS_ASH_STATUS_TRAY_BLUETOOTH_ADD_DEVICE));
+ AddChildView(container);
+ add_device_ = container;
+ }
+
+ // Overridden from ViewClickListener.
+ virtual void ClickedOn(views::View* sender) OVERRIDE {
+ ash::SystemTrayDelegate* delegate =
+ ash::Shell::GetInstance()->tray_delegate();
+ if (sender == header_) {
Ben Goodger (Google) 2012/03/21 15:52:14 nit no braces
+ Shell::GetInstance()->tray()->ShowDefaultView();
+ } else if (sender == toggle_bluetooth_) {
+ delegate->ToggleBluetooth();
+ } else if (sender == add_device_) {
+ delegate->AddBluetoothDevice();
+ } else {
Ben Goodger (Google) 2012/03/21 15:52:14 que?
sadrul 2012/03/21 16:16:42 Added a TODO here. This will be a block of code. S
+ }
+ }
+
+ views::View* header_;
+ views::View* add_device_;
+ views::View* toggle_bluetooth_;
+ views::View* settings_;
+
+ DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView);
+};
+
+} // namespace tray
+
+TrayBluetooth::TrayBluetooth()
+ : TrayImageItem(IDR_AURA_UBER_TRAY_BLUETOOTH_SMALL) {
+}
+
+TrayBluetooth::~TrayBluetooth() {
+}
+
+bool TrayBluetooth::InitialVisibility() {
+ // Hide at startup. If bluetooth is enabled, the tray-delegate will send a
+ // notification, and this will be made visible again.
+ return false;
+}
+
+views::View* TrayBluetooth::CreateDefaultView(user::LoginStatus status) {
+ if (!Shell::GetInstance()->tray_delegate()->GetBluetoothAvailable())
+ return NULL;
+ default_.reset(new tray::BluetoothDefaultView(this));
+ return default_.get();
+}
+
+views::View* TrayBluetooth::CreateDetailedView(user::LoginStatus status) {
+ if (!Shell::GetInstance()->tray_delegate()->GetBluetoothAvailable())
+ return NULL;
+ detailed_.reset(new tray::BluetoothDetailedView);
+ return detailed_.get();
+}
+
+void TrayBluetooth::DestroyDefaultView() {
+ default_.reset();
+}
+
+void TrayBluetooth::DestroyDetailedView() {
+ detailed_.reset();
+}
+
+void TrayBluetooth::OnBluetoothRefresh() {
+ BluetoothDeviceList list =
+ Shell::GetInstance()->tray_delegate()->GetAvailableBluetoothDevices();
+ for (size_t i = 0; i < list.size(); ++i) {
+ LOG(ERROR) << "Bluetooth device: \n"
+ << " address: " << list[i].address << "\n"
+ << " name: " << list[i].display_name << "\n"
+ << " connected: " << list[i].connected;
+ }
+ image_view()->SetVisible(list.size());
+ if (default_.get())
+ default_->UpdateLabel();
+ if (detailed_.get())
+ detailed_->Update();
+}
+
+} // namespace internal
+} // namespace ash

Powered by Google App Engine
This is Rietveld 408576698