BatteryLightSettings: Add ability to turn off LED when fully charged

Option will not show for devices with colored battery LEDs as those
can set the color to black.

Change-Id: I5076776747c1006671e421242f75f61cc6a7cdb2
diff --git a/res/values/bools.xml b/res/values/bools.xml
index 38d748f..3c5764a 100644
--- a/res/values/bools.xml
+++ b/res/values/bools.xml
@@ -1,6 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
 <!--
      Copyright (C) 2015 The CyanogenMod Project
+                   2021 The LineageOS Project
 
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
@@ -20,5 +21,7 @@
     <bool name="def_battery_light_enabled">true</bool>
     <!-- Default value for battery light pulse -->
     <bool name="def_battery_light_pulse">true</bool>
+    <!-- Default value for battery light disabled when fully charged preference -->
+    <bool name="def_battery_light_full_charge_disabled">false</bool>
 
 </resources>
diff --git a/res/values/strings.xml b/res/values/strings.xml
index 021f6ec..42223b8 100644
--- a/res/values/strings.xml
+++ b/res/values/strings.xml
@@ -82,6 +82,7 @@
     <!-- Battery light settings -->
     <string name="battery_light_title">Battery light</string>
     <string name="battery_low_pulse_title">Pulse if battery low</string>
+    <string name="battery_light_full_charge_disabled_title">Turn off when fully charged</string>
     <string name="battery_light_list_title">Colors</string>
     <string name="battery_light_low_color_title">Battery low</string>
     <string name="battery_light_medium_color_title">Charging</string>
diff --git a/res/xml/battery_light_settings.xml b/res/xml/battery_light_settings.xml
index eb2b671..1f09a9b 100644
--- a/res/xml/battery_light_settings.xml
+++ b/res/xml/battery_light_settings.xml
@@ -1,5 +1,7 @@
 <?xml version="1.0" encoding="utf-8"?>
-<!-- Copyright (C) 2012 The CyanogenMod Project
+<!--
+     Copyright (C) 2016 The CyanogenMod Project
+                   2017-2018,2021 The LineageOS Project
 
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
@@ -33,6 +35,12 @@
             android:defaultValue="@bool/def_battery_light_pulse"
             android:dependency="battery_light_enabled" />
 
+        <lineageos.preference.LineageSystemSettingSwitchPreference
+            android:key="battery_light_full_charge_disabled"
+            android:title="@string/battery_light_full_charge_disabled_title"
+            android:defaultValue="@bool/def_battery_light_full_charge_disabled"
+            android:dependency="battery_light_enabled" />
+
     </PreferenceCategory>
 
     <PreferenceCategory
diff --git a/src/org/lineageos/lineageparts/notificationlight/BatteryLightSettings.java b/src/org/lineageos/lineageparts/notificationlight/BatteryLightSettings.java
index 7dc2ae8..4887afa 100644
--- a/src/org/lineageos/lineageparts/notificationlight/BatteryLightSettings.java
+++ b/src/org/lineageos/lineageparts/notificationlight/BatteryLightSettings.java
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2012 The CyanogenMod Project
+ *               2017-2021 The LineageOS Project
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -47,6 +48,8 @@
     private static final String MEDIUM_COLOR_PREF = "medium_color";
     private static final String FULL_COLOR_PREF = "full_color";
     private static final String LIGHT_ENABLED_PREF = "battery_light_enabled";
+    private static final String LIGHT_FULL_CHARGE_DISABLED_PREF =
+            "battery_light_full_charge_disabled";
     private static final String PULSE_ENABLED_PREF = "battery_light_pulse";
     private static final String BRIGHTNESS_PREFERENCE = "battery_light_brightness_level";
     private static final String BRIGHTNESS_ZEN_PREFERENCE = "battery_light_brightness_level_zen";
@@ -56,6 +59,7 @@
     private ApplicationLightPreference mMediumColorPref;
     private ApplicationLightPreference mFullColorPref;
     private LineageSystemSettingSwitchPreference mLightEnabledPref;
+    private LineageSystemSettingSwitchPreference mLightFullChargeDisabledPref;
     private LineageSystemSettingSwitchPreference mPulseEnabledPref;
     private BatteryBrightnessPreference mBatteryBrightnessPref;
     private BatteryBrightnessZenPreference mBatteryBrightnessZenPref;
@@ -94,6 +98,7 @@
         PreferenceGroup generalPrefs = prefSet.findPreference(GENERAL_SECTION);
 
         mLightEnabledPref = prefSet.findPreference(LIGHT_ENABLED_PREF);
+        mLightFullChargeDisabledPref = prefSet.findPreference(LIGHT_FULL_CHARGE_DISABLED_PREF);
         mPulseEnabledPref = prefSet.findPreference(PULSE_ENABLED_PREF);
         mBatteryBrightnessPref = prefSet.findPreference(BRIGHTNESS_PREFERENCE);
         mBatteryBrightnessZenPref = prefSet.findPreference(BRIGHTNESS_ZEN_PREFERENCE);
@@ -112,6 +117,7 @@
         }
 
         if (mMultiColorLed) {
+            generalPrefs.removePreference(mLightFullChargeDisabledPref);
             setHasOptionsMenu(true);
 
             // Low, Medium and full color preferences
@@ -249,9 +255,14 @@
     protected void resetToDefaults() {
         final Resources res = getResources();
         final boolean batteryLightEnabled = res.getBoolean(R.bool.def_battery_light_enabled);
+        final boolean batteryLightFullChargeDisabled =
+                res.getBoolean(R.bool.def_battery_light_full_charge_disabled);
         final boolean batteryLightPulseEnabled = res.getBoolean(R.bool.def_battery_light_pulse);
 
         if (mLightEnabledPref != null) mLightEnabledPref.setChecked(batteryLightEnabled);
+        if (mLightFullChargeDisabledPref != null) {
+            mLightFullChargeDisabledPref.setChecked(batteryLightFullChargeDisabled);
+        }
         if (mPulseEnabledPref != null) mPulseEnabledPref.setChecked(batteryLightPulseEnabled);
 
         resetColors();