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
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 852e81d..eb6de8d1 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -4493,6 +4493,9 @@
     <!-- Description for battery time left, i.e. 50min Estimated time left. [CHAR LIMIT=80]-->
     <string name="estimated_time_left">Estimated time left</string>
 
+    <!-- Description for charging time left, i.e. 50min Time to full charge. [CHAR LIMIT=80]-->
+    <string name="estimated_charging_time_left">Time to full charge</string>
+
     <!-- Description for estimated time. [CHAR LIMIT=80]-->
     <string name="estimated_time_description">Estimation may change based on usage</string>
 
diff --git a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
index 1a349f7..a1fe849 100644
--- a/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
+++ b/src/com/android/settings/fuelgauge/BatteryHistoryPreference.java
@@ -60,7 +60,9 @@
         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 7b64ddf..e696623 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 @@
         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 f828238..ec850cd 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 @@
     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 @@
     }
 
     @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 {