Permalink
Browse files

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

Change-Id: Ibc7aca0295f5089995e5cc8b98c71751f73775b1
  • Loading branch information...
ezio84 authored and xlxfoxxlx committed Nov 29, 2016
1 parent cd0e99f commit e5d7c3df1824a9074009deaa54a20a98aa71959d
View
@@ -637,5 +637,17 @@ limitations under the License.
<item>1200000</item>
</string-array>
<string-array name="text_charging_symbol_entries" translatable="false">
<item>@string/text_charging_symbol_default</item>
<item>@string/text_charging_symbol_flash</item>
<item>@string/text_charging_symbol_tilde</item>
</string-array>
<string-array name="text_charging_symbol_values" translatable="false">
<item>0</item>
<item>1</item>
<item>2</item>
</string-array>
</resources>
View
@@ -178,6 +178,11 @@
<string name="force_charge_battery_text_title">Statusbar battery charging percent</string>
<string name="force_charge_battery_text_summary_on">Show the battery percentage outside the icon while charging</string>
<string name="force_charge_battery_text_summary_off">Show the battery percentage inside the icon while charging</string>
<string name="text_charging_symbol_title">Charging symbol near percentage text</string>
<string name="text_charging_symbol_dialog">Show a symbol near percentage text outside the battery icon when charging</string>
<string name="text_charging_symbol_default">Disabled</string>
<string name="text_charging_symbol_flash">Flash</string>
<string name="text_charging_symbol_tilde">Tilde</string>
<!--Custom logos-->
<string name="sb_custom_logos">Custom Icons</string>
View
@@ -53,10 +53,20 @@
android:summaryOff="@string/force_charge_battery_text_summary_off"
android:defaultValue="true" />
<ListPreference
android:key="text_charging_symbol"
android:title="@string/text_charging_symbol_title"
android:summary="%s"
android:dialogTitle="@string/text_charging_symbol_dialog"
android:entries="@array/text_charging_symbol_entries"
android:entryValues="@array/text_charging_symbol_values"
android:defaultValue="0" />
<com.aosip.owlsnest.preference.SecureSettingSwitchPreference
android:key="status_bar_battery_style_tile"
android:title="@string/status_bar_battery_style_tile_title"
android:summary="@string/status_bar_battery_style_tile_summary"
android:defaultValue="true" />
</PreferenceScreen>
@@ -50,6 +50,7 @@
private static final String STATUS_BAR_BATTERY_STYLE_TILE = "status_bar_battery_style_tile";
private static final String STATUS_BAR_CHARGE_COLOR = "status_bar_charge_color";
private static final String FORCE_CHARGE_BATTERY_TEXT = "force_charge_battery_text";
private static final String TEXT_CHARGING_SYMBOL = "text_charging_symbol";
private static final int STATUS_BAR_BATTERY_STYLE_PORTRAIT = 0;
@@ -63,6 +64,8 @@
private ListPreference mStatusBarBatteryShowPercent;
private SwitchPreference mQsBatteryTitle;
private SwitchPreference mForceChargeBatteryText;
private ListPreference mTextChargingSymbol;
private int mTextChargingSymbolValue;
@Override
protected int getMetricsCategory() {
@@ -112,7 +115,14 @@ public void onCreate(Bundle savedInstanceState) {
mStatusBarBatteryShowPercent.setSummary(mStatusBarBatteryShowPercent.getEntry());
mStatusBarBatteryShowPercent.setOnPreferenceChangeListener(this);
enableStatusBarBatteryDependents(mStatusBarBatteryValue, mStatusBarBatteryShowPercentValue);
mTextChargingSymbol = (ListPreference) findPreference(TEXT_CHARGING_SYMBOL);
mTextChargingSymbolValue = Settings.Secure.getInt(resolver,
Settings.Secure.TEXT_CHARGING_SYMBOL, 0);
mTextChargingSymbol.setValue(Integer.toString(mTextChargingSymbolValue));
mTextChargingSymbol.setSummary(mTextChargingSymbol.getEntry());
mTextChargingSymbol.setOnPreferenceChangeListener(this);
enableStatusBarBatteryDependents();
}
@@ -137,48 +147,78 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
mStatusBarBattery.getEntries()[index]);
Settings.Secure.putInt(resolver,
Settings.Secure.STATUS_BAR_BATTERY_STYLE, mStatusBarBatteryValue);
enableStatusBarBatteryDependents();
return true;
} else if (preference == mStatusBarBatteryShowPercent) {
mStatusBarBatteryShowPercentValue = Integer.valueOf((String) newValue);
int index = mStatusBarBatteryShowPercent.findIndexOfValue((String) newValue);
mStatusBarBatteryShowPercent.setSummary(
mStatusBarBatteryShowPercent.getEntries()[index]);
Settings.Secure.putInt(resolver,
Settings.Secure.STATUS_BAR_SHOW_BATTERY_PERCENT, mStatusBarBatteryShowPercentValue);
enableStatusBarBatteryDependents();
return true;
} else if (preference == mQsBatteryTitle) {
boolean checked = ((SwitchPreference)preference).isChecked();
Settings.Secure.putInt(resolver,
Settings.Secure.STATUS_BAR_BATTERY_STYLE_TILE, checked ? 1:0);
return true;
} else if (preference == mForceChargeBatteryText) {
boolean checked = ((SwitchPreference)preference).isChecked();
Settings.Secure.putInt(resolver,
Settings.Secure.FORCE_CHARGE_BATTERY_TEXT, checked ? 1:0);
//enableStatusBarBatteryDependents();
return true;
} else if (preference.equals(mChargeColor)) {
int color = ((Integer) newValue).intValue();
Settings.Secure.putInt(resolver,
Settings.Secure.STATUS_BAR_CHARGE_COLOR, color);
return true;
} else if (preference == mTextChargingSymbol) {
mTextChargingSymbolValue = Integer.valueOf((String) newValue);
int index = mTextChargingSymbol.findIndexOfValue((String) newValue);
mTextChargingSymbol.setSummary(
mTextChargingSymbol.getEntries()[index]);
Settings.Secure.putInt(resolver,
Settings.Secure.TEXT_CHARGING_SYMBOL, mTextChargingSymbolValue);
return true;
}
enableStatusBarBatteryDependents(mStatusBarBatteryValue, mStatusBarBatteryShowPercentValue);
return true;
return false;
}
private void enableStatusBarBatteryDependents(int batteryIconStyle, int showPercentMode) {
if (batteryIconStyle == STATUS_BAR_BATTERY_STYLE_HIDDEN ||
batteryIconStyle == STATUS_BAR_BATTERY_STYLE_TEXT) {
private void enableStatusBarBatteryDependents() {
if (mStatusBarBatteryValue == STATUS_BAR_BATTERY_STYLE_HIDDEN) {
mStatusBarBatteryShowPercent.setEnabled(false);
mQsBatteryTitle.setEnabled(false);
mForceChargeBatteryText.setEnabled(false);
mChargeColor.setEnabled(false);
mTextChargingSymbol.setEnabled(false);
} else if (mStatusBarBatteryValue == STATUS_BAR_BATTERY_STYLE_TEXT) {
mStatusBarBatteryShowPercent.setEnabled(false);
mQsBatteryTitle.setEnabled(false);
mForceChargeBatteryText.setEnabled(false);
mChargeColor.setEnabled(false);
} else if (batteryIconStyle == STATUS_BAR_BATTERY_STYLE_PORTRAIT) {
mTextChargingSymbol.setEnabled(true);
} else if (mStatusBarBatteryValue == STATUS_BAR_BATTERY_STYLE_PORTRAIT) {
mStatusBarBatteryShowPercent.setEnabled(true);
mQsBatteryTitle.setEnabled(false);
mChargeColor.setEnabled(true);
mForceChargeBatteryText.setEnabled(showPercentMode == 1 ? true : false);
mForceChargeBatteryText.setEnabled(mStatusBarBatteryShowPercentValue == 2 ? false : true);
//relying on the mForceChargeBatteryText isChecked state is glitchy
//you need to click it twice to update the mTextChargingSymbol setEnabled state
//then the mForceChargeBatteryText isChecked state is incorrectly taken inverted
//so till a fix let's keep mTextChargingSymbol enabled by default
//mTextChargingSymbol.setEnabled((mStatusBarBatteryShowPercentValue == 0 && !mForceChargeBatteryText.isChecked())
//|| (mStatusBarBatteryShowPercentValue == 1 && !mForceChargeBatteryText.isChecked()) ? false : true);
mTextChargingSymbol.setEnabled(true);
} else {
mStatusBarBatteryShowPercent.setEnabled(true);
mQsBatteryTitle.setEnabled(true);
mForceChargeBatteryText.setEnabled(showPercentMode == 1 ? true : false);
mChargeColor.setEnabled(true);
mForceChargeBatteryText.setEnabled(mStatusBarBatteryShowPercentValue == 2 ? false : true);
//mTextChargingSymbol.setEnabled((mStatusBarBatteryShowPercentValue == 0 && !mForceChargeBatteryText.isChecked())
//|| (mStatusBarBatteryShowPercentValue == 1 && !mForceChargeBatteryText.isChecked()) ? false : true);
mTextChargingSymbol.setEnabled(true);
}
}

0 comments on commit e5d7c3d

Please sign in to comment.