Revamp battery Ui in low battery mode

This cl refine battery icon ui in low battery mode:
1. Should show indicator(fixed in ag/2035178)
2. Show bolt icon when charging
3. When battery is low, set battery background as red and indicator
as white.

This cl also includes the field updates for battery.

Bug: 36862496
Test: RunSettingsRoboTests
Change-Id: Ifb2ed339742119bbff78712df09288b895756b1f
This commit is contained in:
jackqdyulei
2017-04-04 10:03:14 -07:00
parent 66871d8531
commit f8e6f43425
7 changed files with 138 additions and 27 deletions

View File

@@ -37,6 +37,8 @@ import com.android.settings.TestConfig;
import com.android.settings.Utils;
import com.android.settings.applications.LayoutPreference;
import com.android.settings.testutils.FakeFeatureFactory;
import com.android.settings.testutils.shadow.SettingsShadowResources;
import com.android.settings.testutils.shadow.ShadowDynamicIndexableContentMonitor;
import com.android.settingslib.BatteryInfo;
import org.junit.Before;
@@ -74,7 +76,13 @@ import static org.mockito.Mockito.when;
*/
// TODO: Improve this test class so that it starts up the real activity and fragment.
@RunWith(SettingsRobolectricTestRunner.class)
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
@Config(manifest = TestConfig.MANIFEST_PATH,
sdk = TestConfig.SDK_VERSION,
shadows = {
SettingsShadowResources.class,
SettingsShadowResources.SettingsShadowTheme.class,
ShadowDynamicIndexableContentMonitor.class
})
public class PowerUsageSummaryTest {
private static final String[] PACKAGE_NAMES = {"com.app1", "com.app2"};
private static final String TIME_LEFT = "2h30min";
@@ -123,8 +131,6 @@ public class PowerUsageSummaryTest {
@Mock
private LayoutPreference mBatteryLayoutPref;
@Mock
private BatteryMeterView mBatteryMeterView;
@Mock
private TextView mBatteryPercentText;
@Mock
private TextView mSummary1;
@@ -145,6 +151,7 @@ public class PowerUsageSummaryTest {
private Context mRealContext;
private TestFragment mFragment;
private FakeFeatureFactory mFeatureFactory;
private BatteryMeterView mBatteryMeterView;
@Before
public void setUp() {
@@ -157,6 +164,8 @@ public class PowerUsageSummaryTest {
mFragment = spy(new TestFragment(mContext));
mFragment.initFeatureProvider();
mBatteryMeterView = new BatteryMeterView(mRealContext);
mBatteryMeterView.mDrawable = new BatteryMeterView.BatteryMeterDrawable(mRealContext, 0);
when(mFragment.getActivity()).thenReturn(mSettingsActivity);
when(mAdditionalBatteryInfoMenu.getItemId())
@@ -204,7 +213,7 @@ public class PowerUsageSummaryTest {
mFragment.mScreenUsagePref = mScreenUsagePref;
mFragment.mLastFullChargePref = mLastFullChargePref;
mBatteryInfo.mBatteryLevel = BATTERY_LEVEL;
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
}
@Test
@@ -411,6 +420,18 @@ public class PowerUsageSummaryTest {
verify(mSummary1).setText(mBatteryInfo.remainingLabel);
}
@Test
public void testUpdatePreference_updateBatteryInfo() {
mBatteryInfo.remainingLabel = TIME_LEFT;
mBatteryInfo.batteryLevel = BATTERY_LEVEL;
mBatteryInfo.discharging = true;
mFragment.updateHeaderPreference(mBatteryInfo);
assertThat(mBatteryMeterView.mDrawable.getBatteryLevel()).isEqualTo(BATTERY_LEVEL);
assertThat(mBatteryMeterView.mDrawable.getCharging()).isEqualTo(false);
}
@Test
public void testUpdatePreference_noRemainingTime_showStatusLabel() {
mBatteryInfo.remainingLabel = null;