From 874b35b83613eac69d5a9a35bc62e4ac5efc385c Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 5 Nov 2014 16:11:10 +0100 Subject: [PATCH] Round charging indication to nearest minute Bug: 18177374 Change-Id: I4eb7fcac83398a4d8432bf092d8d91506646b5a1 --- core/java/android/text/format/Formatter.java | 21 +++++++++++++++++++++ core/res/res/values/strings.xml | 3 +++ core/res/res/values/symbols.xml | 1 + .../statusbar/KeyguardIndicationController.java | 4 ++-- 4 files changed, 27 insertions(+), 2 deletions(-) diff --git a/core/java/android/text/format/Formatter.java b/core/java/android/text/format/Formatter.java index b0cbcd224c87..b467f5a8c67a 100644 --- a/core/java/android/text/format/Formatter.java +++ b/core/java/android/text/format/Formatter.java @@ -110,6 +110,7 @@ public final class Formatter { private static final int SECONDS_PER_MINUTE = 60; private static final int SECONDS_PER_HOUR = 60 * 60; private static final int SECONDS_PER_DAY = 24 * 60 * 60; + private static final int MILLIS_PER_MINUTE = 1000 * 60; /** * Returns elapsed time for the given millis, in the following format: @@ -171,4 +172,24 @@ public final class Formatter { return context.getString(com.android.internal.R.string.durationSeconds, seconds); } } + + /** + * Returns elapsed time for the given millis, in the following format: + * 1 day 5 hrs; will include at most two units, can go down to minutes precision. + * @param context the application context + * @param millis the elapsed time in milli seconds + * @return the formatted elapsed time + * @hide + */ + public static String formatShortElapsedTimeRoundingUpToMinutes(Context context, long millis) { + long minutesRoundedUp = (millis + MILLIS_PER_MINUTE - 1) / MILLIS_PER_MINUTE; + + if (minutesRoundedUp == 0) { + return context.getString(com.android.internal.R.string.durationMinutes, 0); + } else if (minutesRoundedUp == 1) { + return context.getString(com.android.internal.R.string.durationMinute, 1); + } + + return formatShortElapsedTime(context, minutesRoundedUp * MILLIS_PER_MINUTE); + } } diff --git a/core/res/res/values/strings.xml b/core/res/res/values/strings.xml index 61fc16188e75..dae43ececb43 100644 --- a/core/res/res/values/strings.xml +++ b/core/res/res/values/strings.xml @@ -61,6 +61,9 @@ %1$d mins + + %1$d min + %1$d min %2$d secs diff --git a/core/res/res/values/symbols.xml b/core/res/res/values/symbols.xml index 3835d8bb1025..bf941e531377 100644 --- a/core/res/res/values/symbols.xml +++ b/core/res/res/values/symbols.xml @@ -574,6 +574,7 @@ + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index 992aa9fa4c50..58067c3001ab 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -146,8 +146,8 @@ public class KeyguardIndicationController { try { long chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining(); if (chargingTimeRemaining > 0) { - String chargingTimeFormatted = - Formatter.formatShortElapsedTime(mContext, chargingTimeRemaining); + String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes( + mContext, chargingTimeRemaining); return mContext.getResources().getString( R.string.keyguard_indication_charging_time, chargingTimeFormatted); } -- 2.11.0