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

Commit 9203171b authored by Michael Bestas's avatar Michael Bestas Committed by Steve Kondik
Browse files

Cleanup battery style code

* Cleanup commented out code
* Fix landscape battery icon padding
* Fix landscape battery icon charging indicator
* Fix landscape battery icon percentage indicator
* Fix circle battery frame color on some black backgrounds
* Fix circle battery artifact on low percentage
* Fix percentage not shown while charging
* Fix percentage always showing on expanded status bar
* Fix battery icon showing after reboot on text/hidden modes

Change-Id: Ic56878c26e9a3416149eaaa8a9325d56d664e22e
parent 30a9dbe6
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -60,7 +60,8 @@
            android:paddingEnd="@dimen/battery_level_padding_end"
            android:textColor="#ffffff"
            android:visibility="gone"
            android:textSize="12sp"/>
            android:textSize="@dimen/battery_level_text_size"
            android:importantForAccessibility="noHideDescendants"/>
    </LinearLayout>

    <com.android.keyguard.CarrierText
+0 −1
Original line number Diff line number Diff line
@@ -93,7 +93,6 @@
                android:layout_gravity="center_vertical"
                android:layout_marginStart="@dimen/header_battery_margin_keyguard"
                android:textColor="#ffffff"
                android:visibility="gone"
                android:textSize="@dimen/battery_level_text_size" />

            <com.android.systemui.statusbar.policy.Clock
+0 −1
Original line number Diff line number Diff line
@@ -91,7 +91,6 @@
                android:layout_gravity="center_vertical"
                android:layout_marginStart="@dimen/header_battery_margin_keyguard"
                android:textColor="#ffffff"
                android:visibility="gone"
                android:textSize="@dimen/battery_level_text_size" />

            <com.android.systemui.statusbar.policy.Clock
+1 −1
Original line number Diff line number Diff line
@@ -77,7 +77,7 @@
            >
            <include layout="@layout/system_icons" />
        </FrameLayout>
        <TextView android:id="@+id/battery_level"
        <com.android.systemui.BatteryLevelTextView android:id="@+id/battery_level_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_vertical"
+73 −50
Original line number Diff line number Diff line
@@ -19,11 +19,13 @@ package com.android.systemui;
import android.app.ActivityManager;
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Configuration;
import android.database.ContentObserver;
import android.net.Uri;
import android.os.Handler;
import android.provider.Settings;
import android.util.AttributeSet;
import android.util.TypedValue;
import android.view.View;
import android.widget.TextView;
import com.android.systemui.statusbar.policy.BatteryController;
@@ -35,78 +37,59 @@ public class BatteryLevelTextView extends TextView implements
    private static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";

    private BatteryController mBatteryController;
    private boolean mBatteryCharging;
    private boolean mShow;
    private boolean mForceShow;
    private boolean mAttached;
    private int mRequestedVisibility;

    private ContentObserver mObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange, Uri uri) {
            loadShowBatteryTextSetting();
            setVisibility(mShow ? View.VISIBLE : View.GONE);
        }
    };

    public BatteryLevelTextView(Context context, AttributeSet attrs) {
        super(context, attrs);
        mRequestedVisibility = getVisibility();
        loadShowBatteryTextSetting();
        setVisibility(mShow ? View.VISIBLE : View.GONE);
    }

    private void loadShowBatteryTextSetting() {
        //mShow = 2 == Settings.System.getInt(getContext().getContentResolver(),
        //        Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);

        ContentResolver resolver = getContext().getContentResolver();
        int currentUserId = ActivityManager.getCurrentUser();

        boolean showInsidePercent = Settings.System.getIntForUser(resolver,
                Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, currentUserId) == 1;

        boolean showNextPercent = Settings.System.getIntForUser(resolver,
                Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, currentUserId) == 2;

        int batteryStyle = Settings.System.getIntForUser(resolver,
                Settings.System.STATUS_BAR_BATTERY_STYLE, 0, currentUserId);
        switch (batteryStyle) {
            case 2:
                //meterMode = BatteryMeterMode.BATTERY_METER_CIRCLE;
                showNextPercent = showNextPercent;
                break;

            case 4:
                //meterMode = BatteryMeterMode.BATTERY_METER_GONE;
                showNextPercent = false;
                break;

            case 5:
                //meterMode = BatteryMeterMode.BATTERY_METER_ICON_LANDSCAPE;
                showNextPercent = showNextPercent;
                break;

            case 6:
                //meterMode = BatteryMeterMode.BATTERY_METER_TEXT;
                showNextPercent = true;
                break;

            default:
                break;
    public void setForceShown(boolean forceShow) {
        mForceShow = forceShow;
        updateVisibility();
    }

        setShowPercent(showNextPercent);
    public void setBatteryController(BatteryController batteryController) {
        mBatteryController = batteryController;
        if (mAttached) {
            mBatteryController.addStateChangedCallback(this);
        }
    }

    @Override
    public void setVisibility(int visibility) {
        mRequestedVisibility = visibility;
        updateVisibility();
    }

    public void setShowPercent(boolean show) {
        mShow = show;
        setVisibility(mShow ? View.VISIBLE : View.GONE);
    @Override
    protected void onConfigurationChanged(Configuration newConfig) {
        super.onConfigurationChanged(newConfig);

        // Respect font size setting.
        setTextSize(TypedValue.COMPLEX_UNIT_PX,
                getResources().getDimensionPixelSize(R.dimen.battery_level_text_size));
     }

    @Override
    public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
        setText(getResources().getString(R.string.battery_level_template, level));
        boolean changed = mBatteryCharging != charging;
        mBatteryCharging = charging;
        if (changed) {
            loadShowBatteryTextSetting();
        }

    public void setBatteryController(BatteryController batteryController) {
        mBatteryController = batteryController;
        mBatteryController.addStateChangedCallback(this);
    }

    @Override
@@ -117,18 +100,58 @@ public class BatteryLevelTextView extends TextView implements
    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();

        if (mBatteryController != null) {
            mBatteryController.addStateChangedCallback(this);
        }
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                STATUS_BAR_BATTERY_STYLE), false, mObserver);
        getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
                STATUS_BAR_SHOW_BATTERY_PERCENT), false, mObserver);
        mAttached = true;
    }

    @Override
    public void onDetachedFromWindow() {
        super.onDetachedFromWindow();
        mAttached = false;
        getContext().getContentResolver().unregisterContentObserver(mObserver);

        if (mBatteryController != null) {
            mBatteryController.removeStateChangedCallback(this);
        }
    }

    private void updateVisibility() {
        if (mShow || mForceShow) {
            super.setVisibility(mRequestedVisibility);
        } else {
            super.setVisibility(GONE);
        }
    }

    private void loadShowBatteryTextSetting() {
        ContentResolver resolver = getContext().getContentResolver();
        int currentUserId = ActivityManager.getCurrentUser();
        int mode = Settings.System.getIntForUser(resolver,
                Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0, currentUserId);

        boolean showNextPercent = (mBatteryCharging && mode == 1) || mode == 2;
        int batteryStyle = Settings.System.getIntForUser(resolver,
                Settings.System.STATUS_BAR_BATTERY_STYLE, 0, currentUserId);

        switch (batteryStyle) {
            case 4: //BATTERY_METER_GONE
                showNextPercent = false;
                break;
            case 6: //BATTERY_METER_TEXT
                showNextPercent = true;
                break;
            default:
                break;
        }

        mShow = showNextPercent;
        updateVisibility();
    }
}
Loading