OmniGears: Visualizer customizations

Change-Id: Icbe767ae938dabb379ec131de4572825c9ca4a7a
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index d698af8..40a561a 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -811,8 +811,12 @@
     <string name="style_settings_summary">Customize the look and feel</string>
     <string name="custom_bars_settings_title">Bars</string>
 
-    <!-- Lock screen visualizer -->
-    <string name="lockscreen_visualizer_title">Music visualizer</string>
-    <string name="lockscreen_visualizer_summary">Show visualizer on lockscreen when music is playing</string>
+    <!-- Lockscreen visualizer -->
+    <string name="lockscreen_visualizer_category">Visualizer</string>
+    <string name="lockscreen_visualizer_enable">Enable lockscreen visualizer</string>
+    <string name="lockscreen_visualizer_enable_summary">Show visualizer on lockscreen when music is playing</string>
+    <string name="lockscreen_visualizer_enable_custom">Use custom color</string>
+    <string name="lockscreen_visualizer_enable_custom_summary">Use a preset color instead of the generated color</string>
+    <string name="lockscreen_visualizer_custom_color">Visualizer Color</string>
 
 </resources>
diff --git a/res/xml/lockscreenitems.xml b/res/xml/lockscreenitems.xml
index 6be6ecb..1c5288e 100644
--- a/res/xml/lockscreenitems.xml
+++ b/res/xml/lockscreenitems.xml
@@ -26,6 +26,20 @@
         android:defaultValue="false" />
 
     <org.omnirom.omnilib.preference.SystemSettingSwitchPreference
+        android:key="lock_screen_visualizer_use_custom_color"
+        android:title="@string/lockscreen_visualizer_enable_custom"
+        android:summary="@string/lockscreen_visualizer_enable_custom_summary"
+        android:dependency="lockscreen_visualizer_enabled"
+        android:defaultValue="false" />
+    
+    <org.omnirom.omnilib.preference.ColorSelectPreference
+        android:key="lock_screen_visualizer_custom_color"
+        android:title="@string/battery_bar_color"
+        android:dependency="lock_screen_visualizer_use_custom_color"
+        android:defaultValue="0xffffffff"
+        android:dialogTitle="@string/lockscreen_visualizer_custom_color" />
+
+    <org.omnirom.omnilib.preference.SystemSettingSwitchPreference
         android:key="lockscreen_weather_enabled"
         android:title="@string/lockscreen_weather_title"
         android:summary="@string/lockscreen_weather_summary"
diff --git a/src/org/omnirom/omnigears/interfacesettings/LockscreenItemSettings.java b/src/org/omnirom/omnigears/interfacesettings/LockscreenItemSettings.java
index c985ca8..3881121 100644
--- a/src/org/omnirom/omnigears/interfacesettings/LockscreenItemSettings.java
+++ b/src/org/omnirom/omnigears/interfacesettings/LockscreenItemSettings.java
@@ -17,19 +17,24 @@
 */
 package org.omnirom.omnigears.interfacesettings;
 import android.os.Bundle;
+import android.content.ContentResolver;
 import android.content.Context;
 import android.content.Intent;
 import android.content.res.Resources;
 import android.support.v7.preference.Preference;
+import android.support.v7.preference.PreferenceScreen;
 import android.provider.SearchIndexableResource;
+import android.provider.Settings;
 
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 
-import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.R;
+import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.search.BaseSearchIndexProvider;
 import com.android.settings.search.Indexable;
 
+import org.omnirom.omnilib.preference.ColorSelectPreference;
+
 import java.util.List;
 import java.util.ArrayList;
 
@@ -37,6 +42,9 @@
         Preference.OnPreferenceChangeListener, Indexable {
 
     private static final String TAG = "LockscreenItemSettings";
+    private static final String LOCK_SCREEN_VISUALIZER_CUSTOM_COLOR = "lock_screen_visualizer_custom_color";
+
+    private ColorSelectPreference mVisualizerColor;
 
     @Override
     public int getMetricsCategory() {
@@ -47,6 +55,17 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         addPreferencesFromResource(R.xml.lockscreenitems);
+        ContentResolver resolver = getActivity().getContentResolver();
+
+        // Visualizer custom color
+        mVisualizerColor = (ColorSelectPreference) findPreference(LOCK_SCREEN_VISUALIZER_CUSTOM_COLOR);
+        int visColor = Settings.System.getInt(resolver,
+                Settings.System.LOCK_SCREEN_VISUALIZER_CUSTOM_COLOR, 0xff1976D2);
+        String hexColor = String.format("#%08X", visColor);
+        mVisualizerColor.setSummary(visColorHex);
+        mVisualizerColor.setNewPreviewColor(visColor);
+        mVisualizerColor.setAlphaSliderEnabled(true);
+        mVisualizerColor.setOnPreferenceChangeListener(this);
     }
 
     @Override
@@ -56,7 +75,15 @@
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
-        return true;
+         ContentResolver resolver = getActivity().getContentResolver();
+         if (preference == mVisualizerColor) {
+            String hexColor = String.format("#%08X", mVisualizerColor.getColor());
+            Settings.System.putInt(resolver,
+                    Settings.System.LOCK_SCREEN_VISUALIZER_CUSTOM_COLOR, mVisualizerColor.getColor());
+            mVisualizerColor.setSummary(hexColor);
+            return true;
+        }
+        return false;
     }
 
     public static final Indexable.SearchIndexProvider SEARCH_INDEX_DATA_PROVIDER =