From 7e39e59f37cce1f0ad803b20d36bfaed3c6f7e5f Mon Sep 17 00:00:00 2001 From: Adrian Roos Date: Wed, 23 Sep 2015 17:03:47 -0700 Subject: Show charging speed when time to full is available Only shows if translation is available, follow-up I3e883eeca002e86d4df30c2b238e18bd63bbddea to show in all locales. Bug: 24167496 Change-Id: I667cde69e5d5f8aec8ac9fd105bbfb7e118ced64 --- packages/SystemUI/res/values-en/donottranslate.xml | 23 +++++++++++++++ packages/SystemUI/res/values/donottranslate.xml | 6 ++++ packages/SystemUI/res/values/strings.xml | 6 ++++ .../statusbar/KeyguardIndicationController.java | 33 ++++++++++++++-------- 4 files changed, 56 insertions(+), 12 deletions(-) create mode 100644 packages/SystemUI/res/values-en/donottranslate.xml (limited to 'packages/SystemUI') diff --git a/packages/SystemUI/res/values-en/donottranslate.xml b/packages/SystemUI/res/values-en/donottranslate.xml new file mode 100644 index 0000000..9f04e1f --- /dev/null +++ b/packages/SystemUI/res/values-en/donottranslate.xml @@ -0,0 +1,23 @@ + + + + + + @string/keyguard_indication_charging_time_fast + + @string/keyguard_indication_charging_time_slowly + \ No newline at end of file diff --git a/packages/SystemUI/res/values/donottranslate.xml b/packages/SystemUI/res/values/donottranslate.xml index 351a1fd..30ff704 100644 --- a/packages/SystemUI/res/values/donottranslate.xml +++ b/packages/SystemUI/res/values/donottranslate.xml @@ -20,4 +20,10 @@ @*android:string/system_ui_date_pattern + + @string/keyguard_indication_charging_time + + + @string/keyguard_indication_charging_time + diff --git a/packages/SystemUI/res/values/strings.xml b/packages/SystemUI/res/values/strings.xml index 3eac84f..dfa85ce 100644 --- a/packages/SystemUI/res/values/strings.xml +++ b/packages/SystemUI/res/values/strings.xml @@ -793,6 +793,12 @@ Charging (%s until full) + + Charging rapidly (%s until full) + + + Charging slowly (%s until full) + diff --git a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java index 54f91da..50d274d 100644 --- a/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java +++ b/packages/SystemUI/src/com/android/systemui/statusbar/KeyguardIndicationController.java @@ -187,32 +187,41 @@ public class KeyguardIndicationController { } // Try fetching charging time from battery stats. + long chargingTimeRemaining = 0; try { - long chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining(); - if (chargingTimeRemaining > 0) { - String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes( - mContext, chargingTimeRemaining); - return mContext.getResources().getString( - R.string.keyguard_indication_charging_time, chargingTimeFormatted); - } + chargingTimeRemaining = mBatteryInfo.computeChargeTimeRemaining(); + } catch (RemoteException e) { Log.e(TAG, "Error calling IBatteryStats: ", e); } + final boolean hasChargingTime = chargingTimeRemaining > 0; - // Fall back to simple charging label. int chargingId; switch (mChargingSpeed) { case KeyguardUpdateMonitor.BatteryStatus.CHARGING_FAST: - chargingId = R.string.keyguard_plugged_in_charging_fast; + chargingId = hasChargingTime + ? R.string.keyguard_indication_charging_time_fast_if_translated + : R.string.keyguard_plugged_in_charging_fast; break; case KeyguardUpdateMonitor.BatteryStatus.CHARGING_SLOWLY: - chargingId = R.string.keyguard_plugged_in_charging_slowly; + chargingId = hasChargingTime + ? R.string.keyguard_indication_charging_time_slowly_if_translated + : R.string.keyguard_plugged_in_charging_slowly; break; default: - chargingId = R.string.keyguard_plugged_in; + chargingId = hasChargingTime + ? R.string.keyguard_indication_charging_time + : R.string.keyguard_plugged_in; break; } - return mContext.getResources().getString(chargingId); + + if (hasChargingTime) { + String chargingTimeFormatted = Formatter.formatShortElapsedTimeRoundingUpToMinutes( + mContext, chargingTimeRemaining); + return mContext.getResources().getString(chargingId, chargingTimeFormatted); + } else { + return mContext.getResources().getString(chargingId); + } } KeyguardUpdateMonitorCallback mUpdateMonitor = new KeyguardUpdateMonitorCallback() { -- cgit v1.1