From 09d3436c4fc70a201e60f2b624a543a4c67abe1a Mon Sep 17 00:00:00 2001 From: Ezio Lacandia Bijelkic Date: Tue, 29 Nov 2016 08:00:41 -0500 Subject: [PATCH] Battery: allow set a custom symbol near text pct on charging [1/2] default (disabled) flash tilde PS2 - OCD things Change-Id: Ibadd63f2b5b1369a02984381ba7a2a2ca37c0dbb --- core/java/android/provider/Settings.java | 30 ++++++++++------ .../systemui/BatteryLevelTextView.java | 34 +++++++++++++++++-- 2 files changed, 52 insertions(+), 12 deletions(-) diff --git a/core/java/android/provider/Settings.java b/core/java/android/provider/Settings.java index 1145a5236309..512733290e16 100644 --- a/core/java/android/provider/Settings.java +++ b/core/java/android/provider/Settings.java @@ -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 diff --git a/packages/SystemUI/src/com/android/systemui/BatteryLevelTextView.java b/packages/SystemUI/src/com/android/systemui/BatteryLevelTextView.java index eedd732c2b1c..88e6554e021d 100644 --- a/packages/SystemUI/src/com/android/systemui/BatteryLevelTextView.java +++ b/packages/SystemUI/src/com/android/systemui/BatteryLevelTextView.java @@ -35,6 +35,8 @@ 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; @@ -42,6 +44,9 @@ public class BatteryLevelTextView extends TextView implements 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); @@ -49,7 +54,9 @@ public BatteryLevelTextView(Context context, AttributeSet 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)); + } + } }