Commit b448570b authored by jennyz@chromium.org's avatar jennyz@chromium.org

M26 new bluetooth UI. List all bluetooth devices in detailed view and...

M26 new bluetooth UI. List all bluetooth devices in detailed view and automatically discover all BT devices when BT detailed view bubble opens.

BUG=130698

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

git-svn-id: svn://svn.chromium.org/chrome/trunk/src@175403 0039d316-1c4b-4281-b951-d872f2087c98
parent 8d320036
...@@ -71,39 +71,64 @@ class BluetoothDetailedView : public TrayDetailsView, ...@@ -71,39 +71,64 @@ class BluetoothDetailedView : public TrayDetailsView,
login_(login), login_(login),
add_device_(NULL), add_device_(NULL),
toggle_bluetooth_(NULL), toggle_bluetooth_(NULL),
enable_bluetooth_(NULL) { enable_bluetooth_(NULL),
bluetooth_discovering_(false) {
CreateItems();
Update(); Update();
} }
virtual ~BluetoothDetailedView() {} virtual ~BluetoothDetailedView() {
// Stop discovering bluetooth devices when exiting BT detailed view.
BluetoothSetDiscovering(false);
}
void Update() { void Update() {
BluetoothSetDiscovering(true);
UpdateBlueToothDeviceList(); UpdateBlueToothDeviceList();
Reset(); // Update UI.
UpdateDeviceScrollList();
add_device_ = NULL; UpdateHeaderEntry();
toggle_bluetooth_ = NULL; Layout();
}
AppendDeviceList(); private:
void CreateItems() {
CreateScrollableList();
AppendSettingsEntries(); AppendSettingsEntries();
AppendHeaderEntry(); AppendHeaderEntry();
}
Layout(); void BluetoothSetDiscovering(bool discovering) {
ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->system_tray_delegate();
if (discovering) {
bool bluetooth_enabled = delegate->GetBluetoothEnabled();
if (!bluetooth_discovering_ && bluetooth_enabled)
delegate->BluetoothSetDiscovering(true);
bluetooth_discovering_ = bluetooth_enabled;
} else { // Stop bluetooth discovering.
if (bluetooth_discovering_) {
bluetooth_discovering_ = false;
delegate->BluetoothSetDiscovering(false);
}
}
} }
private:
void UpdateBlueToothDeviceList() { void UpdateBlueToothDeviceList() {
connected_devices_.clear(); connected_devices_.clear();
paired_not_connected_devices_.clear(); paired_not_connected_devices_.clear();
discovered_not_paired_devices_.clear();
BluetoothDeviceList list; BluetoothDeviceList list;
Shell::GetInstance()->system_tray_delegate()-> Shell::GetInstance()->system_tray_delegate()->
GetAvailableBluetoothDevices(&list); GetAvailableBluetoothDevices(&list);
for (size_t i = 0; i < list.size(); ++i) { for (size_t i = 0; i < list.size(); ++i) {
if (list[i].connected) if (list[i].connected)
connected_devices_.push_back(list[i]); connected_devices_.push_back(list[i]);
else else if (list[i].paired)
paired_not_connected_devices_.push_back(list[i]); paired_not_connected_devices_.push_back(list[i]);
else if (list[i].visible)
discovered_not_paired_devices_.push_back(list[i]);
} }
} }
...@@ -128,16 +153,27 @@ class BluetoothDetailedView : public TrayDetailsView, ...@@ -128,16 +153,27 @@ class BluetoothDetailedView : public TrayDetailsView,
toggle_bluetooth_->SetToggledTooltipText( toggle_bluetooth_->SetToggledTooltipText(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH)); l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH));
footer()->AddButton(toggle_bluetooth_); footer()->AddButton(toggle_bluetooth_);
}
void UpdateHeaderEntry() {
if (toggle_bluetooth_) {
toggle_bluetooth_->SetToggled(
!ash::Shell::GetInstance()->system_tray_delegate()->
GetBluetoothEnabled());
}
} }
void AppendDeviceList() { void UpdateDeviceScrollList() {
device_map_.clear(); device_map_.clear();
CreateScrollableList(); scroll_content()->RemoveAllChildViews(true);
enable_bluetooth_ = NULL;
ash::SystemTrayDelegate* delegate = ash::SystemTrayDelegate* delegate =
ash::Shell::GetInstance()->system_tray_delegate(); ash::Shell::GetInstance()->system_tray_delegate();
bool bluetooth_enabled = delegate->GetBluetoothEnabled(); bool bluetooth_enabled = delegate->GetBluetoothEnabled();
if (delegate->GetBluetoothAvailable() && !bluetooth_enabled) { bool blueooth_available = delegate->GetBluetoothAvailable();
if (blueooth_available && !bluetooth_enabled &&
toggle_bluetooth_) {
enable_bluetooth_ = enable_bluetooth_ =
AddScrollListItem( AddScrollListItem(
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH), l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_ENABLE_BLUETOOTH),
...@@ -148,23 +184,23 @@ class BluetoothDetailedView : public TrayDetailsView, ...@@ -148,23 +184,23 @@ class BluetoothDetailedView : public TrayDetailsView,
connected_devices_, true, true, bluetooth_enabled); connected_devices_, true, true, bluetooth_enabled);
AppendSameTypeDevicesToScrollList( AppendSameTypeDevicesToScrollList(
paired_not_connected_devices_, false, false, bluetooth_enabled); paired_not_connected_devices_, false, false, bluetooth_enabled);
if (discovered_not_paired_devices_.size() > 0)
AddScrollSeparator();
AppendSameTypeDevicesToScrollList(
discovered_not_paired_devices_, false, false, bluetooth_enabled);
// Show user Bluetooth state if there is no bluetooth devices in list. // Show user Bluetooth state if there is no bluetooth devices in list.
if (connected_devices_.size() == 0 && if (device_map_.size() == 0) {
paired_not_connected_devices_.size() == 0) { if (blueooth_available && bluetooth_enabled) {
ash::SystemTrayDelegate* delegate = AddScrollListItem(
ash::Shell::GetInstance()->system_tray_delegate(); l10n_util::GetStringUTF16(
int message_id; IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING),
if (delegate->GetBluetoothAvailable() && gfx::Font::NORMAL, false, true);
delegate->GetBluetoothEnabled()) {
if (delegate->IsBluetoothDiscovering())
message_id = IDS_ASH_STATUS_TRAY_BLUETOOTH_DISCOVERING;
else
message_id = IDS_ASH_STATUS_TRAY_BLUETOOTH_NO_DEVICE;
AddScrollListItem(l10n_util::GetStringUTF16(message_id),
gfx::Font::NORMAL, false, true);
} }
} }
scroll_content()->SizeToPreferredSize();
static_cast<views::View*>(scroller())->Layout();
} }
void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list, void AppendSameTypeDevicesToScrollList(const BluetoothDeviceList& list,
...@@ -224,7 +260,7 @@ class BluetoothDetailedView : public TrayDetailsView, ...@@ -224,7 +260,7 @@ class BluetoothDetailedView : public TrayDetailsView,
delegate->ToggleBluetooth(); delegate->ToggleBluetooth();
delegate->AddBluetoothDevice(); delegate->AddBluetoothDevice();
} else if (sender == enable_bluetooth_) { } else if (sender == enable_bluetooth_) {
delegate->ToggleBluetooth(); delegate->ToggleBluetooth();
} else { } else {
std::map<views::View*, std::string>::iterator find; std::map<views::View*, std::string>::iterator find;
find = device_map_.find(sender); find = device_map_.find(sender);
...@@ -254,6 +290,8 @@ class BluetoothDetailedView : public TrayDetailsView, ...@@ -254,6 +290,8 @@ class BluetoothDetailedView : public TrayDetailsView,
HoverHighlightView* enable_bluetooth_; HoverHighlightView* enable_bluetooth_;
BluetoothDeviceList connected_devices_; BluetoothDeviceList connected_devices_;
BluetoothDeviceList paired_not_connected_devices_; BluetoothDeviceList paired_not_connected_devices_;
BluetoothDeviceList discovered_not_paired_devices_;
bool bluetooth_discovering_;
DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView); DISALLOW_COPY_AND_ASSIGN(BluetoothDetailedView);
}; };
......
...@@ -40,6 +40,8 @@ struct ASH_EXPORT BluetoothDeviceInfo { ...@@ -40,6 +40,8 @@ struct ASH_EXPORT BluetoothDeviceInfo {
std::string address; std::string address;
string16 display_name; string16 display_name;
bool connected; bool connected;
bool paired;
bool visible;
}; };
typedef std::vector<BluetoothDeviceInfo> BluetoothDeviceList; typedef std::vector<BluetoothDeviceInfo> BluetoothDeviceList;
...@@ -184,6 +186,9 @@ class SystemTrayDelegate { ...@@ -184,6 +186,9 @@ class SystemTrayDelegate {
// Returns a list of available bluetooth devices. // Returns a list of available bluetooth devices.
virtual void GetAvailableBluetoothDevices(BluetoothDeviceList* devices) = 0; virtual void GetAvailableBluetoothDevices(BluetoothDeviceList* devices) = 0;
// Requests bluetooth start or stop discovering devices.
virtual void BluetoothSetDiscovering(bool value) = 0;
// Toggles connection to a specific bluetooth device. // Toggles connection to a specific bluetooth device.
virtual void ToggleBluetoothConnection(const std::string& address) = 0; virtual void ToggleBluetoothConnection(const std::string& address) = 0;
......
...@@ -168,6 +168,9 @@ void TestSystemTrayDelegate::GetAvailableBluetoothDevices( ...@@ -168,6 +168,9 @@ void TestSystemTrayDelegate::GetAvailableBluetoothDevices(
BluetoothDeviceList* list) { BluetoothDeviceList* list) {
} }
void TestSystemTrayDelegate::BluetoothSetDiscovering(bool value) {
}
void TestSystemTrayDelegate::ToggleBluetoothConnection( void TestSystemTrayDelegate::ToggleBluetoothConnection(
const std::string& address) { const std::string& address) {
} }
......
...@@ -51,6 +51,7 @@ class TestSystemTrayDelegate : public SystemTrayDelegate { ...@@ -51,6 +51,7 @@ class TestSystemTrayDelegate : public SystemTrayDelegate {
virtual void RequestLockScreen() OVERRIDE; virtual void RequestLockScreen() OVERRIDE;
virtual void RequestRestart() OVERRIDE; virtual void RequestRestart() OVERRIDE;
virtual void GetAvailableBluetoothDevices(BluetoothDeviceList* list) OVERRIDE; virtual void GetAvailableBluetoothDevices(BluetoothDeviceList* list) OVERRIDE;
virtual void BluetoothSetDiscovering(bool value) OVERRIDE;
virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE; virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE;
virtual void GetCurrentIME(IMEInfo* info) OVERRIDE; virtual void GetCurrentIME(IMEInfo* info) OVERRIDE;
virtual void GetAvailableIMEList(IMEInfoList* list) OVERRIDE; virtual void GetAvailableIMEList(IMEInfoList* list) OVERRIDE;
......
...@@ -32,6 +32,7 @@ const int kTrayPopupTextSpacingVertical = 4; ...@@ -32,6 +32,7 @@ const int kTrayPopupTextSpacingVertical = 4;
const int kTrayPopupItemHeight = 48; const int kTrayPopupItemHeight = 48;
const int kTrayPopupDetailsIconWidth = 25; const int kTrayPopupDetailsIconWidth = 25;
const int kTrayPopupScrollSeparatorHeight = 15;
const int kTrayRoundedBorderRadius = 2; const int kTrayRoundedBorderRadius = 2;
const int kTrayBarButtonWidth = 39; const int kTrayBarButtonWidth = 39;
......
...@@ -33,6 +33,7 @@ extern const int kTrayPopupTextSpacingVertical; ...@@ -33,6 +33,7 @@ extern const int kTrayPopupTextSpacingVertical;
extern const int kTrayPopupItemHeight; extern const int kTrayPopupItemHeight;
extern const int kTrayPopupDetailsIconWidth; extern const int kTrayPopupDetailsIconWidth;
extern const int kTrayPopupScrollSeparatorHeight;
extern const int kTrayRoundedBorderRadius; extern const int kTrayRoundedBorderRadius;
extern const int kTrayBarButtonWidth; extern const int kTrayBarButtonWidth;
......
...@@ -15,6 +15,24 @@ ...@@ -15,6 +15,24 @@
namespace ash { namespace ash {
namespace internal { namespace internal {
class ScrollSeparator : public views::View {
public:
ScrollSeparator() {}
virtual ~ScrollSeparator() {}
private:
// Overriden from views::View.
virtual void OnPaint(gfx::Canvas* canvas) OVERRIDE {
canvas->FillRect(gfx::Rect(0, height() / 2, width(), 1), kBorderLightColor);
}
virtual gfx::Size GetPreferredSize() OVERRIDE {
return gfx::Size(1, kTrayPopupScrollSeparatorHeight);
}
DISALLOW_COPY_AND_ASSIGN(ScrollSeparator);
};
class ScrollBorder : public views::Border { class ScrollBorder : public views::Border {
public: public:
ScrollBorder() {} ScrollBorder() {}
...@@ -77,6 +95,14 @@ void TrayDetailsView::CreateScrollableList() { ...@@ -77,6 +95,14 @@ void TrayDetailsView::CreateScrollableList() {
AddChildView(scroller_); AddChildView(scroller_);
} }
void TrayDetailsView::AddScrollSeparator() {
DCHECK(scroll_content_);
// Do not draw the separator if it is the very first item
// in the scrollable list.
if (scroll_content_->has_children())
scroll_content_->AddChildView(new ScrollSeparator);
}
void TrayDetailsView::Reset() { void TrayDetailsView::Reset() {
RemoveAllChildViews(true); RemoveAllChildViews(true);
footer_ = NULL; footer_ = NULL;
......
...@@ -35,6 +35,9 @@ class TrayDetailsView : public views::View { ...@@ -35,6 +35,9 @@ class TrayDetailsView : public views::View {
// any other view between the list and the footer row at the bottom. // any other view between the list and the footer row at the bottom.
void CreateScrollableList(); void CreateScrollableList();
// Adds a separator in scrollable list.
void AddScrollSeparator();
// Removes (and destroys) all child views. // Removes (and destroys) all child views.
void Reset(); void Reset();
......
...@@ -244,7 +244,9 @@ views::Label* HoverHighlightView::AddLabel(const string16& text, ...@@ -244,7 +244,9 @@ views::Label* HoverHighlightView::AddLabel(const string16& text,
views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin)); views::Border::CreateEmptyBorder(5, left_margin, 5, right_margin));
text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT); text_label_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
text_label_->SetFont(text_label_->font().DeriveFont(0, style)); text_label_->SetFont(text_label_->font().DeriveFont(0, style));
text_label_->SetDisabledColor(SkColorSetARGB(127, 0, 0, 0)); // Do not set alpha value in disable color. It will have issue with elide
// blending filter in disabled state for rendering label text color.
text_label_->SetDisabledColor(SkColorSetARGB(255, 127, 127, 127));
if (text_default_color_) if (text_default_color_)
text_label_->SetEnabledColor(text_default_color_); text_label_->SetEnabledColor(text_default_color_);
AddChildView(text_label_); AddChildView(text_label_);
......
...@@ -175,6 +175,10 @@ void BluetoothDeviceDisconnectError() { ...@@ -175,6 +175,10 @@ void BluetoothDeviceDisconnectError() {
// TODO(sad): Do something? // TODO(sad): Do something?
} }
void BluetoothSetDiscoveringError() {
LOG(ERROR) << "BluetoothSetDiscovering failed.";
}
void BluetoothDeviceConnectError( void BluetoothDeviceConnectError(
device::BluetoothDevice::ConnectErrorCode error_code) { device::BluetoothDevice::ConnectErrorCode error_code) {
// TODO(sad): Do something? // TODO(sad): Do something?
...@@ -477,16 +481,22 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate, ...@@ -477,16 +481,22 @@ class SystemTrayDelegate : public ash::SystemTrayDelegate,
bluetooth_adapter_->GetDevices(); bluetooth_adapter_->GetDevices();
for (size_t i = 0; i < devices.size(); ++i) { for (size_t i = 0; i < devices.size(); ++i) {
device::BluetoothDevice* device = devices[i]; device::BluetoothDevice* device = devices[i];
if (!device->IsPaired())
continue;
ash::BluetoothDeviceInfo info; ash::BluetoothDeviceInfo info;
info.address = device->address(); info.address = device->address();
info.display_name = device->GetName(); info.display_name = device->GetName();
info.connected = device->IsConnected(); info.connected = device->IsConnected();
info.paired = device->IsPaired();
info.visible = device->IsVisible();
list->push_back(info); list->push_back(info);
} }
} }
virtual void BluetoothSetDiscovering(bool value) OVERRIDE {
bluetooth_adapter_->SetDiscovering(value,
base::Bind(&base::DoNothing),
base::Bind(&BluetoothSetDiscoveringError));
}
virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE { virtual void ToggleBluetoothConnection(const std::string& address) OVERRIDE {
device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address); device::BluetoothDevice* device = bluetooth_adapter_->GetDevice(address);
if (!device) if (!device)
......
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