OG: lights: Automatically generate an LED color for notifications

Change-Id: If9ac634451bc13ef515a4ff29ba42c53f10cf999
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index cc44802..a8fdd03 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -389,7 +389,8 @@
     <string name="notification_light_zen_mode">Lights in Do Not Disturb mode</string>
     <string name="notification_light_use_multiple_leds">Multiple LEDs</string>
     <string name="keywords_lights_brightness_level">dim leds brightness</string>
-    <string name="notification_light_automagic">Choose colors automatically</string>
+    <string name="notification_light_automagic">AutoColor</string>
+    <string name="notification_light_automagic_summary">Automatically set a proper color for the led notification if the app has no custom values</string>
     <!-- Lights settings, LED notification -->
     <string name="led_notification_title">Light settings</string>
     <string name="led_notification_text">LED light enabled by settings</string>
diff --git a/res/xml/notification_light_settings.xml b/res/xml/notification_light_settings.xml
index e93dc73..538a1ee 100644
--- a/res/xml/notification_light_settings.xml
+++ b/res/xml/notification_light_settings.xml
@@ -25,6 +25,13 @@
             android:key="notification_light_pulse"
             android:title="@string/notification_light_title" />
 
+        <org.omnirom.omnigears.preference.SystemSettingSwitchPreference
+            android:key="notification_light_color_auto"
+            android:title="@string/notification_light_automagic"
+            android:summary="@string/notification_light_automagic_summary"
+            android:dependency="notification_light_pulse"
+            android:defaultValue="true" />
+
         <org.omnirom.omnigears.batterylight.NotificationLightPreference
             android:key="default"
             android:title="@string/notification_light_default_value"
diff --git a/src/org/omnirom/omnigears/batterylight/NotificationLightSettings.java b/src/org/omnirom/omnigears/batterylight/NotificationLightSettings.java
index 708feb6..d0e0989 100644
--- a/src/org/omnirom/omnigears/batterylight/NotificationLightSettings.java
+++ b/src/org/omnirom/omnigears/batterylight/NotificationLightSettings.java
@@ -78,6 +78,7 @@
     private SystemSettingSwitchPreference mEnabledPref;
     private SystemSettingSwitchPreference mScreenOnLightsPref;
     private SystemSettingSwitchPreference mCustomEnabledPref;
+    private SystemSettingSwitchPreference mAutoGenerateColors;
     private NotificationLightPreference mDefaultPref;
     private Menu mMenu;
     private AppSelectListPreference mPackageAdapter;
@@ -120,6 +121,9 @@
                 findPreference(Settings.System.NOTIFICATION_LIGHT_SCREEN_ON);
         mScreenOnLightsPref.setOnPreferenceChangeListener(this);
 
+        mAutoGenerateColors = (SystemSettingSwitchPreference)
+                findPreference(Settings.System.NOTIFICATION_LIGHT_COLOR_AUTO);
+
         // Advanced light settings
         mCustomEnabledPref = (SystemSettingSwitchPreference)
                 findPreference(Settings.System.NOTIFICATION_LIGHT_PULSE_CUSTOM_ENABLE);
@@ -135,6 +139,14 @@
         mPackages = new HashMap<String, Package>();
         setHasOptionsMenu(true);
 
+        mMultiColorLed = resources.getBoolean(com.android.internal.R.bool.config_multiColorNotificationLed);
+        if (!mMultiColorLed) {
+            resetColors();
+            PreferenceGroup mGeneralPrefs = (PreferenceGroup) prefSet.findPreference("general_section");
+            mGeneralPrefs.removePreference(mAutoGenerateColors);
+        } else {
+            mAutoGenerateColors.setOnPreferenceChangeListener(this);
+        }
     }
 
     @Override
@@ -205,7 +217,8 @@
     }
 
     private int getInitialColorForPackage(String packageName) {
-        boolean autoColor = true;
+        boolean autoColor = Settings.System.getInt(getContentResolver(),
+                Settings.System.NOTIFICATION_LIGHT_COLOR_AUTO, mMultiColorLed ? 1 : 0) == 1;;
         int color = mDefaultColor;
         if (autoColor) {
             try {
@@ -341,7 +354,8 @@
     @Override
     public boolean onPreferenceChange(Preference preference, Object objValue) {
         if (preference == mEnabledPref || preference == mCustomEnabledPref ||
-            preference == mScreenOnLightsPref) {
+            preference == mScreenOnLightsPref ||
+            preference == mAutoGenerateColors) {
             getActivity().invalidateOptionsMenu();
         } else {
             NotificationLightPreference lightPref = (NotificationLightPreference) preference;