Battery Customizations

Change-Id: Ifa885f38bc311400bae9575d0c585c1c88d87b12
diff --git a/res/values/custom_arrays.xml b/res/values/custom_arrays.xml
index 6612e0c..340d3e3 100644
--- a/res/values/custom_arrays.xml
+++ b/res/values/custom_arrays.xml
@@ -493,22 +493,27 @@
         <item>3</item>
     </string-array>
 
-    <string-array name="battery_styles_entries" translatable="false">
-        <item>@string/battery_style_default</item>
-        <item>@string/battery_style_meter_horizontal</item>
+    <!-- Battery customizations -->
+    <string-array name="status_bar_battery_style_entries" translatable="false">
+        <item>@string/battery_style_port</item>
         <item>@string/battery_style_circle</item>
+        <item>@string/battery_style_dotted_circle</item>
+        <item>@string/battery_style_big_circle</item>
+        <item>@string/battery_style_big_dotted_circle</item>
+        <item>@string/battery_style_square</item>
+        <item>@string/battery_style_dotted_square</item>
         <item>@string/battery_style_text</item>
-        <item>@string/battery_style_round_rect</item>
-        <item>@string/battery_style_droid</item>
     </string-array>
 
-    <string-array name="battery_styles_values" translatable="false">
+    <string-array name="status_bar_battery_style_values" translatable="false">
         <item>0</item>
-        <item>1</item>
         <item>2</item>
         <item>3</item>
         <item>4</item>
         <item>5</item>
+        <item>6</item>
+        <item>7</item>
+        <item>8</item>
     </string-array>
 
     <string-array name="battery_percent_enable_entries" translatable="false">
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index ed46d9c..585bd2b 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -635,18 +635,19 @@
 
     <string name="keys_action_notifications">Notifications</string>
 
-    <string name="battery_style_text">Text only</string>
-    <string name="battery_style_default">Default</string>
-    <string name="battery_style_meter_horizontal">Horizontal bar</string>
+    <!-- Battery customizations -->
+    <string name="battery_style_category">Battery</string>
+    <string name="battery_style_title">Battery style</string>
+    <string name="battery_style_summary">Change the look of the icon in the statusbar</string>
+    <string name="battery_style_port">Portrait</string>
     <string name="battery_style_circle">Circle</string>
-    <string name="battery_style_droid">Droid</string>
-    <string name="battery_style_round_rect">Square</string>
-    <string name="statusbar_battery_dotted_line_title">Dotted line</string>
-    <string name="statusbar_battery_dotted_line_summary">Use dotted line effect for certain styles</string>
-    <string name="battery_percent_none">Never</string>
-    <string name="battery_percent_always">Always</string>
-    <string name="battery_percent_expanded">Only when expanded</string>
-    <string name="battery_percent_title">Show percent</string>
+    <string name="battery_style_dotted_circle">Dotted circle</string>
+    <string name="battery_style_solid_circle">Solid circle</string>
+    <string name="battery_style_big_circle">Big circle</string>
+    <string name="battery_style_big_dotted_circle">Big dotted circle</string>
+    <string name="battery_style_square">Square</string>
+    <string name="battery_style_dotted_square">Dotted square</string>
+    <string name="battery_style_text">Text</string>
 
     <string name="status_bar_clock">Clock &amp; Date</string>
     <string name="clock_title_enable">Alignment</string>
diff --git a/res/xml/bars_settings.xml b/res/xml/bars_settings.xml
index ced426f..604eeda 100644
--- a/res/xml/bars_settings.xml
+++ b/res/xml/bars_settings.xml
@@ -34,6 +34,19 @@
                 android:persistent="false" />
         </PreferenceCategory>
 
+    <PreferenceCategory
+        android:key="battery_settings"
+        android:title="@string/battery_style_category"/>
+         <ListPreference
+            android:key="status_bar_battery_style"
+            android:title="@string/battery_style_title"
+            android:summary="%s"
+            android:dialogTitle="@string/battery_style_title"
+            android:entries="@array/status_bar_battery_style_entries"
+            android:entryValues="@array/status_bar_battery_style_values"
+            android:defaultValue="0" />
+        </PreferenceCategory>
+
         <PreferenceCategory
             android:key="statusbar_settings_category"
             android:title="@string/statusbar_settings_category">
diff --git a/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java b/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
index 6bbb085..c9ce483 100644
--- a/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
+++ b/src/org/omnirom/omnigears/interfacesettings/BarsSettings.java
@@ -54,11 +54,14 @@
     private static final String KEY_ASPECT_RATIO_CATEGORY = "aspect_ratio_category";
     private static final String KEY_ASPECT_RATIO_APPS_LIST_SCROLLER = "aspect_ratio_apps_list_scroller";
     private static final String KEY_QS_PANEL_ALPHA = "qs_panel_alpha";
+    private static final String STATUS_BAR_BATTERY_STYLE = "status_bar_battery_style";
 
     private AppMultiSelectListPreference mAspectRatioAppsSelect;
     private ScrollAppsViewPreference mAspectRatioApps;
     private SeekBarPreference mQsPanelAlpha;
 
+    private ListPreference mStatusBarBattery;
+
     @Override
     public int getMetricsCategory() {
         return MetricsEvent.OMNI_SETTINGS;
@@ -77,6 +80,14 @@
         mQsPanelAlpha.setValue((int)(((double) qsPanelAlpha / 255) * 100));
         mQsPanelAlpha.setOnPreferenceChangeListener(this);
 
+	// Battery styles
+        mStatusBarBattery = (ListPreference) findPreference(STATUS_BAR_BATTERY_STYLE);
+        int batteryStyle = Settings.Secure.getInt(getContentResolver(),
+                Settings.Secure.STATUS_BAR_BATTERY_STYLE, 0);
+        mStatusBarBattery.setValue(String.valueOf(batteryStyle));
+        mStatusBarBattery.setSummary(mStatusBarBattery.getEntry());
+        mStatusBarBattery.setOnPreferenceChangeListener(this);
+
         final PreferenceCategory aspectRatioCategory =
                 (PreferenceCategory) getPreferenceScreen().findPreference(KEY_ASPECT_RATIO_CATEGORY);
         final boolean supportMaxAspectRatio = getResources().getBoolean(com.android.internal.R.bool.config_haveHigherAspectRatioScreen);
@@ -124,6 +135,13 @@
             Settings.System.putInt(getContentResolver(),
                     Settings.System.OMNI_QS_PANEL_BG_ALPHA, trueValue);
             return true;
+        } else if (preference == mStatusBarBattery) {
+            int clockStyle = Integer.valueOf((String) newValue);
+            int index = mStatusBarBattery.findIndexOfValue((String) newValue);
+            Settings.Secure.putInt(getActivity().getContentResolver(),
+                    Settings.Secure.STATUS_BAR_BATTERY_STYLE, clockStyle);
+            mStatusBarBattery.setSummary(mStatusBarBattery.getEntries()[index]);
+            return true;
         }
         return false;
     }