Cherish:Toggle for bolt icon when charging [2/2]

Make sure the switch is enabled only when relevant
This commit is contained in:
Hưng Phan
2020-09-01 22:07:04 +07:00
parent c95194f7f1
commit fad857d2ba
4 changed files with 50 additions and 3 deletions

View File

@@ -0,0 +1,7 @@
<vector xmlns:android="http://schemas.android.com/apk/res/android"
android:height="24dp"
android:width="24dp"
android:viewportWidth="24"
android:viewportHeight="24">
<path android:fillColor="?android:attr/colorControlNormal" android:pathData="M11 9.47V11H14.76L13 14.53V13H9.24L11 9.47M13 1L6 15H11V23L18 9H13V1Z" />
</vector>

View File

@@ -214,6 +214,8 @@
<string name="status_bar_battery_percentage_text_next">Next to the icon</string>
<string name="status_bar_battery_text_charging_title">Battery percentage when charging</string>
<string name="status_bar_battery_text_charging_summary">Always display battery percentage when charging</string>
<string name="status_bar_battery_charging_bolt_title">Show charging bolt</string>
<string name="status_bar_battery_charging_bolt_summary">Show a \u26A1\uFE0E symbol near battery text when charging</string>
<!-- Battery mode -->
<string name="battery_title">Battery icon</string>

View File

@@ -151,6 +151,13 @@
android:title="@string/status_bar_battery_text_charging_title"
android:summary="@string/status_bar_battery_text_charging_summary"
android:defaultValue="true" />
<com.cherish.settings.preferences.SystemSettingSwitchPreference
android:key="status_bar_battery_charging_bolt"
android:icon="@drawable/ic_lighting_bolt"
android:title="@string/status_bar_battery_charging_bolt_title"
android:summary="@string/status_bar_battery_charging_bolt_summary"
android:defaultValue="true" />
</PreferenceCategory>
</PreferenceScreen>

View File

@@ -42,6 +42,7 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
private static final String STATUS_BAR_CLOCK = "status_bar_clock";
private static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
private static final String STATUS_BAR_BATTERY_TEXT_CHARGING = "status_bar_battery_text_charging";
private static final String STATUS_BAR_BATTERY_CHARGING_BOLT = "status_bar_battery_charging_bolt";
private static final String BATTERY_PERCENTAGE_HIDDEN = "0";
private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
@@ -57,6 +58,7 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
private SwitchPreference mBatteryCharging;
private CustomSeekBarPreference mThreshold;
private SystemSettingSwitchPreference mNetMonitor;
private SwitchPreference mBatteryBolt;
@Override
public void onCreate(Bundle icicle) {
@@ -75,6 +77,10 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
mBatteryPercent = (ListPreference) findPreference(STATUS_BAR_SHOW_BATTERY_PERCENT);
mBatteryCharging = (SwitchPreference) findPreference(STATUS_BAR_BATTERY_TEXT_CHARGING);
mBatteryCharging.setOnPreferenceChangeListener(this);
mBatteryBolt = (SwitchPreference) findPreference(STATUS_BAR_BATTERY_CHARGING_BOLT);
mBatteryBolt.setOnPreferenceChangeListener(this);
mBatteryStyle = (ListPreference) findPreference(STATUS_BAR_BATTERY_STYLE);
int batterystyle = Settings.System.getInt(resolver,
@@ -122,23 +128,48 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
Settings.System.NETWORK_TRAFFIC_AUTOHIDE_THRESHOLD, val,
UserHandle.USER_CURRENT);
return true;
} else if (preference == mBatteryCharging) {
boolean enabled = (Boolean) objValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY_TEXT_CHARGING,
enabled ? 1 : 0);
updateBoltEnablement();
return true;
} else if (preference == mBatteryBolt) {
boolean enabled = (Boolean) objValue;
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY_CHARGING_BOLT,
enabled ? 1 : 0);
return true;
}
return false;
}
private void updateBatteryOptions(int batterystyle) {
boolean enabled = batterystyle != BATTERY_STYLE_TEXT && batterystyle != BATTERY_STYLE_HIDDEN;
boolean enabled = batterystyle != BATTERY_STYLE_TEXT && batterystyle != BATTERY_STYLE_HIDDEN;
if (batterystyle == BATTERY_STYLE_HIDDEN) {
mBatteryPercent.setValue(BATTERY_PERCENTAGE_HIDDEN);
mBatteryPercent.setSummary(mBatteryPercent.getEntry());
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_SHOW_BATTERY_PERCENT, 0);
}
mBatteryCharging.setEnabled(enabled);
mBatteryPercent.setEnabled(enabled);
mBatteryCharging.setEnabled(enabled);
mBatteryPercent.setEnabled(enabled);
updateBoltEnablement();
}
private void updateBoltEnablement() {
int batteryStyle = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_Q);
boolean precentOnCharging = Settings.System.getInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_BATTERY_TEXT_CHARGING, 1) == 1;
boolean textEnabled = batteryStyle == BATTERY_STYLE_TEXT ||
(batteryStyle == BATTERY_STYLE_HIDDEN && precentOnCharging);
mBatteryBolt.setEnabled(textEnabled);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;