OLD | NEW |
| (Empty) |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/system/chromeos/audio/audio_detailed_view.h" | |
6 | |
7 #include "ash/common/system/tray/fixed_sized_scroll_view.h" | |
8 #include "ash/common/system/tray/hover_highlight_view.h" | |
9 #include "ash/common/system/tray/tray_constants.h" | |
10 #include "base/strings/utf_string_conversions.h" | |
11 #include "chromeos/audio/cras_audio_handler.h" | |
12 #include "grit/ash_strings.h" | |
13 #include "ui/base/l10n/l10n_util.h" | |
14 #include "ui/base/resource/resource_bundle.h" | |
15 #include "ui/views/border.h" | |
16 #include "ui/views/controls/label.h" | |
17 | |
18 namespace { | |
19 | |
20 base::string16 GetAudioDeviceName(const chromeos::AudioDevice& device) { | |
21 switch (device.type) { | |
22 case chromeos::AUDIO_TYPE_HEADPHONE: | |
23 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_HEADPHONE); | |
24 case chromeos::AUDIO_TYPE_INTERNAL_SPEAKER: | |
25 return l10n_util::GetStringUTF16( | |
26 IDS_ASH_STATUS_TRAY_AUDIO_INTERNAL_SPEAKER); | |
27 case chromeos::AUDIO_TYPE_INTERNAL_MIC: | |
28 return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_INTERNAL_MIC); | |
29 case chromeos::AUDIO_TYPE_USB: | |
30 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_AUDIO_USB_DEVICE, | |
31 base::UTF8ToUTF16(device.display_name)); | |
32 case chromeos::AUDIO_TYPE_BLUETOOTH: | |
33 return l10n_util::GetStringFUTF16( | |
34 IDS_ASH_STATUS_TRAY_AUDIO_BLUETOOTH_DEVICE, | |
35 base::UTF8ToUTF16(device.display_name)); | |
36 case chromeos::AUDIO_TYPE_HDMI: | |
37 return l10n_util::GetStringFUTF16(IDS_ASH_STATUS_TRAY_AUDIO_HDMI_DEVICE, | |
38 base::UTF8ToUTF16(device.display_name)); | |
39 case chromeos::AUDIO_TYPE_MIC: | |
40 return l10n_util::GetStringUTF16( | |
41 IDS_ASH_STATUS_TRAY_AUDIO_MIC_JACK_DEVICE); | |
42 default: | |
43 return base::UTF8ToUTF16(device.display_name); | |
44 } | |
45 } | |
46 | |
47 } // namespace | |
48 | |
49 using chromeos::CrasAudioHandler; | |
50 | |
51 namespace ash { | |
52 namespace tray { | |
53 | |
54 AudioDetailedView::AudioDetailedView(SystemTrayItem* owner) | |
55 : TrayDetailsView(owner) { | |
56 CreateItems(); | |
57 Update(); | |
58 } | |
59 | |
60 AudioDetailedView::~AudioDetailedView() {} | |
61 | |
62 void AudioDetailedView::Update() { | |
63 UpdateAudioDevices(); | |
64 Layout(); | |
65 } | |
66 | |
67 void AudioDetailedView::AddScrollListInfoItem(const base::string16& text) { | |
68 views::Label* label = new views::Label( | |
69 text, ui::ResourceBundle::GetSharedInstance().GetFontList( | |
70 ui::ResourceBundle::BoldFont)); | |
71 | |
72 // Align info item with checkbox items | |
73 int margin = | |
74 kTrayPopupPaddingHorizontal + kTrayPopupDetailsLabelExtraLeftMargin; | |
75 int left_margin = 0; | |
76 int right_margin = 0; | |
77 if (base::i18n::IsRTL()) | |
78 right_margin = margin; | |
79 else | |
80 left_margin = margin; | |
81 | |
82 label->SetBorder(views::Border::CreateEmptyBorder( | |
83 ash::kTrayPopupPaddingBetweenItems, left_margin, | |
84 ash::kTrayPopupPaddingBetweenItems, right_margin)); | |
85 label->SetHorizontalAlignment(gfx::ALIGN_LEFT); | |
86 label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0)); | |
87 | |
88 scroll_content()->AddChildView(label); | |
89 } | |
90 | |
91 HoverHighlightView* AudioDetailedView::AddScrollListItem( | |
92 const base::string16& text, | |
93 bool highlight, | |
94 bool checked) { | |
95 HoverHighlightView* container = new HoverHighlightView(this); | |
96 container->AddCheckableLabel(text, highlight, checked); | |
97 scroll_content()->AddChildView(container); | |
98 return container; | |
99 } | |
100 | |
101 void AudioDetailedView::CreateHeaderEntry() { | |
102 CreateSpecialRow(IDS_ASH_STATUS_TRAY_AUDIO, this); | |
103 } | |
104 | |
105 void AudioDetailedView::CreateItems() { | |
106 CreateScrollableList(); | |
107 CreateHeaderEntry(); | |
108 } | |
109 | |
110 void AudioDetailedView::UpdateAudioDevices() { | |
111 output_devices_.clear(); | |
112 input_devices_.clear(); | |
113 chromeos::AudioDeviceList devices; | |
114 CrasAudioHandler::Get()->GetAudioDevices(&devices); | |
115 for (size_t i = 0; i < devices.size(); ++i) { | |
116 // Don't display keyboard mic or aokr type. | |
117 if (!devices[i].is_for_simple_usage()) | |
118 continue; | |
119 if (devices[i].is_input) | |
120 input_devices_.push_back(devices[i]); | |
121 else | |
122 output_devices_.push_back(devices[i]); | |
123 } | |
124 UpdateScrollableList(); | |
125 } | |
126 | |
127 void AudioDetailedView::UpdateScrollableList() { | |
128 scroll_content()->RemoveAllChildViews(true); | |
129 device_map_.clear(); | |
130 | |
131 // Add audio output devices. | |
132 AddScrollListInfoItem( | |
133 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_OUTPUT)); | |
134 for (size_t i = 0; i < output_devices_.size(); ++i) { | |
135 HoverHighlightView* container = AddScrollListItem( | |
136 GetAudioDeviceName(output_devices_[i]), false /* highlight */, | |
137 output_devices_[i].active); /* checkmark if active */ | |
138 device_map_[container] = output_devices_[i]; | |
139 } | |
140 | |
141 AddScrollSeparator(); | |
142 | |
143 // Add audio input devices. | |
144 AddScrollListInfoItem( | |
145 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_AUDIO_INPUT)); | |
146 for (size_t i = 0; i < input_devices_.size(); ++i) { | |
147 HoverHighlightView* container = AddScrollListItem( | |
148 GetAudioDeviceName(input_devices_[i]), false /* highlight */, | |
149 input_devices_[i].active); /* checkmark if active */ | |
150 device_map_[container] = input_devices_[i]; | |
151 } | |
152 | |
153 scroll_content()->SizeToPreferredSize(); | |
154 scroller()->Layout(); | |
155 } | |
156 | |
157 void AudioDetailedView::OnViewClicked(views::View* sender) { | |
158 if (sender == footer()->content()) { | |
159 TransitionToDefaultView(); | |
160 } else { | |
161 AudioDeviceMap::iterator iter = device_map_.find(sender); | |
162 if (iter == device_map_.end()) | |
163 return; | |
164 chromeos::AudioDevice device = iter->second; | |
165 CrasAudioHandler::Get()->SwitchToDevice(device, true, | |
166 CrasAudioHandler::ACTIVATE_BY_USER); | |
167 } | |
168 } | |
169 | |
170 } // namespace tray | |
171 } // namespace ash | |
OLD | NEW |