Permalink
Browse files

Always show battery percentage when charging

- also fix a bug from upstream where battery percentage
  wouldn't show on lockscreen with battery style
  set to 'Text'

Change-Id: I3965c1d6a0828bf079cbb495b5f2601a9c0a9aa6
  • Loading branch information...
tsubus authored and xlxfoxxlx committed Nov 15, 2016
1 parent 6cad4a8 commit ec64977fe13a6871b6bd02bd9bd09b4eca6f1d74
@@ -37,6 +37,8 @@
private BatteryController mBatteryController;
private boolean mRequestedVisibility;
private boolean mForceBatteryText;
private boolean mBatteryCharging;
public BatteryLevelTextView(Context context, AttributeSet attrs) {
super(context, attrs);
@@ -45,6 +47,13 @@ public BatteryLevelTextView(Context context, AttributeSet attrs) {
@Override
public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
setText(NumberFormat.getPercentInstance().format((double) level / 100.0));
boolean changed = mBatteryCharging != charging;
mBatteryCharging = charging;
if (changed) {
mForceBatteryText = Settings.Secure.getInt(getContext().getContentResolver(),
Settings.Secure.STATUS_BAR_BATTERY_STYLE, 0) == 6 ? true : false;
setVisibility(mBatteryCharging || mRequestedVisibility || mForceBatteryText ? View.VISIBLE : View.GONE);
}
}
public void setBatteryController(BatteryController batteryController) {
@@ -74,7 +83,9 @@ public void onTuningChanged(String key, String newValue) {
switch (key) {
case STATUS_BAR_SHOW_BATTERY_PERCENT:
mRequestedVisibility = newValue != null && Integer.parseInt(newValue) == 2;
setVisibility(mRequestedVisibility ? View.VISIBLE : View.GONE);
mForceBatteryText = Settings.Secure.getInt(getContext().getContentResolver(),
Settings.Secure.STATUS_BAR_BATTERY_STYLE, 0) == 6 ? true : false;
setVisibility(mBatteryCharging || mRequestedVisibility || mForceBatteryText ? View.VISIBLE : View.GONE);
break;
case STATUS_BAR_BATTERY_STYLE:
final int value = newValue == null ?
@@ -87,7 +98,7 @@ public void onTuningChanged(String key, String newValue) {
setVisibility(View.GONE);
break;
default:
setVisibility(mRequestedVisibility ? View.VISIBLE : View.GONE);
setVisibility(mBatteryCharging || mRequestedVisibility || mForceBatteryText ? View.VISIBLE : View.GONE);
break;
}
break;
@@ -74,6 +74,7 @@
private View mSystemIconsContainer;
private boolean mShowBatteryText;
private boolean mForceBatteryText;
private ContentObserver mObserver = new ContentObserver(new Handler()) {
public void onChange(boolean selfChange, Uri uri) {
@@ -194,7 +195,7 @@ private void updateVisibilities() {
}
mBatteryLevel.setVisibility(
mBatteryCharging || mShowBatteryText ? View.VISIBLE : View.GONE);
mBatteryCharging || mShowBatteryText || mForceBatteryText ? View.VISIBLE : View.GONE);
if (mCarrierLabel != null) {
if (mShowCarrierLabel == 1) {
@@ -367,6 +368,8 @@ public boolean hasOverlappingRendering() {
public void onTuningChanged(String key, String newValue) {
if (key.equals(STATUS_BAR_SHOW_BATTERY_PERCENT)) {
mShowBatteryText = newValue == null ? false : Integer.parseInt(newValue) == 2;
mForceBatteryText = Settings.Secure.getInt(getContext().getContentResolver(),
Settings.Secure.STATUS_BAR_BATTERY_STYLE, 0) == 6 ? true : false;
updateVisibilities();
}
}

0 comments on commit ec64977

Please sign in to comment.