From 950d94f689122ff63d14eda16d1cbe2c1148164f Mon Sep 17 00:00:00 2001 From: Salvador Martinez Date: Wed, 18 Apr 2018 15:56:28 -0700 Subject: [PATCH] Update settings main page battery string UX requested that the percentage be moved to the front. Test: robotests pass Bug: 77874406 Change-Id: I7008c81fa42487bb71ecd84b6a66203d89fe50a8 --- .../settings/fuelgauge/PowerUsageSummary.java | 17 ++++++++++++++++- .../fuelgauge/PowerUsageSummaryTest.java | 13 +++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java index 4c4b6e926ca..0563815dd71 100644 --- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java +++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java @@ -25,6 +25,7 @@ import android.os.BatteryStats; import android.os.Bundle; import android.provider.SearchIndexableResource; import android.support.annotation.VisibleForTesting; +import android.text.BidiFormatter; import android.text.format.Formatter; import android.util.SparseArray; import android.view.Menu; @@ -431,7 +432,7 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList BatteryInfo.getBatteryInfo(mContext, new BatteryInfo.Callback() { @Override public void onBatteryInfoLoaded(BatteryInfo info) { - mLoader.setSummary(SummaryProvider.this, info.chargeLabel); + mLoader.setSummary(SummaryProvider.this, getDashboardLabel(mContext, info)); } }, true /* shortString */); }); @@ -447,6 +448,20 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList } } + @VisibleForTesting + static CharSequence getDashboardLabel(Context context, BatteryInfo info) { + CharSequence label; + final BidiFormatter formatter = BidiFormatter.getInstance(); + if (info.remainingLabel == null) { + label = info.batteryPercentString; + } else { + label = context.getString(R.string.power_remaining_settings_home_page, + formatter.unicodeWrap(info.batteryPercentString), + formatter.unicodeWrap(info.remainingLabel)); + } + return label; + } + public static final SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER = new BaseSearchIndexProvider() { @Override diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java index b20cf168261..b48f00e295b 100644 --- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java +++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java @@ -48,6 +48,7 @@ import com.android.internal.os.BatteryStatsHelper; import com.android.settings.R; import com.android.settings.SettingsActivity; import com.android.settings.applications.LayoutPreference; +import com.android.settings.dashboard.SummaryLoader; import com.android.settings.fuelgauge.anomaly.Anomaly; import com.android.settings.fuelgauge.batterytip.BatteryTipPreferenceController; import com.android.settings.testutils.FakeFeatureFactory; @@ -375,6 +376,18 @@ public class PowerUsageSummaryTest { verify(mFragment).restartBatteryTipLoader(); } + @Test + public void getDashboardLabel_returnsCorrectLabel() { + BatteryInfo info = new BatteryInfo(); + info.batteryPercentString = "3%"; + assertThat(PowerUsageSummary.getDashboardLabel(mRealContext, info)) + .isEqualTo(info.batteryPercentString); + + info.remainingLabel = "Phone will shut down soon"; + assertThat(PowerUsageSummary.getDashboardLabel(mRealContext, info)) + .isEqualTo("3% - Phone will shut down soon"); + } + public static class TestFragment extends PowerUsageSummary { private Context mContext;