Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 6a3433b6 authored by Raff Tsai's avatar Raff Tsai Committed by Tsung-Mao Fang
Browse files

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
(cherry picked from commit 648ada03)
Merged-In: I167ac87c9bd83035e00d4991961599e76f4f69e1
parent ff9bcdbc
Loading
Loading
Loading
Loading
+1 −7
Original line number Diff line number Diff line
@@ -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
+0 −6
Original line number Diff line number Diff line
@@ -55,8 +55,6 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
    TextView mBatteryPercentText;
    @VisibleForTesting
    TextView mSummary1;
    @VisibleForTesting
    TextView mSummary2;

    private Activity mActivity;
    private PreferenceFragmentCompat mHost;
@@ -90,7 +88,6 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
                .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 @@ public class BatteryHeaderPreferenceController extends BasePreferenceController
        } 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);
+5 −9
Original line number Diff line number Diff line
@@ -19,7 +19,6 @@ package com.android.settings.fuelgauge;
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;
@@ -27,7 +26,6 @@ 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;
@@ -162,7 +160,6 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
        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));
@@ -170,14 +167,13 @@ public class PowerUsageSummary extends PowerUsageBase implements OnLongClickList
        // 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);
+0 −5
Original line number Diff line number Diff line
@@ -85,7 +85,6 @@ public class BatteryHeaderPreferenceControllerTest {
    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 @@ public class BatteryHeaderPreferenceControllerTest {
        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 @@ public class BatteryHeaderPreferenceControllerTest {
        mController.mBatteryMeterView = mBatteryMeterView;
        mController.mBatteryPercentText = mBatteryPercentText;
        mController.mSummary1 = mSummary;
        mController.mSummary2 = mSummary2;
    }

    @After
@@ -190,7 +187,6 @@ public class BatteryHeaderPreferenceControllerTest {
    @Test
    public void quickUpdateHeaderPreference_onlyUpdateBatteryLevelAndChargingState() {
        mSummary.setText(BATTERY_STATUS);
        mSummary2.setText(BATTERY_STATUS);

        mController.quickUpdateHeaderPreference();

@@ -198,7 +194,6 @@ public class BatteryHeaderPreferenceControllerTest {
        assertThat(mBatteryMeterView.getCharging()).isTrue();
        assertThat(mBatteryPercentText.getText().toString()).isEqualTo("60 %");
        assertThat(mSummary.getText()).isEqualTo(BATTERY_STATUS);
        assertThat(mSummary2.getText()).isEqualTo(BATTERY_STATUS);
    }

    @Test
+1 −4
Original line number Diff line number Diff line
@@ -265,20 +265,17 @@ public class PowerUsageSummaryTest {
            }
        }).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(