From e2fbdfefefd0056255aed622b408c1003519dffc Mon Sep 17 00:00:00 2001 From: jackqdyulei Date: Mon, 13 Feb 2017 17:33:06 -0800 Subject: [PATCH] Refine battery text in battery header 1. When there exists estimate time, show it, otherwise show battery status label. 2. Change the summary based on whether it is charging. (Estimated time left vs Time to full charge) Bug: 35328749 Test: RunSettingsRoboTests Change-Id: I64ee8acd248062b4effcfc58ed908be7d89621a3 --- res/values/strings.xml | 3 ++ .../fuelgauge/BatteryHistoryPreference.java | 4 ++- .../settings/fuelgauge/PowerUsageSummary.java | 10 ++++-- .../fuelgauge/PowerUsageSummaryTest.java | 31 ++++++++++++++----- 4 files changed, 36 insertions(+), 12 deletions(-) diff --git a/res/values/strings.xml b/res/values/strings.xml index 852e81d94f1..eb6de8d1223 100644 --- a/res/values/strings.xml +++ b/res/values/strings.xml @@ -4493,6 +4493,9 @@ Estimated time left + + Time to full charge + Estimation may change based on usage diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java index 1a349f738a4..a1fe8496f4f 100644 --- a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java +++ b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java @@ -60,7 +60,9 @@ public class BatteryHistoryPreference extends Preference { view.itemView.setClickable(true); view.setDividerAllowedAbove(true); ((TextView) view.findViewById(R.id.charge)).setText(mBatteryInfo.batteryPercentString); - ((TextView) view.findViewById(R.id.estimation)).setText(mBatteryInfo.remainingLabel); + ((TextView) view.findViewById(R.id.estimation)).setText( + mBatteryInfo.remainingLabel != null ? + mBatteryInfo.remainingLabel : mBatteryInfo.statusLabel); UsageView usageView = (UsageView) view.findViewById(R.id.battery_usage); usageView.findViewById(R.id.label_group).setAlpha(.7f); mBatteryInfo.bindHistory(usageView); diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index 7b64ddfa570..e6966239502 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -16,6 +16,7 @@ package com.android.settings.fuelgauge; +import android.annotation.StringRes; import android.app.Activity; import android.content.Context; import android.graphics.drawable.Drawable; @@ -473,15 +474,18 @@ public class PowerUsageSummary extends PowerUsageBase { final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.time); final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1); final TextView summary2 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary2); - final int visible = info.mBatteryLevel != 100 ? View.VISIBLE : View.INVISIBLE; + final int visible = info.remainingTimeUs != 0 ? View.VISIBLE : View.INVISIBLE; + final int summaryResId = info.mDischarging ? + R.string.estimated_time_left : R.string.estimated_charging_time_left; if (info.remainingTimeUs != 0) { timeText.setText(Utils.formatElapsedTime(getContext(), info.remainingTimeUs / 1000, false)); } else { - timeText.setText(info.remainingLabel != null ? - info.remainingLabel : info.batteryPercentString); + timeText.setText(info.statusLabel); } + + summary1.setText(summaryResId); summary1.setVisibility(visible); summary2.setVisibility(visible); batteryView.setBatteryInfo(info.mBatteryLevel); diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java index f828238a5a9..ec850cdf490 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java @@ -65,8 +65,7 @@ public class PowerUsageSummaryTest { private static final String TIME_LEFT = "2h30min"; private static final int UID = 123; private static final int POWER_MAH = 100; - private static final int BATTERY_LEVEL_FULL = 100; - private static final int BATTERY_LEVEL_HALF = 50; + private static final long REMAINING_TIME_US = 100000; private static final double BATTERY_SCREEN_USAGE = 300; private static final double BATTERY_SYSTEM_USAGE = 600; private static final double PRECISION = 0.001; @@ -269,25 +268,41 @@ public class PowerUsageSummaryTest { } @Test - public void testUpdatePreference_BatteryFull_DoNotShowSummary() { - mBatteryInfo.mBatteryLevel = BATTERY_LEVEL_FULL; + public void testUpdatePreference_NoEstimatedTime_DoNotShowSummary() { + mBatteryInfo.remainingTimeUs = 0; mBatteryInfo.remainingLabel = TIME_LEFT; mPowerUsageSummary.updateHeaderPreference(mBatteryInfo); verify(mSummary1).setVisibility(View.INVISIBLE); verify(mSummary2).setVisibility(View.INVISIBLE); - verify(mTimeText).setText(mBatteryInfo.remainingLabel); } @Test - public void testUpdatePreference_BatteryNotFull_ShowSummary() { - mBatteryInfo.mBatteryLevel = BATTERY_LEVEL_HALF; + public void testUpdatePreference_HasEstimatedTime_ShowSummary() { + mBatteryInfo.remainingTimeUs = REMAINING_TIME_US; mBatteryInfo.remainingLabel = TIME_LEFT; mPowerUsageSummary.updateHeaderPreference(mBatteryInfo); verify(mSummary1).setVisibility(View.VISIBLE); verify(mSummary2).setVisibility(View.VISIBLE); - verify(mTimeText).setText(mBatteryInfo.remainingLabel); + } + + @Test + public void testUpdatePreference_Charging_ShowChargingTimeLeft() { + mBatteryInfo.remainingTimeUs = REMAINING_TIME_US; + mBatteryInfo.mDischarging = false; + + mPowerUsageSummary.updateHeaderPreference(mBatteryInfo); + verify(mSummary1).setText(R.string.estimated_charging_time_left); + } + + @Test + public void testUpdatePreference_NotCharging_ShowTimeLeft() { + mBatteryInfo.remainingTimeUs = REMAINING_TIME_US; + mBatteryInfo.mDischarging = true; + + mPowerUsageSummary.updateHeaderPreference(mBatteryInfo); + verify(mSummary1).setText(R.string.estimated_time_left); } public static class TestFragment extends PowerUsageSummary {