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:
@@ -166,4 +166,33 @@
|
|||||||
<item>1</item>
|
<item>1</item>
|
||||||
</string-array>
|
</string-array>
|
||||||
|
|
||||||
</resources>
|
<!-- Battery percent -->
|
||||||
|
<string-array name="battery_percent_entries">
|
||||||
|
<item>@string/status_bar_battery_percentage_default</item>
|
||||||
|
<item>@string/status_bar_battery_percentage_text_next</item>
|
||||||
|
<item>@string/status_bar_battery_percentage_text_inside</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="battery_percent_values" translatable="false">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="status_bar_battery_style_entries" translatable="false">
|
||||||
|
<item>@string/status_bar_battery_style_q</item>
|
||||||
|
<item>@string/status_bar_battery_style_dotted_circle</item>
|
||||||
|
<item>@string/status_bar_battery_style_circle</item>
|
||||||
|
<item>@string/status_bar_battery_style_text</item>
|
||||||
|
<item>@string/status_bar_battery_style_hidden</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
<string-array name="status_bar_battery_style_values" translatable="false">
|
||||||
|
<item>0</item>
|
||||||
|
<item>1</item>
|
||||||
|
<item>2</item>
|
||||||
|
<item>3</item>
|
||||||
|
<item>4</item>
|
||||||
|
</string-array>
|
||||||
|
|
||||||
|
</resources>
|
||||||
|
|||||||
@@ -156,4 +156,22 @@
|
|||||||
<string name="lockscreen_charging_animation_title">Charging animation</string>
|
<string name="lockscreen_charging_animation_title">Charging animation</string>
|
||||||
<string name="lockscreen_charging_animation_summary">Display an animation when the device is plugged in</string>
|
<string name="lockscreen_charging_animation_summary">Display an animation when the device is plugged in</string>
|
||||||
|
|
||||||
|
<!-- Battery Styles -->
|
||||||
|
<string name="battery_style_category_title">Battery level</string>
|
||||||
|
<string name="battery_percent_title">Battery percent</string>
|
||||||
|
|
||||||
|
<!-- Status bar - Battery -->
|
||||||
|
<string name="status_bar_battery_style_title">Battery style</string>
|
||||||
|
<string name="status_bar_battery_style_q">Icon portrait (default)</string>
|
||||||
|
<string name="status_bar_battery_style_dotted_circle">Dotted circle</string>
|
||||||
|
<string name="status_bar_battery_style_circle">Filled circle</string>
|
||||||
|
<string name="status_bar_battery_style_text">Text</string>
|
||||||
|
<string name="status_bar_battery_style_hidden">Hidden</string>
|
||||||
|
|
||||||
|
<!-- Status bar - Battery percentage -->
|
||||||
|
<string name="status_bar_battery_percentage_title">Battery percentage</string>
|
||||||
|
<string name="status_bar_battery_percentage_default">Hidden (default)</string>
|
||||||
|
<string name="status_bar_battery_percentage_text_inside">Inside the icon</string>
|
||||||
|
<string name="status_bar_battery_percentage_text_next">Next to the icon</string>
|
||||||
|
|
||||||
</resources>
|
</resources>
|
||||||
|
|||||||
@@ -32,6 +32,28 @@
|
|||||||
android:summary="@string/status_bar_clock_summary"
|
android:summary="@string/status_bar_clock_summary"
|
||||||
android:defaultValue="true" />
|
android:defaultValue="true" />
|
||||||
|
|
||||||
|
<PreferenceCategory
|
||||||
|
|
||||||
|
android:key="battery_style_category"
|
||||||
|
android:title="@string/battery_style_category_title" >
|
||||||
|
|
||||||
|
<com.cherish.settings.preferences.SecureSettingListPreference
|
||||||
|
android:key="status_bar_battery_style"
|
||||||
|
android:title="@string/status_bar_battery_style_title"
|
||||||
|
android:summary="%s"
|
||||||
|
android:dialogTitle="@string/status_bar_battery_style_title"
|
||||||
|
android:entries="@array/status_bar_battery_style_entries"
|
||||||
|
android:entryValues="@array/status_bar_battery_style_values" />
|
||||||
|
|
||||||
|
<ListPreference
|
||||||
|
android:key="battery_percentage"
|
||||||
|
android:title="@string/battery_percent_title"
|
||||||
|
android:dialogTitle="@string/battery_percent_title"
|
||||||
|
android:entries="@array/battery_percent_entries"
|
||||||
|
android:entryValues="@array/battery_percent_values" />
|
||||||
|
|
||||||
|
</PreferenceCategory>
|
||||||
|
|
||||||
<Preference
|
<Preference
|
||||||
android:title="@string/statusbar_items_title"
|
android:title="@string/statusbar_items_title"
|
||||||
android:icon="@drawable/ic_shortcuts">
|
android:icon="@drawable/ic_shortcuts">
|
||||||
|
|||||||
@@ -41,8 +41,20 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
|
|||||||
OnPreferenceChangeListener {
|
OnPreferenceChangeListener {
|
||||||
|
|
||||||
private static final String STATUS_BAR_CLOCK = "status_bar_clock";
|
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 SystemSettingMasterSwitchPreference mStatusBarClockShow;
|
||||||
|
private ListPreference mBatteryPercent;
|
||||||
|
private ListPreference mBatteryStyle;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCreate(Bundle icicle) {
|
public void onCreate(Bundle icicle) {
|
||||||
@@ -58,6 +70,21 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
|
|||||||
mStatusBarClockShow.setChecked((Settings.System.getInt(resolver,
|
mStatusBarClockShow.setChecked((Settings.System.getInt(resolver,
|
||||||
Settings.System.STATUS_BAR_CLOCK, 1) == 1));
|
Settings.System.STATUS_BAR_CLOCK, 1) == 1));
|
||||||
mStatusBarClockShow.setOnPreferenceChangeListener(this);
|
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
|
@Override
|
||||||
@@ -67,13 +94,33 @@ public class StatusBarSettings extends SettingsPreferenceFragment implements
|
|||||||
Settings.System.putInt(getActivity().getContentResolver(),
|
Settings.System.putInt(getActivity().getContentResolver(),
|
||||||
Settings.System.STATUS_BAR_CLOCK, value ? 1 : 0);
|
Settings.System.STATUS_BAR_CLOCK, value ? 1 : 0);
|
||||||
return true;
|
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;
|
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
|
@Override
|
||||||
public int getMetricsCategory() {
|
public int getMetricsCategory() {
|
||||||
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
return MetricsProto.MetricsEvent.CHERISH_SETTINGS;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user