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

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

Issue 1951493002: Fix i18n number formats in tray power displays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Move time formatting into TimeDurationFormat() Created 4 years, 7 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
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/chromeos/power/power_status_view.h" 5 #include "ash/system/chromeos/power/power_status_view.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_delegate.h" 8 #include "ash/shell_delegate.h"
9 #include "ash/system/chromeos/power/power_status.h" 9 #include "ash/system/chromeos/power/power_status.h"
10 #include "ash/system/chromeos/power/tray_power.h" 10 #include "ash/system/chromeos/power/tray_power.h"
11 #include "ash/system/tray/fixed_sized_image_view.h" 11 #include "ash/system/tray/fixed_sized_image_view.h"
12 #include "ash/system/tray/tray_constants.h" 12 #include "ash/system/tray/tray_constants.h"
13 #include "base/strings/string_number_conversions.h" 13 #include "base/i18n/message_formatter.h"
14 #include "base/i18n/time_formatting.h"
14 #include "base/strings/utf_string_conversions.h" 15 #include "base/strings/utf_string_conversions.h"
15 #include "grit/ash_strings.h" 16 #include "grit/ash_strings.h"
16 #include "ui/base/l10n/l10n_util.h" 17 #include "ui/base/l10n/l10n_util.h"
17 #include "ui/base/l10n/time_format.h" 18 #include "ui/base/l10n/time_format.h"
jungshik at Google 2016/05/13 23:00:35 This header is not necessary in this file, is it?
Greg Levin 2016/05/16 17:12:56 Done.
18 #include "ui/base/resource/resource_bundle.h" 19 #include "ui/base/resource/resource_bundle.h"
19 #include "ui/views/controls/image_view.h" 20 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/label.h" 21 #include "ui/views/controls/label.h"
21 #include "ui/views/layout/box_layout.h" 22 #include "ui/views/layout/box_layout.h"
22 #include "ui/views/layout/grid_layout.h" 23 #include "ui/views/layout/grid_layout.h"
23 24
24 namespace ash { 25 namespace ash {
25 26
26 // Padding between battery status text and battery icon on default view. 27 // Padding between battery status text and battery icon on default view.
27 const int kPaddingBetweenBatteryStatusAndIcon = 3; 28 const int kPaddingBetweenBatteryStatusAndIcon = 3;
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 void PowerStatusView::UpdateText() { 84 void PowerStatusView::UpdateText() {
84 const PowerStatus& status = *PowerStatus::Get(); 85 const PowerStatus& status = *PowerStatus::Get();
85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); 86 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
86 base::string16 battery_percentage; 87 base::string16 battery_percentage;
87 base::string16 battery_time_status; 88 base::string16 battery_time_status;
88 89
89 if (status.IsBatteryFull()) { 90 if (status.IsBatteryFull()) {
90 battery_time_status = 91 battery_time_status =
91 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); 92 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL);
92 } else { 93 } else {
93 battery_percentage = l10n_util::GetStringFUTF16( 94 battery_percentage = base::i18n::MessageFormatter::FormatWithNumberedArgs(
94 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, 95 base::ASCIIToUTF16("{0,number,percent}"),
95 base::IntToString16(status.GetRoundedBatteryPercent())); 96 static_cast<double>(status.GetRoundedBatteryPercent()) / 100.0);
96 if (status.IsUsbChargerConnected()) { 97 if (status.IsUsbChargerConnected()) {
97 battery_time_status = rb.GetLocalizedString( 98 battery_time_status = rb.GetLocalizedString(
98 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); 99 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE);
99 } else if (status.IsBatteryTimeBeingCalculated()) { 100 } else if (status.IsBatteryTimeBeingCalculated()) {
100 battery_time_status = 101 battery_time_status =
101 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); 102 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING);
102 } else { 103 } else {
103 base::TimeDelta time = status.IsBatteryCharging() ? 104 base::TimeDelta time = status.IsBatteryCharging() ?
104 status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty(); 105 status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty();
105 if (PowerStatus::ShouldDisplayBatteryTime(time) && 106 if (PowerStatus::ShouldDisplayBatteryTime(time) &&
106 !status.IsBatteryDischargingOnLinePower()) { 107 !status.IsBatteryDischargingOnLinePower()) {
107 int hour = 0, min = 0; 108 battery_time_status = l10n_util::GetStringFUTF16(
108 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); 109 status.IsBatteryCharging()
109 base::string16 minute = min < 10 ? 110 ? IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_SHORT
110 base::ASCIIToUTF16("0") + base::IntToString16(min) : 111 : IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_SHORT,
111 base::IntToString16(min); 112 TimeDurationFormat(time, base::DURATION_WIDTH_NUMERIC));
112 battery_time_status =
113 l10n_util::GetStringFUTF16(
114 status.IsBatteryCharging() ?
115 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_SHORT :
116 IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_SHORT,
117 base::IntToString16(hour),
118 minute);
119 } 113 }
120 } 114 }
121 battery_percentage = battery_time_status.empty() ? 115 battery_percentage = battery_time_status.empty() ?
122 battery_percentage : battery_percentage + base::ASCIIToUTF16(" - "); 116 battery_percentage : battery_percentage + base::ASCIIToUTF16(" - ");
123 } 117 }
124 percentage_label_->SetVisible(!battery_percentage.empty()); 118 percentage_label_->SetVisible(!battery_percentage.empty());
125 percentage_label_->SetText(battery_percentage); 119 percentage_label_->SetText(battery_percentage);
126 time_status_label_->SetVisible(!battery_time_status.empty()); 120 time_status_label_->SetVisible(!battery_time_status.empty());
127 time_status_label_->SetText(battery_time_status); 121 time_status_label_->SetText(battery_time_status);
128 } 122 }
(...skipping 15 matching lines...) Expand all
144 views::View::Layout(); 138 views::View::Layout();
145 139
146 // Move the time_status_label_ closer to percentage_label_. 140 // Move the time_status_label_ closer to percentage_label_.
147 if (percentage_label_ && time_status_label_ && 141 if (percentage_label_ && time_status_label_ &&
148 percentage_label_->visible() && time_status_label_->visible()) { 142 percentage_label_->visible() && time_status_label_->visible()) {
149 time_status_label_->SetX(percentage_label_->bounds().right() + 1); 143 time_status_label_->SetX(percentage_label_->bounds().right() + 1);
150 } 144 }
151 } 145 }
152 146
153 } // namespace ash 147 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698