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

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

Issue 1951493002: Fix i18n number formats in tray power displays (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/battery_notification.h" 5 #include "ash/system/chromeos/power/battery_notification.h"
6 6
7 #include "ash/system/chromeos/power/power_status.h" 7 #include "ash/system/chromeos/power/power_status.h"
8 #include "ash/system/system_notifier.h" 8 #include "ash/system/system_notifier.h"
9 #include "base/strings/string_number_conversions.h" 9 #include "base/i18n/number_formatting.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
11 #include "base/time/time.h" 11 #include "base/time/time.h"
12 #include "grit/ash_resources.h" 12 #include "grit/ash_resources.h"
13 #include "grit/ash_strings.h" 13 #include "grit/ash_strings.h"
14 #include "ui/base/l10n/l10n_util.h" 14 #include "ui/base/l10n/l10n_util.h"
15 #include "ui/base/l10n/time_format.h" 15 #include "ui/base/l10n/time_format.h"
16 #include "ui/base/resource/resource_bundle.h" 16 #include "ui/base/resource/resource_bundle.h"
17 #include "ui/gfx/image/image.h" 17 #include "ui/gfx/image/image.h"
18 #include "ui/message_center/message_center.h" 18 #include "ui/message_center/message_center.h"
19 #include "ui/message_center/notification.h" 19 #include "ui/message_center/notification.h"
(...skipping 22 matching lines...) Expand all
42 42
43 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); 43 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(resource_id);
44 } 44 }
45 45
46 std::unique_ptr<Notification> CreateNotification( 46 std::unique_ptr<Notification> CreateNotification(
47 TrayPower::NotificationState notification_state) { 47 TrayPower::NotificationState notification_state) {
48 const PowerStatus& status = *PowerStatus::Get(); 48 const PowerStatus& status = *PowerStatus::Get();
49 49
50 base::string16 message = l10n_util::GetStringFUTF16( 50 base::string16 message = l10n_util::GetStringFUTF16(
51 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, 51 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT,
52 base::IntToString16(status.GetRoundedBatteryPercent())); 52 base::FormatNumber(status.GetRoundedBatteryPercent()));
53 53
54 const base::TimeDelta time = status.IsBatteryCharging() 54 const base::TimeDelta time = status.IsBatteryCharging()
55 ? status.GetBatteryTimeToFull() 55 ? status.GetBatteryTimeToFull()
56 : status.GetBatteryTimeToEmpty(); 56 : status.GetBatteryTimeToEmpty();
57 base::string16 time_message; 57 base::string16 time_message;
58 if (status.IsUsbChargerConnected()) { 58 if (status.IsUsbChargerConnected()) {
59 time_message = l10n_util::GetStringUTF16( 59 time_message = l10n_util::GetStringUTF16(
60 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); 60 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE);
61 } else if (PowerStatus::ShouldDisplayBatteryTime(time) && 61 } else if (PowerStatus::ShouldDisplayBatteryTime(time) &&
62 !status.IsBatteryDischargingOnLinePower()) { 62 !status.IsBatteryDischargingOnLinePower()) {
63 int hour = 0, min = 0; 63 int hour = 0, min = 0;
64 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); 64 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min);
65 if (status.IsBatteryCharging()) { 65 if (status.IsBatteryCharging()) {
66 time_message = l10n_util::GetStringFUTF16( 66 time_message = l10n_util::GetStringFUTF16(
67 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, 67 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, base::FormatNumber(hour),
Daniel Erat 2016/05/03 19:17:33 just to check, is some combination of hours and mi
stevenjb 2016/05/03 19:49:09 +1. This seems like something that we ought to hav
jungshik at Google 2016/05/10 08:50:44 Do we really need to use "2h 3m" instead of '2 hrs
Greg Levin 2016/05/11 19:43:02 Thanks for the code snippet... HUGE help! Got it
68 base::IntToString16(hour), base::IntToString16(min)); 68 base::FormatNumber(min));
69 } else { 69 } else {
70 // This is a low battery warning prompting the user in minutes. 70 // This is a low battery warning prompting the user in minutes.
71 time_message = ui::TimeFormat::Simple( 71 time_message = ui::TimeFormat::Simple(
72 ui::TimeFormat::FORMAT_REMAINING, ui::TimeFormat::LENGTH_LONG, 72 ui::TimeFormat::FORMAT_REMAINING, ui::TimeFormat::LENGTH_LONG,
73 base::TimeDelta::FromMinutes(hour * 60 + min)); 73 base::TimeDelta::FromMinutes(hour * 60 + min));
74 } 74 }
75 } 75 }
76 76
77 if (!time_message.empty()) 77 if (!time_message.empty())
78 message = message + base::ASCIIToUTF16("\n") + time_message; 78 message = message + base::ASCIIToUTF16("\n") + time_message;
(...skipping 25 matching lines...) Expand all
104 104
105 void BatteryNotification::Update( 105 void BatteryNotification::Update(
106 TrayPower::NotificationState notification_state) { 106 TrayPower::NotificationState notification_state) {
107 if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) { 107 if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) {
108 message_center_->UpdateNotification(kBatteryNotificationId, 108 message_center_->UpdateNotification(kBatteryNotificationId,
109 CreateNotification(notification_state)); 109 CreateNotification(notification_state));
110 } 110 }
111 } 111 }
112 112
113 } // namespace ash 113 } // namespace ash
OLDNEW
« no previous file with comments | « no previous file | ash/system/chromeos/power/power_status_view.cc » ('j') | ash/system/chromeos/power/power_status_view.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698