Permalink
Browse files

Battery: allow set a custom symbol near text pct on charging [1/2]

default (disabled)
flash
tilde

PS2 - OCD things

Change-Id: Ibadd63f2b5b1369a02984381ba7a2a2ca37c0dbb
  • Loading branch information...
ezio84 authored and xlxfoxxlx committed Nov 29, 2016
1 parent 739f8aa commit 09d3436c4fc70a201e60f2b624a543a4c67abe1a
@@ -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
@@ -35,21 +35,28 @@
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) {
@@ -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
@@ -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.