OmniControl: Update Battery led settings for the new battery_low_behavior
Change-Id: I68fcefcabada249a930ff273110353b12a07a3a9
diff --git a/app/src/main/java/org/omnirom/control/BatteryLightSettingsFragment.java b/app/src/main/java/org/omnirom/control/BatteryLightSettingsFragment.java
index f67a3e4..96c17c0 100644
--- a/app/src/main/java/org/omnirom/control/BatteryLightSettingsFragment.java
+++ b/app/src/main/java/org/omnirom/control/BatteryLightSettingsFragment.java
@@ -26,6 +26,7 @@
import androidx.annotation.DrawableRes;
import androidx.annotation.XmlRes;
+import androidx.preference.ListPreference;
import androidx.preference.Preference;
import androidx.preference.PreferenceGroup;
import androidx.preference.PreferenceScreen;
@@ -46,8 +47,8 @@
private static final String FAST_COLOR_PREF = "fast_battery_light_color";
private static final String FAST_CHARGING_LED_PREF = "fast_charging_led_enabled";
private static final String BATTERY_DND_PREF = "battery_light_allow_on_dnd";
+ private static final String BATTERY_LED_LOW_BEHAVIOR = "battery_low_behavior";
private static final String BATTERY_LIGHT_PREF = "battery_light_enabled";
- private static final String BATTERY_PULSE_PREF = "battery_light_pulse";
private static final String BATTERY_LIGHT_ONLY_FULL_PREF = "battery_light_only_fully_charged";
private static final String KEY_CATEGORY_FAST_CHARGE = "fast_color_cat";
private static final String KEY_CATEGORY_CHARGE_COLORS = "colors_list";
@@ -57,10 +58,10 @@
private SystemSettingsColorSelectPreference mFullColorPref;
private SystemSettingsColorSelectPreference mReallyFullColorPref;
private SystemSettingsColorSelectPreference mFastColorPref;
+ private ListPreference mLedLowBehavior;
private Preference mDefaultValues;
private SystemSettingSwitchPreference mDndPref;
private SystemSettingSwitchPreference mEnabledPref;
- private SystemSettingSwitchPreference mPulsePref;
private SystemSettingSwitchPreference mOnlyFullPref;
private SystemSettingSwitchPreference mFastBatteryLightEnabledPref;
@@ -103,9 +104,15 @@
}
});
+ mLedLowBehavior = (ListPreference) findPreference(BATTERY_LED_LOW_BEHAVIOR);
+ int ledlowBehaviorValue = Settings.System.getInt(resolver,
+ OmniSettings.OMNI_LOW_BATTERY_BEHAVIOR, 0);
+ mLedLowBehavior.setValue(Integer.toString(ledlowBehaviorValue));
+ mLedLowBehavior.setSummary(mLedLowBehavior.getEntry());
+ mLedLowBehavior.setOnPreferenceChangeListener(this);
+
mDndPref = (SystemSettingSwitchPreference) findPreference(BATTERY_DND_PREF);
mEnabledPref = (SystemSettingSwitchPreference) findPreference(BATTERY_LIGHT_PREF);
- mPulsePref = (SystemSettingSwitchPreference) findPreference(BATTERY_PULSE_PREF);
mOnlyFullPref = (SystemSettingSwitchPreference) findPreference(BATTERY_LIGHT_ONLY_FULL_PREF);
mOnlyFullPref.setOnPreferenceChangeListener(this);
@@ -157,6 +164,13 @@
// If enabled, disable all but really full color preference.
updateEnablement(value);
}
+ if (preference == mLedLowBehavior) {
+ int value = Integer.valueOf((String) objValue);
+ int index = mLedLowBehavior.findIndexOfValue((String) objValue);
+ mLedLowBehavior.setSummary(mLedLowBehavior.getEntries()[index]);
+ Settings.System.putInt(getContext().getContentResolver(),
+ OmniSettings.OMNI_LOW_BATTERY_BEHAVIOR, value);
+ }
return true;
}
@@ -186,9 +200,6 @@
if (mEnabledPref != null) {
mEnabledPref.setChecked(true);
}
- if (mPulsePref != null) {
- mPulsePref.setChecked(false);
- }
if (mOnlyFullPref != null) {
mOnlyFullPref.setChecked(false);
}
@@ -199,6 +210,12 @@
boolean showOnlyWhenFull = Settings.System.getInt(getContext().getContentResolver(),
OmniSettings.OMNI_BATTERY_LIGHT_ONLY_FULLY_CHARGED, 1) != 0;
updateEnablement(showOnlyWhenFull);
+
+ if (mLedLowBehavior != null) {
+ mLedLowBehavior.setSummary(mLedLowBehavior.getEntries()[0]);
+ Settings.System.putInt(getContext().getContentResolver(),
+ OmniSettings.OMNI_LOW_BATTERY_BEHAVIOR, 0);
+ }
}
protected void resetColors() {
diff --git a/app/src/main/res/values/arrays.xml b/app/src/main/res/values/arrays.xml
index 6cf9ed4..bc76d8b 100644
--- a/app/src/main/res/values/arrays.xml
+++ b/app/src/main/res/values/arrays.xml
@@ -1,4 +1,17 @@
<resources>
+ <!-- LED behavior when battery is low -->
+ <string-array name="led_battery_entries" translatable="false">
+ <item>Solid when charging, flashing when not charging</item>
+ <item>Always solid when battery is low</item>
+ <item>Always flashing when battery is low</item>
+ </string-array>
+
+ <string-array name="led_battery_values" translatable="false">
+ <item>0</item>
+ <item>1</item>
+ <item>2</item>
+ </string-array>
+
<!-- Reply Preference -->
<string-array name="reply_entries">
<item>Reply</item>
diff --git a/app/src/main/res/values/strings.xml b/app/src/main/res/values/strings.xml
index e9fae61..2054975 100644
--- a/app/src/main/res/values/strings.xml
+++ b/app/src/main/res/values/strings.xml
@@ -93,6 +93,7 @@
<string name="batterylight_title">Battery LED settings</string>
<string name="batterylight_summary">Customize your battery led</string>
<string name="battery_light_enable">Enable</string>
+ <string name="battery_low_behavior_tile">LED behavior when battery is low</string>
<string name="battery_low_pulse_title">Pulse if battery low</string>
<string name="battery_light_only_full_charge_title">Only light up when fully charged</string>
<string name="battery_light_list_title">Colors</string>
diff --git a/app/src/main/res/xml/battery_light_settings_preferences.xml b/app/src/main/res/xml/battery_light_settings_preferences.xml
index 7a94455..0942a94 100644
--- a/app/src/main/res/xml/battery_light_settings_preferences.xml
+++ b/app/src/main/res/xml/battery_light_settings_preferences.xml
@@ -17,11 +17,13 @@
android:key="general_section"
android:title="@string/notification_light_general_title">
- <omnirom.preference.SystemSettingSwitchPreference
- android:key="battery_light_pulse"
- android:title="@string/battery_low_pulse_title"
+ <ListPreference
+ android:key="battery_low_behavior"
+ android:title="@string/battery_low_behavior_tile"
android:dependency="battery_light_enabled"
- android:defaultValue="false" />
+ android:entries="@array/led_battery_entries"
+ android:entryValues="@array/led_battery_values"
+ android:persistent="false" />
<omnirom.preference.SystemSettingSwitchPreference
android:key="battery_light_only_fully_charged"