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

Commit bee63924 authored by Danesh Mondegarian's avatar Danesh Mondegarian Committed by Matt Garnes
Browse files

SYstemUI : Make battery percentage configurable

Change-Id: Ibfc0cf9c5a4efc13ecd3c3e99723bb2b717c50a7
parent 312e5007
Loading
Loading
Loading
Loading
+15 −2
Original line number Diff line number Diff line
@@ -22,17 +22,20 @@ import android.content.Intent;
import android.content.IntentFilter;
import android.content.res.Resources;
import android.content.res.TypedArray;
import android.database.ContentObserver;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Path;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.net.Uri;
import android.os.BatteryManager;
import android.os.Bundle;
import android.os.Handler;
import android.provider.Settings;
import android.util.AttributeSet;
import android.view.View;
import android.content.ContentResolver;

import com.android.systemui.statusbar.policy.BatteryController;

@@ -162,6 +165,14 @@ public class BatteryMeterView extends View implements DemoMode,
        }
    };

    private ContentObserver mObserver = new ContentObserver(new Handler()) {
        public void onChange(boolean selfChange, Uri uri) {
            mShowPercent = ENABLE_PERCENT && 0 != Settings.System.getInt(
                getContext().getContentResolver(), "status_bar_show_battery_percent", 0);
            postInvalidate();
        }
    };

    @Override
    public void onAttachedToWindow() {
        super.onAttachedToWindow();
@@ -175,6 +186,8 @@ public class BatteryMeterView extends View implements DemoMode,
            mTracker.onReceive(getContext(), sticky);
        }
        mBatteryController.addStateChangedCallback(this);
       getContext().getContentResolver().registerContentObserver(Settings.System.getUriFor(
           "status_bar_show_battery_percent"), false, mObserver);
    }

    @Override
@@ -438,8 +451,8 @@ public class BatteryMeterView extends View implements DemoMode,
        boolean pctOpaque = false;
        float pctX = 0, pctY = 0;
        String pctText = null;
        if (!tracker.plugged && level > mCriticalLevel && mShowPercent
                && !(tracker.level == 100 && !SHOW_100_PERCENT)) {
        if (!tracker.plugged && level > mCriticalLevel && (mShowPercent
                || !(tracker.level == 100 && !SHOW_100_PERCENT))) {
            mTextPaint.setColor(getColorForLevel(level));
            mTextPaint.setTextSize(height *
                    (SINGLE_DIGIT_PERCENT ? 0.75f