Fix Battery page animation
TextView summary1 has default height 2 line. If the content is longer
than 2 line, the TextView increases itself which causes the animation.
By increasing minLines to 3, it can avoid the animation. And remove
summary2 because it is only for debug purpose, the debug information
can be merged to summary1.
Fixes: 139554919
Test: visual, make RunSettingsRoboTests
Change-Id: I167ac87c9bd83035e00d4991961599e76f4f69e1
diff --git a/res/layout/battery_header.xml b/res/layout/battery_header.xml
index b3b699a..dca0972 100644
--- a/res/layout/battery_header.xml
+++ b/res/layout/battery_header.xml
@@ -44,16 +44,10 @@
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="8dp"
- android:minLines="2"
+ android:minLines="3"
android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"/>
android:textColor="?android:attr/textColorPrimary"/>
- <TextView
- android:id="@+id/summary2"
- android:layout_width="match_parent"
- android:layout_height="wrap_content"
- android:textAppearance="@android:style/TextAppearance.DeviceDefault.Small"/>
- android:textColor="?android:attr/textColorPrimary"/>
</LinearLayout>
<com.android.settings.fuelgauge.BatteryMeterView
diff --git a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
index 3064d4f..bfa43d1 100644
--- a/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
+++ b/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceController.java
@@ -55,8 +55,6 @@
TextView mBatteryPercentText;
@VisibleForTesting
TextView mSummary1;
- @VisibleForTesting
- TextView mSummary2;
private Activity mActivity;
private PreferenceFragmentCompat mHost;
@@ -90,7 +88,6 @@
.findViewById(R.id.battery_header_icon);
mBatteryPercentText = mBatteryLayoutPref.findViewById(R.id.battery_percent);
mSummary1 = mBatteryLayoutPref.findViewById(R.id.summary1);
- mSummary2 = mBatteryLayoutPref.findViewById(R.id.summary2);
quickUpdateHeaderPreference();
}
@@ -115,9 +112,6 @@
} else {
mSummary1.setText(info.remainingLabel);
}
- // Clear this just to be sure we don't get UI jank on re-entering this view from another
- // activity.
- mSummary2.setText("");
mBatteryMeterView.setBatteryLevel(info.batteryLevel);
mBatteryMeterView.setCharging(!info.discharging);
diff --git a/src/com/android/settings/fuelgauge/PowerUsageSummary.java b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
index 4a68be9..4034efc 100644
--- a/src/com/android/settings/fuelgauge/PowerUsageSummary.java
+++ b/src/com/android/settings/fuelgauge/PowerUsageSummary.java
@@ -19,15 +19,12 @@
import static com.android.settings.fuelgauge.BatteryBroadcastReceiver.BatteryUpdateType;
import android.app.settings.SettingsEnums;
-import android.content.ContentResolver;
import android.content.Context;
import android.database.ContentObserver;
import android.net.Uri;
-import android.os.BatteryStats;
import android.os.Bundle;
import android.os.Handler;
import android.provider.SearchIndexableResource;
-import android.provider.Settings;
import android.provider.Settings.Global;
import android.text.format.Formatter;
import android.view.Menu;
@@ -157,7 +154,6 @@
final TextView percentRemaining =
mBatteryLayoutPref.findViewById(R.id.battery_percent);
final TextView summary1 = mBatteryLayoutPref.findViewById(R.id.summary1);
- final TextView summary2 = mBatteryLayoutPref.findViewById(R.id.summary2);
BatteryInfo oldInfo = batteryInfos.get(0);
BatteryInfo newInfo = batteryInfos.get(1);
percentRemaining.setText(Utils.formatPercentage(oldInfo.batteryLevel));
@@ -165,14 +161,13 @@
// set the text to the old estimate (copied from battery info). Note that this
// can sometimes say 0 time remaining because battery stats requires the phone
// be unplugged for a period of time before being willing ot make an estimate.
- summary1.setText(mPowerFeatureProvider.getOldEstimateDebugString(
+ final String OldEstimateString = mPowerFeatureProvider.getOldEstimateDebugString(
Formatter.formatShortElapsedTime(getContext(),
- PowerUtil.convertUsToMs(oldInfo.remainingTimeUs))));
-
- // for this one we can just set the string directly
- summary2.setText(mPowerFeatureProvider.getEnhancedEstimateDebugString(
+ PowerUtil.convertUsToMs(oldInfo.remainingTimeUs)));
+ final String NewEstimateString = mPowerFeatureProvider.getEnhancedEstimateDebugString(
Formatter.formatShortElapsedTime(getContext(),
- PowerUtil.convertUsToMs(newInfo.remainingTimeUs))));
+ PowerUtil.convertUsToMs(newInfo.remainingTimeUs)));
+ summary1.setText(OldEstimateString + "\n" + NewEstimateString);
batteryView.setBatteryLevel(oldInfo.batteryLevel);
batteryView.setCharging(!oldInfo.discharging);
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
index 5be7274..63e8a80 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/BatteryHeaderPreferenceControllerTest.java
@@ -85,7 +85,6 @@
private BatteryMeterView mBatteryMeterView;
private TextView mBatteryPercentText;
private TextView mSummary;
- private TextView mSummary2;
private LayoutPreference mBatteryLayoutPref;
private Intent mBatteryIntent;
private LifecycleOwner mLifecycleOwner;
@@ -102,7 +101,6 @@
mBatteryPercentText = new TextView(mContext);
mSummary = new TextView(mContext);
ShadowEntityHeaderController.setUseMock(mEntityHeaderController);
- mSummary2 = new TextView(mContext);
mBatteryIntent = new Intent();
mBatteryIntent.putExtra(BatteryManager.EXTRA_LEVEL, BATTERY_LEVEL);
@@ -126,7 +124,6 @@
mController.mBatteryMeterView = mBatteryMeterView;
mController.mBatteryPercentText = mBatteryPercentText;
mController.mSummary1 = mSummary;
- mController.mSummary2 = mSummary2;
}
@After
@@ -190,7 +187,6 @@
@Test
public void quickUpdateHeaderPreference_onlyUpdateBatteryLevelAndChargingState() {
mSummary.setText(BATTERY_STATUS);
- mSummary2.setText(BATTERY_STATUS);
mController.quickUpdateHeaderPreference();
@@ -198,7 +194,6 @@
assertThat(mBatteryMeterView.getCharging()).isTrue();
assertThat(mBatteryPercentText.getText().toString()).isEqualTo("60 %");
assertThat(mSummary.getText()).isEqualTo(BATTERY_STATUS);
- assertThat(mSummary2.getText()).isEqualTo(BATTERY_STATUS);
}
@Test
diff --git a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
index 4d77bdd..7839e1a 100644
--- a/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
+++ b/tests/robotests/src/com/android/settings/fuelgauge/PowerUsageSummaryTest.java
@@ -265,20 +265,17 @@
}
}).when(mFeatureFactory.powerUsageFeatureProvider).getEnhancedEstimateDebugString(any());
- doReturn(new TextView(mRealContext)).when(mBatteryLayoutPref).findViewById(R.id.summary2);
doReturn(new TextView(mRealContext)).when(mBatteryLayoutPref).findViewById(R.id.summary1);
mFragment.onLongClick(new View(mRealContext));
TextView summary1 = mFragment.mBatteryLayoutPref.findViewById(R.id.summary1);
- TextView summary2 = mFragment.mBatteryLayoutPref.findViewById(R.id.summary2);
Robolectric.flushBackgroundThreadScheduler();
- assertThat(summary2.getText().toString()).contains(NEW_ML_EST_SUFFIX);
+ assertThat(summary1.getText().toString()).contains(NEW_ML_EST_SUFFIX);
assertThat(summary1.getText().toString()).contains(OLD_EST_SUFFIX);
}
@Test
public void debugMode() {
doReturn(true).when(mFeatureFactory.powerUsageFeatureProvider).isEstimateDebugEnabled();
- doReturn(new TextView(mRealContext)).when(mBatteryLayoutPref).findViewById(R.id.summary2);
mFragment.restartBatteryInfoLoader();
ArgumentCaptor<View.OnLongClickListener> listener = ArgumentCaptor.forClass(