Permalink
Browse files

Battery icon: allow to set a custom charging color [2/2]

Change-Id: I33a167e9b537f0de4f57ab90bd355979891349ca
  • Loading branch information...
ezio84 authored and xlxfoxxlx committed Nov 25, 2016
1 parent 992bdba commit 0278a91b2cc20a945ea7a02a38541e07d14f4aaa
Showing with 34 additions and 4 deletions.
  1. +2 −0 res/values/strings.xml
  2. +8 −1 res/xml/aosip_battery.xml
  3. +24 −3 src/com/aosip/owlsnest/statusbar/BatteryCategory.java
View
@@ -173,6 +173,8 @@
<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>
<string name="status_bar_charge_color_title">Statusbar battery icon charging color</string>
<string name="status_bar_charge_color_summary">Set the color of the statusbar battery icon while charging</string>
<!--Custom logos-->
<string name="sb_custom_logos">Custom Icons</string>
@@ -39,7 +39,14 @@
android:entryValues="@array/status_bar_battery_percentage_values"
android:defaultValue="0" />
<com.dirtyunicorns.dutweaks.preference.SecureSettingSwitchPreference
<net.margaritov.preference.colorpicker.ColorPickerPreference
android:key="status_bar_charge_color"
android:title="@string/status_bar_charge_color_title"
android:summary="@string/status_bar_charge_color_summary"
android:persistent="false"
android:defaultValue="0xffffff" />
<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"
@@ -19,10 +19,13 @@
import android.content.ContentResolver;
import android.content.Context;
import android.content.res.Resources;
import android.graphics.Color;
import android.net.TrafficStats;
import android.os.Bundle;
import android.support.v7.preference.ListPreference;
import android.support.v7.preference.Preference;
import android.support.v7.preference.PreferenceScreen;
import android.support.v14.preference.SwitchPreference;
import android.provider.SearchIndexableResource;
import android.provider.Settings;
@@ -37,18 +40,22 @@
import java.util.ArrayList;
import net.margaritov.preference.colorpicker.ColorPickerPreference;
import com.aosip.owlsnest.preference.CustomSeekBarPreference;
public class BatteryCategory extends SettingsPreferenceFragment implements
Preference.OnPreferenceChangeListener {
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 String STATUS_BAR_CHARGE_COLOR = "status_bar_charge_color";
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 ColorPickerPreference mChargeColor;
private int mStatusBarBatteryValue;
private int mStatusBarBatteryShowPercentValue;
private ListPreference mStatusBarBattery;
@@ -84,6 +91,12 @@ public void onCreate(Bundle savedInstanceState) {
mStatusBarBattery.setSummary(mStatusBarBattery.getEntry());
mStatusBarBattery.setOnPreferenceChangeListener(this);
int chargeColor = Settings.Secure.getInt(resolver,
Settings.Secure.STATUS_BAR_CHARGE_COLOR, Color.WHITE);
mChargeColor = (ColorPickerPreference) findPreference("status_bar_charge_color");
mChargeColor.setNewPreviewColor(chargeColor);
mChargeColor.setOnPreferenceChangeListener(this);
mStatusBarBatteryShowPercent =
(ListPreference) findPreference(STATUS_BAR_SHOW_BATTERY_PERCENT);
mStatusBarBatteryShowPercentValue = Settings.Secure.getInt(resolver,
@@ -115,20 +128,25 @@ public boolean onPreferenceChange(Preference preference, Object newValue) {
int index = mStatusBarBattery.findIndexOfValue((String) newValue);
mStatusBarBattery.setSummary(
mStatusBarBattery.getEntries()[index]);
Settings.Secure.putInt(getContentResolver(),
Settings.Secure.putInt(resolver,
Settings.Secure.STATUS_BAR_BATTERY_STYLE, mStatusBarBatteryValue);
enableStatusBarBatteryDependents(mStatusBarBatteryValue);
} else if (preference == mStatusBarBatteryShowPercent) {
mStatusBarBatteryShowPercentValue = Integer.valueOf((String) newValue);
int index = mStatusBarBatteryShowPercent.findIndexOfValue((String) newValue);
mStatusBarBatteryShowPercent.setSummary(
mStatusBarBatteryShowPercent.getEntries()[index]);
Settings.Secure.putInt(getContentResolver(),
Settings.Secure.putInt(resolver,
Settings.Secure.STATUS_BAR_SHOW_BATTERY_PERCENT, mStatusBarBatteryShowPercentValue);
} else if (preference == mQsBatteryTitle) {
boolean checked = ((SwitchPreference)preference).isChecked();
Settings.Secure.putInt(getActivity().getContentResolver(),
Settings.Secure.putInt(resolver,
Settings.Secure.STATUS_BAR_BATTERY_STYLE_TILE, checked ? 1:0);
} else if (preference.equals(mChargeColor)) {
int color = ((Integer) newValue).intValue();
Settings.Secure.putInt(resolver,
Settings.Secure.STATUS_BAR_CHARGE_COLOR, color);
return true;
}
return true;
}
@@ -138,11 +156,14 @@ private void enableStatusBarBatteryDependents(int batteryIconStyle) {
batteryIconStyle == STATUS_BAR_BATTERY_STYLE_TEXT) {
mStatusBarBatteryShowPercent.setEnabled(false);
mQsBatteryTitle.setEnabled(false);
mChargeColor.setEnabled(false);
} else if (batteryIconStyle == STATUS_BAR_BATTERY_STYLE_PORTRAIT) {
mQsBatteryTitle.setEnabled(false);
mChargeColor.setEnabled(true);
} else {
mStatusBarBatteryShowPercent.setEnabled(true);
mQsBatteryTitle.setEnabled(true);
mChargeColor.setEnabled(true);
}
}

0 comments on commit 0278a91

Please sign in to comment.