Navigation Menu

Skip to content

Commit

Permalink
Battery: allow set a custom symbol near text pct on charging [1/2]
Browse files Browse the repository at this point in the history
default (disabled)
flash
tilde

PS2 - OCD things

Change-Id: Ibadd63f2b5b1369a02984381ba7a2a2ca37c0dbb
  • Loading branch information
ezio84 authored and xlxfoxxlx committed Jun 15, 2017
1 parent 739f8aa commit 09d3436
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 12 deletions.
30 changes: 20 additions & 10 deletions core/java/android/provider/Settings.java
Expand Up @@ -7343,18 +7343,28 @@ public static boolean putFloatForUser(ContentResolver cr, String name, float val
public static final String STATUS_BAR_BATTERY_STYLE_TILE = "status_bar_battery_style_tile";

/**
* battery icon color when charging
*
* @hide
*/
public static final String STATUS_BAR_CHARGE_COLOR = "status_bar_charge_color";
* Battery icon color while charging
*
* @hide
*/
public static final String STATUS_BAR_CHARGE_COLOR = "status_bar_charge_color";

/**
* Whether to force percentage text out of the battery icon when charging
*
* @hide
*/
public static final String FORCE_CHARGE_BATTERY_TEXT = "force_charge_battery_text";
* Whether to force percentage text out of the battery icon while charging
*
* @hide
*/
public static final String FORCE_CHARGE_BATTERY_TEXT = "force_charge_battery_text";

/**
* Charging symbol near battery text percentage
* 0: no symbol
* 1: flash symbol
* 2: tilde symbol
* default: 0
* @hide
*/
public static final String TEXT_CHARGING_SYMBOL = "text_charging_symbol";

/**
* Whether the camera double twist gesture to flip between front and back mode should be
Expand Down
Expand Up @@ -35,21 +35,28 @@ public class BatteryLevelTextView extends TextView implements
Settings.Secure.STATUS_BAR_BATTERY_STYLE;
private static final String FORCE_CHARGE_BATTERY_TEXT =
Settings.Secure.FORCE_CHARGE_BATTERY_TEXT;
private static final String TEXT_CHARGING_SYMBOL =
Settings.Secure.TEXT_CHARGING_SYMBOL;

private BatteryController mBatteryController;

private boolean mRequestedVisibility;
private boolean mForceBatteryText;
private boolean mForceChargeBatteryText;
private boolean mBatteryCharging;
private int mTextChargingSymbol;
private int currentLevel;
private boolean isPlugged;

public BatteryLevelTextView(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public void onBatteryLevelChanged(int level, boolean pluggedIn, boolean charging) {
setText(NumberFormat.getPercentInstance().format((double) level / 100.0));
currentLevel = level;
isPlugged = pluggedIn;
updateChargingSymbol(currentLevel, isPlugged);
boolean changed = mBatteryCharging != charging;
mBatteryCharging = charging;
if (changed) {
Expand All @@ -65,7 +72,7 @@ public void setBatteryController(BatteryController batteryController) {
mBatteryController = batteryController;
mBatteryController.addStateChangedCallback(this);
TunerService.get(getContext()).addTunable(this,
STATUS_BAR_SHOW_BATTERY_PERCENT, STATUS_BAR_BATTERY_STYLE, FORCE_CHARGE_BATTERY_TEXT);
STATUS_BAR_SHOW_BATTERY_PERCENT, STATUS_BAR_BATTERY_STYLE, FORCE_CHARGE_BATTERY_TEXT, TEXT_CHARGING_SYMBOL);
}

@Override
Expand Down Expand Up @@ -118,8 +125,31 @@ public void onTuningChanged(String key, String newValue) {
FORCE_CHARGE_BATTERY_TEXT, 1) == 1 ? true : false;
setVisibility((mBatteryCharging && mForceChargeBatteryText) || mRequestedVisibility || mForceBatteryText ? View.VISIBLE : View.GONE);
break;
case TEXT_CHARGING_SYMBOL:
updateChargingSymbol(currentLevel, isPlugged);
break;
default:
break;
}
}

private void updateChargingSymbol(int level, boolean pluggedIn) {
mTextChargingSymbol = Settings.Secure.getInt(getContext().getContentResolver(),
TEXT_CHARGING_SYMBOL, 0);
if (pluggedIn) {
switch (mTextChargingSymbol) {
case 1:
setText("⚡️" + NumberFormat.getPercentInstance().format((double) level / 100.0));
break;
case 2:
setText("~" + NumberFormat.getPercentInstance().format((double) level / 100.0));
break;
default:
setText(NumberFormat.getPercentInstance().format((double) level / 100.0));
break;
}
} else {
setText(NumberFormat.getPercentInstance().format((double) level / 100.0));
}
}
}

0 comments on commit 09d3436

Please sign in to comment.