Cherish: Implement battery styles (2/2)

spezi77:
- Adapted to our battery styles
- Note to myself: In Android10 battery percentage has become a global setting
This commit is contained in:
TheStrix
2020-01-14 08:53:59 +00:00
committed by Hưng Phan
parent 8230859788
commit 3469e1146b
4 changed files with 118 additions and 2 deletions

View File

@@ -41,8 +41,20 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
OnPreferenceChangeListener {
private static final String STATUS_BAR_CLOCK = "status_bar_clock";
private static final String SHOW_BATTERY_PERCENT = "show_battery_percent";
private static final String KEY_BATTERY_PERCENTAGE = "battery_percentage";
private static final String BATTERY_PERCENTAGE_HIDDEN = "0";
private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
private static final int BATTERY_STYLE_Q = 0;
private static final int BATTERY_STYLE_DOTTED_CIRCLE = 1;
private static final int BATTERY_STYLE_CIRCLE = 2;
private static final int BATTERY_STYLE_TEXT = 3;
private static final int BATTERY_STYLE_HIDDEN = 4;
private SystemSettingMasterSwitchPreference mStatusBarClockShow;
private ListPreference mBatteryPercent;
private ListPreference mBatteryStyle;
@Override
public void onCreate(Bundle icicle) {
@@ -58,6 +70,21 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
mStatusBarClockShow.setChecked((Settings.System.getInt(resolver,
Settings.System.STATUS_BAR_CLOCK, 1) == 1));
mStatusBarClockShow.setOnPreferenceChangeListener(this);
mBatteryPercent = (ListPreference) findPreference(KEY_BATTERY_PERCENTAGE);
int percentstyle = Settings.System.getInt(resolver,
Settings.System.SHOW_BATTERY_PERCENT, 0);
mBatteryPercent.setValue(String.valueOf(percentstyle));
mBatteryPercent.setSummary(mBatteryPercent.getEntry());
mBatteryPercent.setOnPreferenceChangeListener(this);
mBatteryStyle = (ListPreference) findPreference(STATUS_BAR_BATTERY_STYLE);
int batterystyle = Settings.Secure.getIntForUser(resolver,
Settings.Secure.STATUS_BAR_BATTERY_STYLE, BATTERY_STYLE_Q,
UserHandle.USER_CURRENT);
mBatteryStyle.setOnPreferenceChangeListener(this);
updateBatteryOptions(batterystyle);
}
@Override
@@ -67,13 +94,33 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.STATUS_BAR_CLOCK, value ? 1 : 0);
return true;
} else if (preference == mBatteryPercent) {
int value = Integer.parseInt((String) objValue);
int index = mBatteryPercent.findIndexOfValue((String) objValue);
Settings.System.putInt(getActivity().getContentResolver(),
Settings.System.SHOW_BATTERY_PERCENT, value);
mBatteryPercent.setSummary(mBatteryPercent.getEntries()[index]);
return true;
} else if (preference == mBatteryStyle) {
int value = Integer.parseInt((String) objValue);
updateBatteryOptions(value);
return true;
}
return false;
}
private void updateBatteryOptions(int batterystyle) {
if (batterystyle == BATTERY_STYLE_HIDDEN) {
mBatteryPercent.setValue(BATTERY_PERCENTAGE_HIDDEN);
mBatteryPercent.setSummary(mBatteryPercent.getEntry());
}
mBatteryPercent.setEnabled(batterystyle != BATTERY_STYLE_TEXT && batterystyle != BATTERY_STYLE_HIDDEN);
}
@Override
public int getMetricsCategory() {
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
}
}
}