Skip to content

Commit

Permalink
Battery tile: allow to disable custom battery style [2/2]
Browse files Browse the repository at this point in the history
- Disable battery tile toggle when style is enabled for portrait, text
or hidden.

Change-Id: I4e6f7c1bb5f3dd35919d59f9b7b4cf828854125b
  • Loading branch information
ezio84 authored and xlxfoxxlx committed Jun 12, 2017
1 parent 0292da6 commit 992bdba
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 0 deletions.
2 changes: 2 additions & 0 deletions res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,8 @@
<string name="status_bar_battery_percentage_default">Hidden</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>
<string name="status_bar_battery_style_tile_title">Custom battery tile style</string>
<string name="status_bar_battery_style_tile_summary">Allow to set the same icon style chosen for the statusbar battery</string>

<!--Custom logos-->
<string name="sb_custom_logos">Custom Icons</string>
Expand Down
5 changes: 5 additions & 0 deletions res/xml/aosip_battery.xml
Original file line number Diff line number Diff line change
Expand Up @@ -39,5 +39,10 @@
android:entryValues="@array/status_bar_battery_percentage_values"
android:defaultValue="0" />

<com.dirtyunicorns.dutweaks.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>

16 changes: 16 additions & 0 deletions src/com/aosip/owlsnest/statusbar/BatteryCategory.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,14 +43,17 @@ public class BatteryCategory extends SettingsPreferenceFragment implements

private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
private static final String STATUS_BAR_SHOW_BATTERY_PERCENT = "status_bar_show_battery_percent";
private static final String STATUS_BAR_BATTERY_STYLE_TILE = "status_bar_battery_style_tile";

private static final int STATUS_BAR_BATTERY_STYLE_PORTRAIT = 0;
private static final int STATUS_BAR_BATTERY_STYLE_HIDDEN = 4;
private static final int STATUS_BAR_BATTERY_STYLE_TEXT = 6;

private int mStatusBarBatteryValue;
private int mStatusBarBatteryShowPercentValue;
private ListPreference mStatusBarBattery;
private ListPreference mStatusBarBatteryShowPercent;
private SwitchPreference mQsBatteryTitle;

@Override
protected int getMetricsCategory() {
Expand All @@ -69,6 +72,11 @@ public void onCreate(Bundle savedInstanceState) {
int intColor;
String hexColor;

mQsBatteryTitle = (SwitchPreference) findPreference(STATUS_BAR_BATTERY_STYLE_TILE);
mQsBatteryTitle.setChecked((Settings.Secure.getInt(resolver,
Settings.Secure.STATUS_BAR_BATTERY_STYLE_TILE, 1) == 1));
mQsBatteryTitle.setOnPreferenceChangeListener(this);

mStatusBarBattery = (ListPreference) findPreference(STATUS_BAR_BATTERY_STYLE);
mStatusBarBatteryValue = Settings.Secure.getInt(resolver,
Settings.Secure.STATUS_BAR_BATTERY_STYLE, 0);
Expand Down Expand Up @@ -117,6 +125,10 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
mStatusBarBatteryShowPercent.getEntries()[index]);
Settings.Secure.putInt(getContentResolver(),
Settings.Secure.STATUS_BAR_SHOW_BATTERY_PERCENT, mStatusBarBatteryShowPercentValue);
} else if (preference == mQsBatteryTitle) {
boolean checked = ((SwitchPreference)preference).isChecked();
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.STATUS_BAR_BATTERY_STYLE_TILE, checked ? 1:0);
}
return true;
}
Expand All @@ -125,8 +137,12 @@ private void enableStatusBarBatteryDependents(int batteryIconStyle) {
if (batteryIconStyle == STATUS_BAR_BATTERY_STYLE_HIDDEN ||
batteryIconStyle == STATUS_BAR_BATTERY_STYLE_TEXT) {
mStatusBarBatteryShowPercent.setEnabled(false);
mQsBatteryTitle.setEnabled(false);
} else if (batteryIconStyle == STATUS_BAR_BATTERY_STYLE_PORTRAIT) {
mQsBatteryTitle.setEnabled(false);
} else {
mStatusBarBatteryShowPercent.setEnabled(true);
mQsBatteryTitle.setEnabled(true);
}
}

Expand Down

0 comments on commit 992bdba

Please sign in to comment.