Chromium Code Reviews| OLD | NEW |
|---|---|
| 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/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
| 15 #include "grit/ash_strings.h" | 15 #include "grit/ash_strings.h" |
| 16 #include "ui/base/l10n/l10n_util.h" | 16 #include "ui/base/l10n/l10n_util.h" |
| 17 #include "ui/base/l10n/time_format.h" | 17 #include "ui/base/l10n/time_format.h" |
| 18 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 19 #include "ui/views/controls/image_view.h" | 19 #include "ui/views/controls/image_view.h" |
| 20 #include "ui/views/controls/label.h" | 20 #include "ui/views/controls/label.h" |
| 21 #include "ui/views/layout/box_layout.h" | 21 #include "ui/views/layout/box_layout.h" |
| 22 #include "ui/views/layout/grid_layout.h" | 22 #include "ui/views/layout/grid_layout.h" |
| 23 | 23 |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 83 void PowerStatusView::UpdateText() { | 83 void PowerStatusView::UpdateText() { |
| 84 const PowerStatus& status = *PowerStatus::Get(); | 84 const PowerStatus& status = *PowerStatus::Get(); |
| 85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | 85 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); |
| 86 base::string16 battery_percentage; | 86 base::string16 battery_percentage; |
| 87 base::string16 battery_time_status; | 87 base::string16 battery_time_status; |
| 88 | 88 |
| 89 if (status.IsBatteryFull()) { | 89 if (status.IsBatteryFull()) { |
| 90 battery_time_status = | 90 battery_time_status = |
| 91 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); | 91 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_FULL); |
| 92 } else { | 92 } else { |
| 93 battery_percentage = l10n_util::GetStringFUTF16( | 93 battery_percentage = base::i18n::MessageFormatter::FormatWithNumberedArgs( |
| 94 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT_ONLY, | 94 base::ASCIIToUTF16("{0,number,percent}"), |
| 95 base::IntToString16(status.GetRoundedBatteryPercent())); | 95 static_cast<double>(status.GetRoundedBatteryPercent()) / 100.0); |
| 96 if (status.IsUsbChargerConnected()) { | 96 if (status.IsUsbChargerConnected()) { |
| 97 battery_time_status = rb.GetLocalizedString( | 97 battery_time_status = rb.GetLocalizedString( |
| 98 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); | 98 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); |
| 99 } else if (status.IsBatteryTimeBeingCalculated()) { | 99 } else if (status.IsBatteryTimeBeingCalculated()) { |
| 100 battery_time_status = | 100 battery_time_status = |
| 101 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); | 101 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_BATTERY_CALCULATING); |
| 102 } else { | 102 } else { |
| 103 base::TimeDelta time = status.IsBatteryCharging() ? | 103 base::TimeDelta time = status.IsBatteryCharging() ? |
| 104 status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty(); | 104 status.GetBatteryTimeToFull() : status.GetBatteryTimeToEmpty(); |
| 105 if (PowerStatus::ShouldDisplayBatteryTime(time) && | 105 if (PowerStatus::ShouldDisplayBatteryTime(time) && |
| 106 !status.IsBatteryDischargingOnLinePower()) { | 106 !status.IsBatteryDischargingOnLinePower()) { |
| 107 int hour = 0, min = 0; | 107 int hour = 0, min = 0; |
| 108 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); | 108 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); |
| 109 base::string16 minute = min < 10 ? | 109 base::string16 pattern = rb.GetLocalizedString( |
| 110 base::ASCIIToUTF16("0") + base::IntToString16(min) : | 110 status.IsBatteryCharging() |
| 111 base::IntToString16(min); | 111 ? IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL_SHORT |
| 112 : IDS_ASH_STATUS_TRAY_BATTERY_TIME_LEFT_SHORT); | |
|
jungshik at Google
2016/05/11 20:32:39
Please use l10n_util::GetStringUTF16()
Greg Levin
2016/05/12 19:31:43
I had already switched back to GetStringFUTF16() i
jungshik at Google
2016/05/13 23:00:35
Oh. I didn't realize that there are other uses of
Greg Levin
2016/05/16 17:12:56
Done.
| |
| 112 battery_time_status = | 113 battery_time_status = |
| 113 l10n_util::GetStringFUTF16( | 114 base::i18n::MessageFormatter::FormatWithNumberedArgs(pattern, hour, |
| 114 status.IsBatteryCharging() ? | 115 min); |
| 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 } | 116 } |
| 120 } | 117 } |
| 121 battery_percentage = battery_time_status.empty() ? | 118 battery_percentage = battery_time_status.empty() ? |
| 122 battery_percentage : battery_percentage + base::ASCIIToUTF16(" - "); | 119 battery_percentage : battery_percentage + base::ASCIIToUTF16(" - "); |
| 123 } | 120 } |
| 124 percentage_label_->SetVisible(!battery_percentage.empty()); | 121 percentage_label_->SetVisible(!battery_percentage.empty()); |
| 125 percentage_label_->SetText(battery_percentage); | 122 percentage_label_->SetText(battery_percentage); |
| 126 time_status_label_->SetVisible(!battery_time_status.empty()); | 123 time_status_label_->SetVisible(!battery_time_status.empty()); |
| 127 time_status_label_->SetText(battery_time_status); | 124 time_status_label_->SetText(battery_time_status); |
| 128 } | 125 } |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 144 views::View::Layout(); | 141 views::View::Layout(); |
| 145 | 142 |
| 146 // Move the time_status_label_ closer to percentage_label_. | 143 // Move the time_status_label_ closer to percentage_label_. |
| 147 if (percentage_label_ && time_status_label_ && | 144 if (percentage_label_ && time_status_label_ && |
| 148 percentage_label_->visible() && time_status_label_->visible()) { | 145 percentage_label_->visible() && time_status_label_->visible()) { |
| 149 time_status_label_->SetX(percentage_label_->bounds().right() + 1); | 146 time_status_label_->SetX(percentage_label_->bounds().right() + 1); |
| 150 } | 147 } |
| 151 } | 148 } |
| 152 | 149 |
| 153 } // namespace ash | 150 } // namespace ash |
| OLD | NEW |