Settings: statusbar weather temperature placement (1/2)

Left or right options

PS2: no more restartSystemUI
PS3: remove unneeded explanation

Change-Id: I26a5f129c17bf041a6e84dbb21cb3acedb1a4f0b

Conflicts:
	res/values/custom_arrays.xml
	res/values/strings_aicp.xml
	res/xml/status_bar_weather.xml
	src/com/android/settings/broken/StatusBarWeatherIcon.java
diff --git a/res/values/custom_arrays.xml b/res/values/custom_arrays.xml
index c1f9d87..7590a01 100644
--- a/res/values/custom_arrays.xml
+++ b/res/values/custom_arrays.xml
@@ -1156,6 +1156,17 @@
     </string-array>
 
     <string-array name="status_bar_weather_font_style_values" translatable="false">
+		<item>0</item>
+        <item>1</item>
+    </string-array>
+
+    <!-- Status bar temperature location-->
+    <string-array name="status_bar_temperature_location_entries" translatable="false">
+        <item>@string/status_bar_temperature_location_right</item>
+        <item>@string/status_bar_temperature_location_left</item>
+    </string-array>
+
+    <string-array name="status_bar_temperature_location_values" translatable="false">
         <item>0</item>
         <item>1</item>
     </string-array>
diff --git a/res/values/custom_strings.xml b/res/values/custom_strings.xml
index eee1cbd..9346006 100644
--- a/res/values/custom_strings.xml
+++ b/res/values/custom_strings.xml
@@ -1860,8 +1860,12 @@
     <string name="status_bar_temperature_title">Status bar weather icon</string>
     <string name="status_bar_temperature_summary">Show weather in the status bar</string>
     <string name="status_bar_temperature_hidden">Hidden</string>
-    <string name="status_bar_temperature_show_scale">Scale showing</string>
-    <string name="status_bar_temperature_hide_scale">Scale hidden</string>
+    <string name="status_bar_temperature_show_scale">Shown with scale</string>
+    <string name="status_bar_temperature_hide_scale">Shown without scale</string>
+    <string name="status_bar_temperature_location_title">Placement</string>
+    <string name="status_bar_temperature_location_summary">Select where the weather temperature is shown on the statusbar</string>
+    <string name="status_bar_temperature_location_right">Show on right</string>
+    <string name="status_bar_temperature_location_left">Show on left</string>
     <string name="status_bar_weather_font_style_title">Font</string>
     <string name="status_bar_weather_font_normal">Normal</string>
     <string name="status_bar_weather_font_bold">Bold</string>
diff --git a/res/xml/status_bar_weather_icon.xml b/res/xml/status_bar_weather_icon.xml
index 8e34c7b..3f1bc90 100644
--- a/res/xml/status_bar_weather_icon.xml
+++ b/res/xml/status_bar_weather_icon.xml
@@ -28,6 +28,13 @@
             android:entryValues="@array/status_bar_weather_font_style_values"
             android:title="@string/status_bar_weather_font_style_title" />
 
+        <ListPreference
+            android:key="status_bar_temperature_style"
+            android:title="@string/status_bar_temperature_location_title"
+            android:dialogTitle="@string/status_bar_temperature_location_title"
+            android:entries="@array/status_bar_temperature_location_entries"
+            android:entryValues="@array/status_bar_temperature_location_values" />
+
         <net.margaritov.preference.colorpicker.ColorPickerPreference
             android:key="status_bar_weather_color"
             android:title="@string/status_bar_weather_color_title"
diff --git a/src/com/android/settings/broken/StatusBarWeatherIcon.java b/src/com/android/settings/broken/StatusBarWeatherIcon.java
index 50e808b..9abadd9 100644
--- a/src/com/android/settings/broken/StatusBarWeatherIcon.java
+++ b/src/com/android/settings/broken/StatusBarWeatherIcon.java
@@ -20,6 +20,7 @@
 import android.content.Intent;
 import android.content.res.Configuration;
 import android.os.Bundle;
+import android.os.UserHandle;
 import android.preference.ListPreference;
 import android.preference.Preference;
 import android.preference.Preference.OnPreferenceChangeListener;
@@ -39,6 +40,7 @@
 public class StatusBarWeatherIcon extends SettingsPreferenceFragment
         implements OnPreferenceChangeListener {
 
+    private static final String STATUS_BAR_TEMPERATURE = "status_bar_temperature";
     private static final String STATUS_BAR_TEMPERATURE_STYLE = "status_bar_temperature_style";
     private static final String PREF_STATUS_BAR_WEATHER_FONT_STYLE = "status_bar_weather_font_style";
     private static final String PREF_STATUS_BAR_WEATHER_COLOR = "status_bar_weather_color";
@@ -46,6 +48,7 @@
     private ListPreference mStatusBarTemperature;
     private ListPreference mStatusBarTemperatureFontStyle;
     private ColorPickerPreference mStatusBarTemperatureColor;
+    private ListPreference mStatusBarTemperatureStyle;
 
     @Override
     public void onCreate(Bundle icicle) {
@@ -54,10 +57,11 @@
 
         ContentResolver resolver = getActivity().getContentResolver();
 
-        mStatusBarTemperature = (ListPreference) findPreference(STATUS_BAR_TEMPERATURE_STYLE);
-        int temperatureStyle = Settings.System.getInt(resolver,
-                Settings.System.STATUS_BAR_SHOW_WEATHER_TEMP, 0);
-        mStatusBarTemperature.setValue(String.valueOf(temperatureStyle));
+        mStatusBarTemperature = (ListPreference) findPreference(STATUS_BAR_TEMPERATURE);
+        int temperatureShow = Settings.System.getIntForUser(resolver,
+                Settings.System.STATUS_BAR_SHOW_WEATHER_TEMP, 0,
+                UserHandle.USER_CURRENT);
+        mStatusBarTemperature.setValue(String.valueOf(temperatureShow));
         mStatusBarTemperature.setSummary(mStatusBarTemperature.getEntry());
         mStatusBarTemperature.setOnPreferenceChangeListener(this);
 
@@ -67,7 +71,7 @@
                 .getContentResolver(), Settings.System.STATUS_BAR_WEATHER_FONT_STYLE, 0)));
         mStatusBarTemperatureFontStyle.setSummary(mStatusBarTemperatureFontStyle.getEntry());
 
-         mStatusBarTemperatureColor =
+        mStatusBarTemperatureColor =
             (ColorPickerPreference) findPreference(PREF_STATUS_BAR_WEATHER_COLOR);
         mStatusBarTemperatureColor.setOnPreferenceChangeListener(this);
         int intColor = Settings.System.getInt(resolver,
@@ -75,16 +79,25 @@
         String hexColor = String.format("#%08x", (0xffffffff & intColor));
             mStatusBarTemperatureColor.setSummary(hexColor);
             mStatusBarTemperatureColor.setNewPreviewColor(intColor);
+
+        mStatusBarTemperatureStyle = (ListPreference) findPreference(STATUS_BAR_TEMPERATURE_STYLE);
+        int temperatureStyle = Settings.System.getIntForUser(resolver,
+                Settings.System.STATUS_BAR_WEATHER_TEMP_STYLE, 0,
+                UserHandle.USER_CURRENT);
+        mStatusBarTemperatureStyle.setValue(String.valueOf(temperatureStyle));
+        mStatusBarTemperatureStyle.setSummary(mStatusBarTemperatureStyle.getEntry());
+        mStatusBarTemperatureStyle.setOnPreferenceChangeListener(this);
     }
 
     @Override
     public boolean onPreferenceChange(Preference preference, Object newValue) {
         ContentResolver resolver = getActivity().getContentResolver();
         if (preference == mStatusBarTemperature) {
-            int temperatureStyle = Integer.valueOf((String) newValue);
+            int temperatureShow = Integer.valueOf((String) newValue);
             int index = mStatusBarTemperature.findIndexOfValue((String) newValue);
-            Settings.System.putInt(
-                    resolver, Settings.System.STATUS_BAR_SHOW_WEATHER_TEMP, temperatureStyle);
+            Settings.System.putIntForUser(
+                    resolver, Settings.System.STATUS_BAR_SHOW_WEATHER_TEMP, temperatureShow,
+                    UserHandle.USER_CURRENT);
             mStatusBarTemperature.setSummary(
                     mStatusBarTemperature.getEntries()[index]);
             return true;
@@ -103,6 +116,15 @@
             Settings.System.putInt(getContentResolver(),
                     Settings.System.STATUS_BAR_WEATHER_COLOR, intHex);
             return true;
+        } else if (preference == mStatusBarTemperatureStyle) {
+            int temperatureStyle = Integer.valueOf((String) newValue);
+            int index = mStatusBarTemperatureStyle.findIndexOfValue((String) newValue);
+            Settings.System.putIntForUser(
+                    resolver, Settings.System.STATUS_BAR_WEATHER_TEMP_STYLE, temperatureStyle,
+                    UserHandle.USER_CURRENT);
+            mStatusBarTemperatureStyle.setSummary(
+                    mStatusBarTemperatureStyle.getEntries()[index]);
+            return true;
         }
         return false;
     }