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

Commit a242548b authored by jackqdyulei's avatar jackqdyulei Committed by android-build-merger
Browse files

Merge "Ui changes in battery main page" into oc-dev

am: f297e843

Change-Id: I3b96043a327498f0ed935a80a24d6fffbd36c913
parents 53352cd3 f297e843
Loading
Loading
Loading
Loading
+11 −20
Original line number Diff line number Diff line
@@ -27,44 +27,35 @@
    android:background="@drawable/selectable_card_grey"
    style="@style/EntityHeader">

    <com.android.settings.fuelgauge.BatteryMeterView
        android:id="@+id/battery_header_icon"
        android:layout_width="@dimen/battery_meter_width"
        android:layout_height="@dimen/battery_meter_height"/>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_width="216dp"
        android:layout_height="wrap_content"
        android:layout_marginStart="12dp"
        android:layout_marginStart="48dp"
        android:layout_marginEnd="12dp"
        android:orientation="vertical">

        <TextView
            android:id="@+id/time"
            android:id="@+id/battery_percent"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:gravity="center"
            android:textAppearance="@android:style/TextAppearance.Material.Medium"/>
            android:textAppearance="@android:style/TextAppearance.Material.Display1"/>

        <TextView
            android:id="@+id/summary1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:gravity="center"
            android:textAppearance="@android:style/TextAppearance.Material.Small"
            android:text="@string/estimated_time_left"/>

        <TextView
            android:id="@+id/summary2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="12dp"
            android:gravity="center"
            android:textAppearance="@android:style/TextAppearance.Material.Small"
            android:text="@string/estimated_time_description"/>

    </LinearLayout>

    <com.android.settings.fuelgauge.BatteryMeterView
        android:id="@+id/battery_header_icon"
        android:layout_width="@dimen/battery_meter_width"
        android:layout_height="@dimen/battery_meter_height"
        android:layout_gravity="end"
        android:layout_marginEnd="24dp"/>

</LinearLayout>
 No newline at end of file
+13 −18
Original line number Diff line number Diff line
@@ -25,6 +25,19 @@
        android:selectable="true"
        android:layout="@layout/battery_header"/>

    <PreferenceCategory
        android:key="device_usage_list">

        <com.android.settings.fuelgauge.PowerGaugePreference
            android:key="last_full_charge"
            android:title="@string/battery_last_full_charge"/>

        <com.android.settings.fuelgauge.PowerGaugePreference
            android:key="screen_usage"
            android:title="@string/device_screen_usage"/>

    </PreferenceCategory>

    <PreferenceCategory
        android:key="power_management"
        android:title="@string/battery_power_management">
@@ -60,22 +73,4 @@
        android:key="app_list"
        android:title="@string/power_usage_list_summary"/>

    <PreferenceCategory
        android:key="device_usage_list"
        android:title="@string/device_usage_list_summary">

        <Preference
            android:key="screen_usage"
            android:title="@string/device_screen_usage"/>

        <Preference
            android:key="screen_consumption"
            android:title="@string/device_screen_consumption"/>

        <Preference
            android:key="cellular_network"
            android:title="@string/device_cellular_network"/>

    </PreferenceCategory>

</PreferenceScreen>
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public class BatteryMeterView extends ImageView {

        mDrawable = new BatteryMeterDrawable(context, frameColor);
        mDrawable.setColorFilter(new PorterDuffColorFilter(tintColor, PorterDuff.Mode.SRC_IN));
        mDrawable.setShowPercent(true);
        mDrawable.setShowPercent(false);
        setImageDrawable(mDrawable);
    }

+23 −6
Original line number Diff line number Diff line
@@ -29,8 +29,11 @@ import com.android.settings.TintablePreference;
import com.android.settings.Utils;

/**
 * Custom preference for displaying power consumption as a bar and an icon on
 * Custom preference for displaying battery usage info as a bar and an icon on
 * the left for the subsystem/app type.
 *
 * The battery usage info could be usage percentage or usage time. The preference
 * won't show any icon if it is null.
 */
public class PowerGaugePreference extends TintablePreference {
    private final int mIconSize;
@@ -41,7 +44,20 @@ public class PowerGaugePreference extends TintablePreference {

    public PowerGaugePreference(Context context, Drawable icon, CharSequence contentDescription,
            BatteryEntry info) {
        super(context, null);
        this(context, null, icon, contentDescription, info);
    }

    public PowerGaugePreference(Context context) {
        this(context, null, null, null, null);
    }

    public PowerGaugePreference(Context context, AttributeSet attrs) {
        this(context, attrs, null, null, null);
    }

    private PowerGaugePreference(Context context, AttributeSet attrs, Drawable icon,
            CharSequence contentDescription, BatteryEntry info) {
        super(context, attrs);
        setIcon(icon != null ? icon : new ColorDrawable(0));
        setWidgetLayoutResource(R.layout.preference_widget_summary);
        mInfo = info;
@@ -49,10 +65,6 @@ public class PowerGaugePreference extends TintablePreference {
        mIconSize = context.getResources().getDimensionPixelSize(R.dimen.app_icon_size);
    }

    public PowerGaugePreference(Context context) {
        this(context, null, null, null);
    }

    public void setContentDescription(String name) {
        mContentDescription = name;
        notifyChanged();
@@ -67,6 +79,11 @@ public class PowerGaugePreference extends TintablePreference {
        return mProgress.toString();
    }

    public void setSubtitle(String subtitle) {
        mProgress = subtitle;
        notifyChanged();
    }

    BatteryEntry getInfo() {
        return mInfo;
    }
+35 −39
Original line number Diff line number Diff line
@@ -16,7 +16,6 @@

package com.android.settings.fuelgauge;

import android.annotation.StringRes;
import android.app.Activity;
import android.content.Context;
import android.graphics.drawable.Drawable;
@@ -26,6 +25,7 @@ import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.os.Process;
import android.os.SystemClock;
import android.os.UserHandle;
import android.provider.SearchIndexableResource;
import android.support.annotation.VisibleForTesting;
@@ -39,7 +39,6 @@ import android.util.TypedValue;
import android.view.Menu;
import android.view.MenuInflater;
import android.view.MenuItem;
import android.view.View;
import android.widget.TextView;

import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
@@ -60,6 +59,7 @@ import com.android.settings.display.BatteryPercentagePreferenceController;
import com.android.settings.display.TimeoutPreferenceController;
import com.android.settings.overlay.FeatureFactory;
import com.android.settings.search.BaseSearchIndexProvider;
import com.android.settings.widget.FooterPreferenceMixin;
import com.android.settingslib.BatteryInfo;

import java.util.ArrayList;
@@ -87,8 +87,7 @@ public class PowerUsageSummary extends PowerUsageBase {
    private static final int SECONDS_IN_HOUR = 60 * 60;

    private static final String KEY_SCREEN_USAGE = "screen_usage";
    private static final String KEY_SCREEN_CONSUMPTION = "screen_consumption";
    private static final String KEY_CELLULAR_NETWORK = "cellular_network";
    private static final String KEY_TIME_SINCE_LAST_FULL_CHARGE = "last_full_charge";


    private static final int MENU_STATS_TYPE = Menu.FIRST;
@@ -100,14 +99,15 @@ public class PowerUsageSummary extends PowerUsageBase {
    static final int MENU_TOGGLE_APPS = Menu.FIRST + 5;
    private static final int MENU_HELP = Menu.FIRST + 6;

    private final FooterPreferenceMixin mFooterPreferenceMixin =
            new FooterPreferenceMixin(this, getLifecycle());

    @VisibleForTesting
    boolean mShowAllApps = false;
    @VisibleForTesting
    Preference mScreenUsagePref;
    @VisibleForTesting
    Preference mScreenConsumptionPref;
    PowerGaugePreference mScreenUsagePref;
    @VisibleForTesting
    Preference mCellularNetworkPref;
    PowerGaugePreference mLastFullChargePref;
    @VisibleForTesting
    PowerUsageFeatureProvider mPowerFeatureProvider;

@@ -122,9 +122,10 @@ public class PowerUsageSummary extends PowerUsageBase {

        mBatteryLayoutPref = (LayoutPreference) findPreference(KEY_BATTERY_HEADER);
        mAppListGroup = (PreferenceGroup) findPreference(KEY_APP_LIST);
        mScreenUsagePref = findPreference(KEY_SCREEN_USAGE);
        mScreenConsumptionPref = findPreference(KEY_SCREEN_CONSUMPTION);
        mCellularNetworkPref = findPreference(KEY_CELLULAR_NETWORK);
        mScreenUsagePref = (PowerGaugePreference) findPreference(KEY_SCREEN_USAGE);
        mLastFullChargePref = (PowerGaugePreference) findPreference(
                KEY_TIME_SINCE_LAST_FULL_CHARGE);
        mFooterPreferenceMixin.createFooterPreference().setTitle(R.string.battery_footer_summary);

        initFeatureProvider();
    }
@@ -417,8 +418,11 @@ public class PowerUsageSummary extends PowerUsageBase {
        final int dischargeAmount = USE_FAKE_DATA ? 5000
                : stats != null ? stats.getDischargeAmount(mStatsType) : 0;

        updateScreenPreference(dischargeAmount);
        updateCellularPreference(dischargeAmount);
        final long runningTime = calculateRunningTimeBasedOnStatsType();
        updateScreenPreference();
        updateLastFullChargePreference(runningTime);
        mAppListGroup.setTitle(getString(R.string.power_usage_list_summary,
                Utils.formatElapsedTime(context, runningTime, false)));

        if (averagePower >= MIN_AVERAGE_POWER_THRESHOLD_MILLI_AMP || USE_FAKE_DATA) {
            final List<BatterySipper> usageList = getCoalescedUsageList(
@@ -527,28 +531,27 @@ public class PowerUsageSummary extends PowerUsageBase {
    }

    @VisibleForTesting
    void updateScreenPreference(final int dischargeAmount) {
    void updateScreenPreference() {
        final BatterySipper sipper = findBatterySipperByType(
                mStatsHelper.getUsageList(), DrainType.SCREEN);
        final Context context = getContext();
        final double totalPowerMah = sipper != null ? sipper.totalPowerMah : 0;
        final long usageTimeMs = sipper != null ? sipper.usageTimeMs : 0;
        final double percentOfTotal = calculatePercentage(totalPowerMah, dischargeAmount);

        mScreenUsagePref.setSummary(getString(R.string.battery_used_for,
                Utils.formatElapsedTime(context, usageTimeMs, false)));
        mScreenConsumptionPref.setSummary(getString(R.string.battery_overall_usage,
                Utils.formatPercentage(percentOfTotal, true)));
        mScreenUsagePref.setSubtitle(Utils.formatElapsedTime(context, usageTimeMs, false));
    }

    @VisibleForTesting
    void updateCellularPreference(final int dischargeAmount) {
        final BatterySipper sipper = findBatterySipperByType(
                mStatsHelper.getUsageList(), DrainType.CELL);
        final double totalPowerMah = sipper != null ? sipper.totalPowerMah : 0;
        final double percentOfTotal = calculatePercentage(totalPowerMah, dischargeAmount);
        mCellularNetworkPref.setSummary(getString(R.string.battery_overall_usage,
                Utils.formatPercentage(percentOfTotal, true)));
    void updateLastFullChargePreference(long timeMs) {
        mLastFullChargePref.setSubtitle(getString(R.string.power_last_full_charge_summary,
                Utils.formatElapsedTime(getContext(), timeMs, false)));
    }

    @VisibleForTesting
    long calculateRunningTimeBasedOnStatsType() {
        final long elapsedRealtimeUs = SystemClock.elapsedRealtime() * 1000;
        // Return the battery time (millisecond) on status mStatsType
        return mStatsHelper.getStats().computeBatteryRealtime(elapsedRealtimeUs,
                mStatsType /* STATS_SINCE_CHARGED */) / 1000;
    }

    @VisibleForTesting
@@ -559,22 +562,15 @@ public class PowerUsageSummary extends PowerUsageBase {
        }
        final BatteryMeterView batteryView = (BatteryMeterView) mBatteryLayoutPref
                .findViewById(R.id.battery_header_icon);
        final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.time);
        final TextView timeText = (TextView) mBatteryLayoutPref.findViewById(R.id.battery_percent);
        final TextView summary1 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary1);
        final TextView summary2 = (TextView) mBatteryLayoutPref.findViewById(R.id.summary2);
        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(context, info.remainingTimeUs / 1000, false));
        timeText.setText(Utils.formatPercentage(info.mBatteryLevel));
        if (info.remainingLabel == null ) {
            summary1.setText(info.statusLabel);
        } else {
            timeText.setText(info.statusLabel);
            summary1.setText(info.remainingLabel);
        }

        summary1.setText(summaryResId);
        summary1.setVisibility(visible);
        summary2.setVisibility(visible);
        batteryView.setBatteryInfo(info.mBatteryLevel);
    }

Loading