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

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: Switch unit test from Bengali to Persian for Android (and merge) 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
« no previous file with comments | « ash/system/chromeos/power/battery_notification.cc ('k') | base/i18n/time_formatting.h » ('j') | 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/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/resource/resource_bundle.h"
19 #include "ui/views/controls/image_view.h" 18 #include "ui/views/controls/image_view.h"
20 #include "ui/views/controls/label.h" 19 #include "ui/views/controls/label.h"
21 #include "ui/views/layout/box_layout.h" 20 #include "ui/views/layout/box_layout.h"
22 #include "ui/views/layout/grid_layout.h" 21 #include "ui/views/layout/grid_layout.h"
23 22
24 namespace ash { 23 namespace ash {
25 24
26 // Padding between battery status text and battery icon on default view. 25 // Padding between battery status text and battery icon on default view.
27 const int kPaddingBetweenBatteryStatusAndIcon = 3; 26 const int kPaddingBetweenBatteryStatusAndIcon = 3;
28 27
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 AddChildView(icon_); 79 AddChildView(icon_);
81 80
82 AddChildView(percentage_label_); 81 AddChildView(percentage_label_);
83 AddChildView(separator_label_); 82 AddChildView(separator_label_);
84 AddChildView(time_status_label_); 83 AddChildView(time_status_label_);
85 } 84 }
86 } 85 }
87 86
88 void PowerStatusView::UpdateText() { 87 void PowerStatusView::UpdateText() {
89 const PowerStatus& status = *PowerStatus::Get(); 88 const PowerStatus& status = *PowerStatus::Get();
90 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance();
91 base::string16 battery_percentage; 89 base::string16 battery_percentage;
92 base::string16 battery_time_status; 90 base::string16 battery_time_status;
93 91
94 if (status.IsBatteryFull()) { 92 if (status.IsBatteryFull()) {
95 battery_time_status = 93 battery_time_status =
96 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); 94 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_FULL);
97 } else { 95 } else {
98 battery_percentage = l10n_util::GetStringFUTF16( 96 battery_percentage = base::i18n::MessageFormatter::FormatWithNumberedArgs(
99 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, 97 base::ASCIIToUTF16("{0,number,percent}"),
100 base::IntToString16(status.GetRoundedBatteryPercent())); 98 static_cast<double>(status.GetRoundedBatteryPercent()) / 100.0);
101 if (status.IsUsbChargerConnected()) { 99 if (status.IsUsbChargerConnected()) {
102 battery_time_status = rb.GetLocalizedString( 100 battery_time_status = l10n_util::GetStringUTF16(
103 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); 101 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE);
104 } else if (status.IsBatteryTimeBeingCalculated()) { 102 } else if (status.IsBatteryTimeBeingCalculated()) {
105 battery_time_status = 103 battery_time_status =
106 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); 104 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING);
107 } else { 105 } else {
108 base::TimeDelta time = status.IsBatteryCharging() ? 106 base::TimeDelta time = status.IsBatteryCharging() ?
109 status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty(); 107 status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty();
110 if (PowerStatus::ShouldDisplayBatteryTime(time) && 108 if (PowerStatus::ShouldDisplayBatteryTime(time) &&
111 !status.IsBatteryDischargingOnLinePower()) { 109 !status.IsBatteryDischargingOnLinePower()) {
112 int hour = 0, min = 0; 110 battery_time_status = l10n_util::GetStringFUTF16(
113 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); 111 status.IsBatteryCharging()
114 base::string16 minute = min < 10 ? 112 ? IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_SHORT
115 base::ASCIIToUTF16("0") + base::IntToString16(min) : 113 : IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_SHORT,
116 base::IntToString16(min); 114 TimeDurationFormat(time, base::DURATION_WIDTH_NUMERIC));
117 battery_time_status =
118 l10n_util::GetStringFUTF16(
119 status.IsBatteryCharging() ?
120 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_SHORT :
121 IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_SHORT,
122 base::IntToString16(hour),
123 minute);
124 } 115 }
125 } 116 }
126 } 117 }
127 percentage_label_->SetVisible(!battery_percentage.empty()); 118 percentage_label_->SetVisible(!battery_percentage.empty());
128 percentage_label_->SetText(battery_percentage); 119 percentage_label_->SetText(battery_percentage);
129 separator_label_->SetVisible(!battery_percentage.empty() && 120 separator_label_->SetVisible(!battery_percentage.empty() &&
130 !battery_time_status.empty()); 121 !battery_time_status.empty());
131 time_status_label_->SetVisible(!battery_time_status.empty()); 122 time_status_label_->SetVisible(!battery_time_status.empty());
132 time_status_label_->SetText(battery_time_status); 123 time_status_label_->SetText(battery_time_status);
133 } 124 }
(...skipping 17 matching lines...) Expand all
151 // Move the time_status_label_, separator_label_, and percentage_label_ 142 // Move the time_status_label_, separator_label_, and percentage_label_
152 // closer to each other. 143 // closer to each other.
153 if (percentage_label_ && separator_label_ && time_status_label_ && 144 if (percentage_label_ && separator_label_ && time_status_label_ &&
154 percentage_label_->visible() && time_status_label_->visible()) { 145 percentage_label_->visible() && time_status_label_->visible()) {
155 separator_label_->SetX(percentage_label_->bounds().right() + 1); 146 separator_label_->SetX(percentage_label_->bounds().right() + 1);
156 time_status_label_->SetX(separator_label_->bounds().right() + 1); 147 time_status_label_->SetX(separator_label_->bounds().right() + 1);
157 } 148 }
158 } 149 }
159 150
160 } // namespace ash 151 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/power/battery_notification.cc ('k') | base/i18n/time_formatting.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698