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

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: 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/ash_chromeos_strings.grdp ('k') | ash/system/chromeos/power/power_status_view.cc » ('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 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
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
50 base::string16 message = l10n_util::GetStringFUTF16( 51 base::string16 message = base::i18n::MessageFormatter::FormatWithNumberedArgs(
51 IDS_ASH_STATUS_TRAY_BATTERY_PERCENT, 52 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_BATTERY_PERCENT),
52 base::IntToString16(status.GetRoundedBatteryPercent())); 53 static_cast<double>(status.GetRoundedBatteryPercent()) / 100.0);
53 54
54 const base::TimeDelta time = status.IsBatteryCharging() 55 const base::TimeDelta time = status.IsBatteryCharging()
55 ? status.GetBatteryTimeToFull() 56 ? status.GetBatteryTimeToFull()
56 : status.GetBatteryTimeToEmpty(); 57 : status.GetBatteryTimeToEmpty();
57 base::string16 time_message; 58 base::string16 time_message;
58 if (status.IsUsbChargerConnected()) { 59 if (status.IsUsbChargerConnected()) {
59 time_message = l10n_util::GetStringUTF16( 60 time_message = l10n_util::GetStringUTF16(
60 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE); 61 IDS_ASH_STATUS_TRAY_BATTERY_CHARGING_UNRELIABLE);
61 } else if (PowerStatus::ShouldDisplayBatteryTime(time) && 62 } else if (PowerStatus::ShouldDisplayBatteryTime(time) &&
62 !status.IsBatteryDischargingOnLinePower()) { 63 !status.IsBatteryDischargingOnLinePower()) {
63 int hour = 0, min = 0;
64 PowerStatus::SplitTimeIntoHoursAndMinutes(time, &hour, &min);
65 if (status.IsBatteryCharging()) { 64 if (status.IsBatteryCharging()) {
66 time_message = l10n_util::GetStringFUTF16( 65 time_message = l10n_util::GetStringFUTF16(
67 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL, 66 IDS_ASH_STATUS_TRAY_BATTERY_TIME_UNTIL_FULL,
68 base::IntToString16(hour), base::IntToString16(min)); 67 TimeDurationFormat(time, base::DURATION_WIDTH_NARROW));
69 } else { 68 } else {
70 // This is a low battery warning prompting the user in minutes. 69 // This is a low battery warning prompting the user in minutes.
71 time_message = ui::TimeFormat::Simple( 70 time_message = ui::TimeFormat::Simple(ui::TimeFormat::FORMAT_REMAINING,
72 ui::TimeFormat::FORMAT_REMAINING, ui::TimeFormat::LENGTH_LONG, 71 ui::TimeFormat::LENGTH_LONG, time);
73 base::TimeDelta::FromMinutes(hour * 60 + min));
74 } 72 }
75 } 73 }
76 74
77 if (!time_message.empty()) 75 if (!time_message.empty())
78 message = message + base::ASCIIToUTF16("\n") + time_message; 76 message = message + base::ASCIIToUTF16("\n") + time_message;
79 77
80 std::unique_ptr<Notification> notification(new Notification( 78 std::unique_ptr<Notification> notification(new Notification(
81 message_center::NOTIFICATION_TYPE_SIMPLE, kBatteryNotificationId, 79 message_center::NOTIFICATION_TYPE_SIMPLE, kBatteryNotificationId,
82 base::string16(), message, GetBatteryImage(notification_state), 80 base::string16(), message, GetBatteryImage(notification_state),
83 base::string16(), GURL(), 81 base::string16(), GURL(),
(...skipping 20 matching lines...) Expand all
104 102
105 void BatteryNotification::Update( 103 void BatteryNotification::Update(
106 TrayPower::NotificationState notification_state) { 104 TrayPower::NotificationState notification_state) {
107 if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) { 105 if (message_center_->FindVisibleNotificationById(kBatteryNotificationId)) {
108 message_center_->UpdateNotification(kBatteryNotificationId, 106 message_center_->UpdateNotification(kBatteryNotificationId,
109 CreateNotification(notification_state)); 107 CreateNotification(notification_state));
110 } 108 }
111 } 109 }
112 110
113 } // namespace ash 111 } // namespace ash
OLDNEW
« no previous file with comments | « ash/ash_chromeos_strings.grdp ('k') | ash/system/chromeos/power/power_status_view.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698