From 4d8a2a414307ed1ccbbbdd61eed77d1ed747b286 Mon Sep 17 00:00:00 2001 From: Evan Laird Date: Mon, 11 Mar 2019 19:39:04 -0400 Subject: [PATCH] Go back to original string for <1 day case Battery remaining estimate will say "Until H:MM" in quick settings. Also shorten the alloted #chars from 100 to 20 Test: visual Fixes: 124861973 Change-Id: I48893e0254c6b3f84901866f6bf376015ca61251 --- packages/SettingsLib/res/values/strings.xml | 4 ++-- .../android/settingslib/utils/PowerUtil.java | 17 ++++++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/packages/SettingsLib/res/values/strings.xml b/packages/SettingsLib/res/values/strings.xml index c60e8c321ec56..2a83edb03d1a1 100644 --- a/packages/SettingsLib/res/values/strings.xml +++ b/packages/SettingsLib/res/values/strings.xml @@ -937,7 +937,7 @@ About %1$s left based on your usage About %1$s left based on your usage (%2$s) - + %1$s @@ -948,7 +948,7 @@ Should last until about %1$s (%2$s) Should last until about %1$s - + Until %1$s Extend battery life past %1$s diff --git a/packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java b/packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java index 5600dd279b95c..7046d234904b1 100644 --- a/packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java +++ b/packages/SettingsLib/src/com/android/settingslib/utils/PowerUtil.java @@ -223,12 +223,19 @@ public class PowerUtil { } private static String getRegularTimeRemainingShortString(Context context, long drainTimeMs) { - // Get the time remaining rounded to the nearest 15 min - final long roundedTimeMs = roundTimeToNearestThreshold(drainTimeMs, FIFTEEN_MINUTES_MILLIS); - CharSequence timeString = StringUtil.formatElapsedTime(context, roundedTimeMs, - false /* withSeconds */); + // Get the time of day we think device will die rounded to the nearest 15 min. + final long roundedTimeOfDayMs = + roundTimeToNearestThreshold( + System.currentTimeMillis() + drainTimeMs, + FIFTEEN_MINUTES_MILLIS); - return context.getString(R.string.power_remaining_duration_only_short, timeString); + // convert the time to a properly formatted string. + String skeleton = android.text.format.DateFormat.getTimeFormatString(context); + DateFormat fmt = DateFormat.getInstanceForSkeleton(skeleton); + Date date = Date.from(Instant.ofEpochMilli(roundedTimeOfDayMs)); + CharSequence timeString = fmt.format(date); + + return context.getString(R.string.power_discharge_by_only_short, timeString); } public static long convertUsToMs(long timeUs) {