[2/2] OmniGears: lock screen clock style setting

Change-Id: I7dda1f6e78719daa7206e69a882cfc7819f1964e
diff --git a/res/values/custom_arrays.xml b/res/values/custom_arrays.xml
index 68430d2..3c3d3e8 100644
--- a/res/values/custom_arrays.xml
+++ b/res/values/custom_arrays.xml
@@ -627,4 +627,14 @@
         <item>0</item>
         <item>1</item>
     </string-array>
+
+    <string-array name="lockscreen_clock_style_entries" translatable="false">
+        <item>@string/clock_style_digital</item>
+        <item>@string/clock_style_analog</item>
+    </string-array>
+
+    <string-array name="lockscreen_clock_style_values" translatable="false">
+        <item>0</item>
+        <item>1</item>
+    </string-array>
 </resources>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index aa888d4..eef7a01 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -778,4 +778,8 @@
 
     <string name="navigation_bar_menu_arrow_keys_title">Arrow keys while typing</string>
     <string name="navigation_bar_menu_arrow_keys_summary">Display left and right cursor buttons while typing</string>
+
+    <string name="lockscreen_clock_style_title">Lock screen clock style</string>
+    <string name="clock_style_digital">Digital</string>
+    <string name="clock_style_analog">Analog</string>
 </resources>
diff --git a/res/xml/lockscreen_settings.xml b/res/xml/lockscreen_settings.xml
index 8dd6f2a..2edfe6a 100644
--- a/res/xml/lockscreen_settings.xml
+++ b/res/xml/lockscreen_settings.xml
@@ -51,5 +51,11 @@
         android:summary="@string/lockscreen_qs_disabled_summary"
         android:defaultValue="false" />
 
+    <ListPreference
+        android:key="lockscreen_clock_style"
+        android:title="@string/lockscreen_clock_style_title"
+        android:entries="@array/lockscreen_clock_style_entries"
+        android:entryValues="@array/lockscreen_clock_style_values"
+        android:persistent="false"/>
 </PreferenceScreen>
 
diff --git a/src/org/omnirom/omnigears/interfacesettings/LockscreenSettings.java b/src/org/omnirom/omnigears/interfacesettings/LockscreenSettings.java
index 3fb3789..a2be839 100644
--- a/src/org/omnirom/omnigears/interfacesettings/LockscreenSettings.java
+++ b/src/org/omnirom/omnigears/interfacesettings/LockscreenSettings.java
@@ -16,12 +16,17 @@
  *
 */
 package org.omnirom.omnigears.interfacesettings;
+
+import android.content.ContentResolver;
 import android.content.Context;
 import android.os.Bundle;
+import android.support.v7.preference.ListPreference;
 import android.support.v7.preference.Preference;
 import com.android.internal.logging.MetricsLogger;
 import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
 import android.provider.SearchIndexableResource;
+import android.provider.Settings;
+
 import com.android.settings.SettingsPreferenceFragment;
 import com.android.settings.R;
 import com.android.settings.search.BaseSearchIndexProvider;
@@ -33,6 +38,9 @@
 public class LockscreenSettings extends SettingsPreferenceFragment implements
         Preference.OnPreferenceChangeListener, Indexable {
     private static final String TAG = "LockscreenSettings";
+    private static final String LOCKSCREEN_CLOCK_STYLE = "lockscreen_clock_style";
+
+    private ListPreference mLockscreenClockStyle;
 
     @Override
     public int getMetricsCategory() {
@@ -43,6 +51,15 @@
     public void onCreate(Bundle savedInstanceState) {
         super.onCreate(savedInstanceState);
         addPreferencesFromResource(R.xml.lockscreen_settings);
+        final ContentResolver resolver = getContentResolver();
+
+        mLockscreenClockStyle = (ListPreference) findPreference(LOCKSCREEN_CLOCK_STYLE);
+        int clockStyle = Settings.System.getInt(resolver,
+                Settings.System.LOCKSCREEN_CLOCK_STYLE, 0);
+
+        mLockscreenClockStyle.setValue(Integer.toString(clockStyle));
+        mLockscreenClockStyle.setSummary(mLockscreenClockStyle.getEntry());
+        mLockscreenClockStyle.setOnPreferenceChangeListener(this);
     }
 
     @Override
@@ -52,6 +69,13 @@
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
+        if (preference == mLockscreenClockStyle) {
+            int value = Integer.valueOf((String) newValue);
+            int index = mLockscreenClockStyle.findIndexOfValue((String) newValue);
+            mLockscreenClockStyle.setSummary(mLockscreenClockStyle.getEntries()[index]);
+            Settings.System.putInt(getContentResolver(), Settings.System.LOCKSCREEN_CLOCK_STYLE, value);
+            return true;
+        }
         return false;
     }