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

Side by Side Diff: ash/system/power/power_status_view.cc

Issue 10830292: Change the battery time display format according m23 spec. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 4 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ash/ash_strings.grd ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ash/system/power/power_status_view.h" 5 #include "ash/system/power/power_status_view.h"
6 6
7 #include "ash/system/power/tray_power.h" 7 #include "ash/system/power/tray_power.h"
8 #include "ash/system/tray/tray_constants.h" 8 #include "ash/system/tray/tray_constants.h"
9 #include "base/string_number_conversions.h" 9 #include "base/string_number_conversions.h"
10 #include "base/utf_string_conversions.h" 10 #include "base/utf_string_conversions.h"
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
107 string16 battery_percentage = l10n_util::GetStringFUTF16( 107 string16 battery_percentage = l10n_util::GetStringFUTF16(
108 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, 108 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY,
109 base::IntToString16( 109 base::IntToString16(
110 static_cast<int>(supply_status_.battery_percentage))); 110 static_cast<int>(supply_status_.battery_percentage)));
111 string16 battery_time = string16(); 111 string16 battery_time = string16();
112 if (supply_status_.is_calculating_battery_time) { 112 if (supply_status_.is_calculating_battery_time) {
113 battery_time = 113 battery_time =
114 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 114 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
115 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); 115 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING);
116 } else if (hour || min){ 116 } else if (hour || min){
117 string16 minute = min < 10 ?
118 ASCIIToUTF16("0") + base::IntToString16(min) :
119 base::IntToString16(min);
117 battery_time = 120 battery_time =
118 l10n_util::GetStringFUTF16( 121 l10n_util::GetStringFUTF16(
119 IDS_ASH_STATUS_TRAY_BATTERY_TIME_ONLY, 122 IDS_ASH_STATUS_TRAY_BATTERY_TIME_ONLY,
120 base::IntToString16(hour), 123 base::IntToString16(hour),
121 base::IntToString16(min)) + 124 minute);
122 ASCIIToUTF16(" - ");
123 } 125 }
124 string16 battery_status = battery_time + battery_percentage; 126 string16 battery_status = battery_time.empty() ?
127 battery_percentage :
128 battery_percentage + ASCIIToUTF16(" - ") + battery_time;
125 time_status_label_->SetText(battery_status); 129 time_status_label_->SetText(battery_status);
126 } 130 }
127 } 131 }
128 132
129 void PowerStatusView::UpdateTextForNotificationView() { 133 void PowerStatusView::UpdateTextForNotificationView() {
130 int hour = 0; 134 int hour = 0;
131 int min = 0; 135 int min = 0;
132 if (!supply_status_.is_calculating_battery_time) { 136 if (!supply_status_.is_calculating_battery_time) {
133 base::TimeDelta time = base::TimeDelta::FromSeconds( 137 base::TimeDelta time = base::TimeDelta::FromSeconds(
134 supply_status_.line_power_on ? 138 supply_status_.line_power_on ?
(...skipping 13 matching lines...) Expand all
148 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, 152 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT,
149 base::IntToString16( 153 base::IntToString16(
150 static_cast<int>(supply_status_.battery_percentage)))); 154 static_cast<int>(supply_status_.battery_percentage))));
151 } 155 }
152 156
153 if (supply_status_.is_calculating_battery_time) { 157 if (supply_status_.is_calculating_battery_time) {
154 time_label_->SetText( 158 time_label_->SetText(
155 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( 159 ui::ResourceBundle::GetSharedInstance().GetLocalizedString(
156 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING)); 160 IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING));
157 } else if (hour || min) { 161 } else if (hour || min) {
158 time_label_->SetText( 162 if (supply_status_.line_power_on) {
163 time_label_->SetText(
159 l10n_util::GetStringFUTF16( 164 l10n_util::GetStringFUTF16(
160 supply_status_.line_power_on ? 165 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL,
161 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL :
162 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_EMPTY,
163 base::IntToString16(hour), 166 base::IntToString16(hour),
164 base::IntToString16(min))); 167 base::IntToString16(min)));
168 } else {
169 // This is a low battery warning, which prompts user when battery
170 // time left is not much (ie in minutes).
171 min = hour * 60 + min;
172 time_label_->SetText(
173 l10n_util::GetStringFUTF16(
174 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_EMPTY,
175 base::IntToString16(min)));
176 }
165 } else { 177 } else {
166 time_label_->SetText(string16()); 178 time_label_->SetText(string16());
167 } 179 }
168 180
169 } 181 }
170 182
171 void PowerStatusView::UpdateIcon() { 183 void PowerStatusView::UpdateIcon() {
172 if (icon_) { 184 if (icon_) {
173 icon_->SetImage(TrayPower::GetBatteryImage(supply_status_, ICON_DARK)); 185 icon_->SetImage(TrayPower::GetBatteryImage(supply_status_, ICON_DARK));
174 icon_->SetVisible(true); 186 icon_->SetVisible(true);
175 } 187 }
176 } 188 }
177 189
178 void PowerStatusView::Update() { 190 void PowerStatusView::Update() {
179 UpdateText(); 191 UpdateText();
180 UpdateIcon(); 192 UpdateIcon();
181 } 193 }
182 194
183 void PowerStatusView::ChildPreferredSizeChanged(views::View* child) { 195 void PowerStatusView::ChildPreferredSizeChanged(views::View* child) {
184 PreferredSizeChanged(); 196 PreferredSizeChanged();
185 } 197 }
186 198
187 gfx::Size PowerStatusView::GetPreferredSize() { 199 gfx::Size PowerStatusView::GetPreferredSize() {
188 gfx::Size size = views::View::GetPreferredSize(); 200 gfx::Size size = views::View::GetPreferredSize();
189 return gfx::Size(size.width(), kTrayPopupItemHeight); 201 return gfx::Size(size.width(), kTrayPopupItemHeight);
190 } 202 }
191 203
192 } // namespace internal 204 } // namespace internal
193 } // namespace ash 205 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash_strings.grd ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698