OLD | NEW |
---|---|
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/message_formatter.h" |
10 #include "base/i18n/time_formatting.h" | |
10 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
11 #include "base/time/time.h" | 12 #include "base/time/time.h" |
12 #include "grit/ash_resources.h" | 13 #include "grit/ash_resources.h" |
13 #include "grit/ash_strings.h" | 14 #include "grit/ash_strings.h" |
14 #include "ui/base/l10n/l10n_util.h" | 15 #include "ui/base/l10n/l10n_util.h" |
15 #include "ui/base/l10n/time_format.h" | 16 #include "ui/base/l10n/time_format.h" |
16 #include "ui/base/resource/resource_bundle.h" | 17 #include "ui/base/resource/resource_bundle.h" |
17 #include "ui/gfx/image/image.h" | 18 #include "ui/gfx/image/image.h" |
18 #include "ui/message_center/message_center.h" | 19 #include "ui/message_center/message_center.h" |
19 #include "ui/message_center/notification.h" | 20 #include "ui/message_center/notification.h" |
(...skipping 20 matching lines...) Expand all Loading... | |
40 resource_id = 0; | 41 resource_id = 0; |
41 } | 42 } |
42 | 43 |
43 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); | 44 return ui::ResourceBundle::GetSharedInstance().GetImageNamed(resource_id); |
44 } | 45 } |
45 | 46 |
46 std::unique_ptr<Notification> CreateNotification( | 47 std::unique_ptr<Notification> CreateNotification( |
47 TrayPower::NotificationState notification_state) { | 48 TrayPower::NotificationState notification_state) { |
48 const PowerStatus& status = *PowerStatus::Get(); | 49 const PowerStatus& status = *PowerStatus::Get(); |
49 | 50 |
51 base::string16 percentage = | |
52 base::i18n::MessageFormatter::FormatWithNumberedArgs( | |
53 base::ASCIIToUTF16("{0,number,percent}"), | |
54 static_cast<double>(status.GetRoundedBatteryPercent()) / 100.0); | |
50 base::string16 message = l10n_util::GetStringFUTF16( | 55 base::string16 message = l10n_util::GetStringFUTF16( |
51 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, | 56 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, percentage); |
jungshik at Google
2016/05/11 21:19:49
You can change IDS_ASH_...PRECENT from
<ph name
Greg Levin
2016/05/12 19:31:44
Done.
| |
52 base::IntToString16(status.GetRoundedBatteryPercent())); | |
53 | 57 |
54 const base::TimeDelta time = status.IsBatteryCharging() | 58 const base::TimeDelta time = status.IsBatteryCharging() |
55 ? status.GetBatteryTimeToFull() | 59 ? status.GetBatteryTimeToFull() |
56 : status.GetBatteryTimeToEmpty(); | 60 : status.GetBatteryTimeToEmpty(); |
57 base::string16 time_message; | 61 base::string16 time_message; |
58 if (status.IsUsbChargerConnected()) { | 62 if (status.IsUsbChargerConnected()) { |
59 time_message = l10n_util::GetStringUTF16( | 63 time_message = l10n_util::GetStringUTF16( |
60 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); | 64 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); |
61 } else if (PowerStatus::ShouldDisplayBatteryTime(time) && | 65 } else if (PowerStatus::ShouldDisplayBatteryTime(time) && |
62 !status.IsBatteryDischargingOnLinePower()) { | 66 !status.IsBatteryDischargingOnLinePower()) { |
63 int hour = 0, min = 0; | |
64 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min); | |
65 if (status.IsBatteryCharging()) { | 67 if (status.IsBatteryCharging()) { |
66 time_message = l10n_util::GetStringFUTF16( | 68 time_message = l10n_util::GetStringFUTF16( |
67 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, | 69 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, |
68 base::IntToString16(hour), base::IntToString16(min)); | 70 TimeDurationFormat(time, base::DURATION_WIDTH_NARROW)); |
69 } else { | 71 } else { |
70 // This is a low battery warning prompting the user in minutes. | 72 // This is a low battery warning prompting the user in minutes. |
71 time_message = ui::TimeFormat::Simple( | 73 time_message = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING, |
72 ui::TimeFormat::FORMAT_REMAINING, ui::TimeFormat::LENGTH_LONG, | 74 ui::TimeFormat::LENGTH_LONG, time); |
73 base::TimeDelta::FromMinutes(hour * 60 + min)); | |
74 } | 75 } |
75 } | 76 } |
76 | 77 |
77 if (!time_message.empty()) | 78 if (!time_message.empty()) |
78 message = message + base::ASCIIToUTF16("\n") + time_message; | 79 message = message + base::ASCIIToUTF16("\n") + time_message; |
79 | 80 |
80 std::unique_ptr<Notification> notification(new Notification( | 81 std::unique_ptr<Notification> notification(new Notification( |
81 message_center::NOTIFICATION_TYPE_SIMPLE, kBatteryNotificationId, | 82 message_center::NOTIFICATION_TYPE_SIMPLE, kBatteryNotificationId, |
82 base::string16(), message, GetBatteryImage(notification_state), | 83 base::string16(), message, GetBatteryImage(notification_state), |
83 base::string16(), GURL(), | 84 base::string16(), GURL(), |
(...skipping 20 matching lines...) Expand all Loading... | |
104 | 105 |
105 void BatteryNotification::Update( | 106 void BatteryNotification::Update( |
106 TrayPower::NotificationState notification_state) { | 107 TrayPower::NotificationState notification_state) { |
107 if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) { | 108 if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) { |
108 message_center_->UpdateNotification(kBatteryNotificationId, | 109 message_center_->UpdateNotification(kBatteryNotificationId, |
109 CreateNotification(notification_state)); | 110 CreateNotification(notification_state)); |
110 } | 111 } |
111 } | 112 } |
112 | 113 |
113 } // namespace ash | 114 } // namespace ash |
OLD | NEW |