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

Commit 154ad690 authored by Simon Davie's avatar Simon Davie
Browse files

(1/2) Add status bar battery icon configuration.

Many people resort to editing the compiled frameworks to remove the
battery icon on the status bar. This patch set adds an new option in
CMParts to select between the stock icon, the CyanogenMod percentage
meter, or no battery status at all.

By default the stock battery icon is shown.

Part 2/2: I2cb73df37a4857288dae6ffabb8652c37d76a8ca

Change-Id: Ie73690cfa465f0299f8904cb4f3690898614eb71
parent cba1d1e6
Loading
Loading
Loading
Loading
+5 −5
Original line number Diff line number Diff line
@@ -2255,14 +2255,14 @@ public final class Settings {
        public static final String STATUS_BAR_AM_PM = "status_bar_am_pm";

        /**
         * Whether to show the CM battery percentage implementation instead
         * of the stock battery icon
         * 0: don't show / show stock icon instead
         * 1: show cm battery / dont show stock icon
         * Display style of the status bar battery information
         * 0: Display the stock battery information
         * 1: Display cm battery percentage implementation / dont show stock icon
         * 2: Hide the battery information
         * default: 0
         * @hide
         */
        public static final String STATUS_BAR_CM_BATTERY = "status_bar_cm_battery";
        public static final String STATUS_BAR_BATTERY = "status_bar_battery";

        /**
         * Whether to show the clock in status bar
+11 −8
Original line number Diff line number Diff line
@@ -64,8 +64,9 @@ public class CmBatteryMiniIcon extends ImageView {
    // recalculation of BATTERY_MINI_ICON_MARGIN_RIGHT_DIP to pixels
    private int mMarginRightPx;

    // weather to show this battery widget or not
    private boolean mShowCmBattery = false;
    // battery style preferences
    private static final int BATTERY_STYLE_PERCENT   = 1;
    private int mStatusBarBattery;

    // used for animation and still values when not charging/fully charged
    private int mCurrentFrame = 0;
@@ -92,7 +93,7 @@ public class CmBatteryMiniIcon extends ImageView {
        void observe() {
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(
                    Settings.System.getUriFor(Settings.System.STATUS_BAR_CM_BATTERY), false, this);
                    Settings.System.getUriFor(Settings.System.STATUS_BAR_BATTERY), false, this);
        }

        @Override
@@ -218,7 +219,7 @@ public class CmBatteryMiniIcon extends ImageView {
    protected void onDraw(Canvas canvas) {
        super.onDraw(canvas);

        if (!mAttached || !mShowCmBattery)
        if (!mAttached || mStatusBarBattery != BATTERY_STYLE_PERCENT)
            return;

        canvas.drawBitmap(mMiniIconCache[mCurrentFrame], mMatrix, mPaint);
@@ -270,14 +271,16 @@ public class CmBatteryMiniIcon extends ImageView {
    private void updateSettings() {
        ContentResolver resolver = mContext.getContentResolver();

        mShowCmBattery = (Settings.System
                .getInt(resolver, Settings.System.STATUS_BAR_CM_BATTERY, 0) == 1);
        int statusBarBattery = (Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_BATTERY, 2));
        mStatusBarBattery = Integer.valueOf(statusBarBattery);

        if (mShowCmBattery)
        if (mStatusBarBattery == BATTERY_STYLE_PERCENT) {
            setVisibility(View.VISIBLE);
        else
        } else {
            setVisibility(View.GONE);
        }
    }

    // should be toggled to private (or inlined at constructor), once StatusBarService.updateResources properly handles theme change
    public void updateIconCache() {
+10 −7
Original line number Diff line number Diff line
@@ -34,8 +34,9 @@ import android.widget.TextView;
public class CmBatteryText extends TextView {
    private boolean mAttached;

    // weather to show this battery widget or not
    private boolean mShowCmBattery;
    // battery style preferences
    private static final int BATTERY_STYLE_PERCENT   = 1;
    private int mStatusBarBattery;

    Handler mHandler;

@@ -49,7 +50,7 @@ public class CmBatteryText extends TextView {
        void observe() {
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(
                    Settings.System.getUriFor(Settings.System.STATUS_BAR_CM_BATTERY), false, this);
                    Settings.System.getUriFor(Settings.System.STATUS_BAR_BATTERY), false, this);
        }

        @Override
@@ -129,12 +130,14 @@ public class CmBatteryText extends TextView {
    private void updateSettings() {
        ContentResolver resolver = mContext.getContentResolver();

        mShowCmBattery = (Settings.System
                .getInt(resolver, Settings.System.STATUS_BAR_CM_BATTERY, 0) == 1);
        int statusBarBattery = (Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_BATTERY, 2));
        mStatusBarBattery = Integer.valueOf(statusBarBattery);

        if (mShowCmBattery)
        if (mStatusBarBattery == BATTERY_STYLE_PERCENT) {
            setVisibility(View.VISIBLE);
        else
        } else {
            setVisibility(View.GONE);
        }
    }
}
+22 −11
Original line number Diff line number Diff line
@@ -85,6 +85,10 @@ public class StatusBarPolicy {

    private static int AM_PM_STYLE = AM_PM_STYLE_GONE;

    private static final int BATTERY_STYLE_NORMAL    = 0;
    private static final int BATTERY_STYLE_PERCENT   = 1;
    private static final int BATTERY_STYLE_GONE      = 2;

    private static final int INET_CONDITION_THRESHOLD = 50;

    private final Context mContext;
@@ -602,8 +606,7 @@ public class StatusBarPolicy {
        }
    };

    private boolean mShowCmBattery;
    private boolean mCmBatteryStatus;
    private int mStatusBarBattery;
    // need another var that superceding mPhoneSignalHidden
    private boolean mShowCmSignal;

@@ -617,7 +620,7 @@ public class StatusBarPolicy {
        void observe() {
            ContentResolver resolver = mContext.getContentResolver();
            resolver.registerContentObserver(Settings.System.getUriFor(
                    Settings.System.STATUS_BAR_CM_BATTERY), false, this);
                    Settings.System.STATUS_BAR_BATTERY), false, this);

            resolver.registerContentObserver(Settings.System
                    .getUriFor(Settings.System.STATUS_BAR_CM_SIGNAL_TEXT), false, this);
@@ -805,10 +808,13 @@ public class StatusBarPolicy {
    private final void updateBattery(Intent intent) {
        final int id = intent.getIntExtra("icon-small", 0);
        int level = intent.getIntExtra("level", 0);
        if(!mShowCmBattery || mCmBatteryStatus != mShowCmBattery) {
        mService.setIcon("battery", id, level);
                mService.setIconVisibility("battery", !mShowCmBattery);
                mCmBatteryStatus = mShowCmBattery;
        if(mStatusBarBattery == BATTERY_STYLE_NORMAL) {
                mService.setIconVisibility("battery", true);
        } else if (mStatusBarBattery == BATTERY_STYLE_PERCENT) {
                mService.setIconVisibility("battery", false);
        } else if (mStatusBarBattery == BATTERY_STYLE_GONE) {
                mService.setIconVisibility("battery", false);
        }

        boolean plugged = intent.getIntExtra("plugged", 0) != 0;
@@ -1645,10 +1651,15 @@ public class StatusBarPolicy {
    private void updateSettings(){
        ContentResolver resolver = mContext.getContentResolver();

        mShowCmBattery = (Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_CM_BATTERY, 0) == 1);
        mCmBatteryStatus = !mShowCmBattery;
        mService.setIconVisibility("battery", !mShowCmBattery);
        int statusBarBattery = Settings.System.getInt(resolver,
                Settings.System.STATUS_BAR_BATTERY, 0);
        mStatusBarBattery = Integer.valueOf(statusBarBattery);

        if (mStatusBarBattery == BATTERY_STYLE_NORMAL) {
                mService.setIconVisibility("battery", true);
        } else if (mStatusBarBattery == BATTERY_STYLE_PERCENT || mStatusBarBattery == BATTERY_STYLE_GONE) {
                mService.setIconVisibility("battery", false);
        }

        //0 will hide the cmsignaltext and show the signal bars
        mShowCmSignal = Settings.System.getInt(mContext.getContentResolver(),