WeatherInformation: settings improvements
authorGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 8 Oct 2014 01:48:01 +0000 (03:48 +0200)
committerGustavo Martin Morcuende <gu.martinm@gmail.com>
Wed, 8 Oct 2014 01:48:01 +0000 (03:48 +0200)
Android/WeatherInformation/res/layout/weather_current_fragment.xml
Android/WeatherInformation/res/values/arrays.xml
Android/WeatherInformation/res/values/strings.xml
Android/WeatherInformation/res/xml/weather_preferences.xml
Android/WeatherInformation/src/de/example/exampletdd/NotificationIntentService.java
Android/WeatherInformation/src/de/example/exampletdd/WidgetIntentService.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/current/CurrentFragment.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/preferences/WeatherInformationPreferencesFragment.java
Android/WeatherInformation/src/de/example/exampletdd/fragment/specific/SpecificFragment.java

index 74a56ec..e6618b6 100644 (file)
@@ -4,12 +4,13 @@
     android:layout_width="match_parent"
     android:layout_height="match_parent" >
 
-    <FrameLayout 
+    <FrameLayout
         android:layout_width="match_parent"
-        android:layout_height="wrap_content">
+        android:layout_height="wrap_content"
+        android:layout_gravity="center">
         
     <!-- TODO: align start/end feels like-snow humidity-rain wind-clouds -->
-    <LinearLayout
+    <LinearLayout android:id="@+id/weather_current_data_container"
         android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
index 0404af5..d306f8e 100644 (file)
@@ -6,9 +6,9 @@
         <item>K</item>
     </string-array>
     <string-array name="weather_preferences_units_human_value">
-        <item>Celsius</item>
-        <item>Fahrenheit</item>
-        <item>Kelvin</item>
+        <item>celsius</item>
+        <item>fahrenheit</item>
+        <item>kelvin</item>
     </string-array>
     <string-array name="weather_preferences_language_value">
         <item>ar</item>
index 3150a22..4214cd3 100644 (file)
@@ -21,7 +21,6 @@
     <string name="weather_preferences_actionbar_title">Settings</string>
     <string name="weather_preferences_units">Units</string>
     <string name="weather_preferences_units_key">weather_preferences_units</string>
-    <string name="weather_preferences_units_celsius">Celsius</string>
     <string name="weather_preferences_temperature_units">Temperature</string>
     <string name="weather_preferences_notifications">Notifications</string>
     <string name="weather_preferences_notifications_switch_off_summary">Disabled</string>
@@ -37,7 +36,7 @@
     <string name="weather_preferences_refresh_interval">Refresh interval</string>
     <string name="weather_preferences_wind_key">weather_preferences_wind</string>
     <string name="weather_preferences_wind">Wind</string>
-    <string name="weather_preferences_wind_summary">Wind</string>
+    <string name="weather_preferences_wind_summary">meter per second</string>
     <string name="city_not_found">city not found</string>
     <string name="country_not_found">country not found</string>
     <string name="progress_dialog_generic_message">Please wait&#8230;</string>
index ac012d9..a2754f8 100644 (file)
     <PreferenceCategory android:title="@string/weather_preferences_units">
         <ListPreference android:key="@string/weather_preferences_units_key"
             android:title="@string/weather_preferences_temperature_units"
-            android:summary="@string/weather_preferences_units_celsius"
+            android:summary="celsius"
             android:entries="@array/weather_preferences_units_human_value"
             android:entryValues="@array/weather_preferences_units_value"
             android:selectable="true"
             android:persistent="true"
-            android:defaultValue="@string/weather_preferences_units_celsius" />
+            android:defaultValue="ºC" />
         <ListPreference android:key="@string/weather_preferences_wind_key"
-            android:entryValues="@array/weather_preferences_wind_human_value"
-            android:entries="@array/weather_preferences_wind"
+            android:entryValues="@array/weather_preferences_wind"
+            android:entries="@array/weather_preferences_wind_human_value"
+            android:summary="@string/weather_preferences_wind_summary"
+            android:selectable="true"
+            android:persistent="true"
+            android:defaultValue="m/s"
             android:title="@string/weather_preferences_wind"/>
     </PreferenceCategory>
     <PreferenceCategory android:title="@string/weather_preferences_notifications">
index d544cb9..608c4d7 100644 (file)
@@ -99,25 +99,54 @@ public class NotificationIntentService extends IntentService {
         return current;
     }
     
+    private interface UnitsConversor {
+       
+       public double doConversion(final double value);
+    }
+    
     private void showNotification(final Current current, final WeatherLocation weatherLocation) {
         final SharedPreferences sharedPreferences = PreferenceManager
                 .getDefaultSharedPreferences(this.getApplicationContext());
 
-        // TODO: repeating the same code in Overview, Specific and Current!!!
-        // 1. Update units of measurement.
-        boolean mIsFahrenheit = false;
-        final String keyPreference = this.getResources().getString(
-                R.string.weather_preferences_units_key);
-        final String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
-        final String celsius = this.getResources().getString(
-                R.string.weather_preferences_units_celsius);
-        if (unitsPreferenceValue.equals(celsius)) {
-            mIsFahrenheit = false;
+               // TODO: repeating the same code in Overview, Specific and Current!!!
+               // 1. Update units of measurement.
+        // 1.1 Temperature
+        String tempSymbol;
+        UnitsConversor tempUnitsConversor;
+        String keyPreference = this.getResources().getString(R.string.weather_preferences_units_key);
+        String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
+        String[] values = this.getResources().getStringArray(R.array.weather_preferences_units_value);
+        if (unitsPreferenceValue.equals(values[0])) {
+               tempSymbol = values[0];
+               tempUnitsConversor = new UnitsConversor(){
+
+                               @Override
+                               public double doConversion(final double value) {
+                                       return value - 273.15;
+                               }
+                       
+               };
+        } else if (unitsPreferenceValue.equals(values[1])) {
+               tempSymbol = values[1];
+               tempUnitsConversor = new UnitsConversor(){
+
+                               @Override
+                               public double doConversion(final double value) {
+                                       return (value * 1.8) - 459.67;
+                               }
+                       
+               };
         } else {
-            mIsFahrenheit = true;
+               tempSymbol = values[2];
+               tempUnitsConversor = new UnitsConversor(){
+
+                               @Override
+                               public double doConversion(final double value) {
+                                       return value;
+                               }
+                       
+               };
         }
-        final double tempUnits = mIsFahrenheit ? 0 : 273.15;
-        final String symbol = mIsFahrenheit ? "ºF" : "ºC";
 
 
         // 2. Formatters
@@ -129,14 +158,14 @@ public class NotificationIntentService extends IntentService {
         String tempMax = "";
         if (current.getMain().getTemp_max() != null) {
             double conversion = (Double) current.getMain().getTemp_max();
-            conversion = conversion - tempUnits;
-            tempMax = tempFormatter.format(conversion) + symbol;
+            conversion = tempUnitsConversor.doConversion(conversion);
+            tempMax = tempFormatter.format(conversion) + tempSymbol;
         }
         String tempMin = "";
         if (current.getMain().getTemp_min() != null) {
             double conversion = (Double) current.getMain().getTemp_min();
-            conversion = conversion - tempUnits;
-            tempMin = tempFormatter.format(conversion) + symbol;
+            conversion = tempUnitsConversor.doConversion(conversion);
+            tempMin = tempFormatter.format(conversion) + tempSymbol;
         }
         Bitmap picture;
         if ((current.getWeather().size() > 0)
index 4319637..ae164ba 100644 (file)
@@ -143,25 +143,54 @@ public class WidgetIntentService extends IntentService {
                return current;
        }
 
+    private interface UnitsConversor {
+       
+       public double doConversion(final double value);
+    }
+    
        private RemoteViews makeView(final Current current, final WeatherLocation weatherLocation) {
                final SharedPreferences sharedPreferences = PreferenceManager
                                .getDefaultSharedPreferences(this.getApplicationContext());
 
                // TODO: repeating the same code in Overview, Specific and Current!!!
                // 1. Update units of measurement.
-               boolean mIsFahrenheit = false;
-               final String keyPreference = this.getResources().getString(
-                               R.string.weather_preferences_units_key);
-               final String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
-               final String celsius = this.getResources().getString(
-                               R.string.weather_preferences_units_celsius);
-               if (unitsPreferenceValue.equals(celsius)) {
-                       mIsFahrenheit = false;
-               } else {
-                       mIsFahrenheit = true;
-               }
-               final double tempUnits = mIsFahrenheit ? 0 : 273.15;
-               final String symbol = mIsFahrenheit ? "ºF" : "ºC";
+        // 1.1 Temperature
+        String tempSymbol;
+        UnitsConversor tempUnitsConversor;
+        String keyPreference = this.getResources().getString(R.string.weather_preferences_units_key);
+        String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
+        String[] values = this.getResources().getStringArray(R.array.weather_preferences_units_value);
+        if (unitsPreferenceValue.equals(values[0])) {
+               tempSymbol = values[0];
+               tempUnitsConversor = new UnitsConversor(){
+
+                               @Override
+                               public double doConversion(final double value) {
+                                       return value - 273.15;
+                               }
+                       
+               };
+        } else if (unitsPreferenceValue.equals(values[1])) {
+               tempSymbol = values[1];
+               tempUnitsConversor = new UnitsConversor(){
+
+                               @Override
+                               public double doConversion(final double value) {
+                                       return (value * 1.8) - 459.67;
+                               }
+                       
+               };
+        } else {
+               tempSymbol = values[2];
+               tempUnitsConversor = new UnitsConversor(){
+
+                               @Override
+                               public double doConversion(final double value) {
+                                       return value;
+                               }
+                       
+               };
+        }
 
 
                // 2. Formatters
@@ -173,14 +202,14 @@ public class WidgetIntentService extends IntentService {
                String tempMax = "";
                if (current.getMain().getTemp_max() != null) {
                        double conversion = (Double) current.getMain().getTemp_max();
-                       conversion = conversion - tempUnits;
-                       tempMax = tempFormatter.format(conversion) + symbol;
+                       conversion = tempUnitsConversor.doConversion(conversion);
+                       tempMax = tempFormatter.format(conversion) + tempSymbol;
                }
                String tempMin = "";
                if (current.getMain().getTemp_min() != null) {
                        double conversion = (Double) current.getMain().getTemp_min();
-                       conversion = conversion - tempUnits;
-                       tempMin = tempFormatter.format(conversion) + symbol;
+                       conversion = tempUnitsConversor.doConversion(conversion);
+                       tempMin = tempFormatter.format(conversion) + tempSymbol;
                }
                Bitmap picture;
                if ((current.getWeather().size() > 0)
index 7552c35..901ecfa 100644 (file)
@@ -82,10 +82,9 @@ public class CurrentFragment extends Fragment {
         
         this.setHasOptionsMenu(false);
 
-        final ProgressBar progress = (ProgressBar) getActivity().findViewById(R.id.weather_current_progressbar);
-        progress.setVisibility(View.VISIBLE);
-        final TextView errorMessage = (TextView) getActivity().findViewById(R.id.weather_current_error_message);
-        errorMessage.setVisibility(View.GONE);
+        this.getActivity().findViewById(R.id.weather_current_data_container).setVisibility(View.GONE);
+        this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.VISIBLE);
+       this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.GONE);   
     }
 
     @Override
@@ -126,11 +125,9 @@ public class CurrentFragment extends Fragment {
 
                                        } else {
                                                // Empty UI and show error message
-                                               CurrentFragment.this.clearUI();
-                                               final ProgressBar progress = (ProgressBar) getActivity().findViewById(R.id.weather_current_progressbar);
-                                       progress.setVisibility(View.GONE);
-                                               final TextView errorMessage = (TextView) getActivity().findViewById(R.id.weather_current_error_message);
-                                       errorMessage.setVisibility(View.VISIBLE);
+                                               CurrentFragment.this.getActivity().findViewById(R.id.weather_current_data_container).setVisibility(View.GONE);
+                                               CurrentFragment.this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.GONE);
+                                               CurrentFragment.this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.VISIBLE);
                                        }
                                }
                        }
@@ -143,7 +140,7 @@ public class CurrentFragment extends Fragment {
                                                        .registerReceiver(this.mReceiver, filter);
 
         // Empty UI
-        this.clearUI();
+        this.getActivity().findViewById(R.id.weather_current_data_container).setVisibility(View.GONE);
         
         final DatabaseQueries query = new DatabaseQueries(this.getActivity().getApplicationContext());
         final WeatherLocation weatherLocation = query.queryDataBase();
@@ -165,10 +162,8 @@ public class CurrentFragment extends Fragment {
         } else {
             // Load remote data (aynchronous)
             // Gets the data from the web.
-               final ProgressBar progress = (ProgressBar) getActivity().findViewById(R.id.weather_current_progressbar);
-            progress.setVisibility(View.VISIBLE);
-            final TextView errorMessage = (TextView) getActivity().findViewById(R.id.weather_current_error_message);
-            errorMessage.setVisibility(View.GONE);
+               this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.VISIBLE);
+               this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.GONE);
             final CurrentTask task = new CurrentTask(
                        this.getActivity().getApplicationContext(),
                     new CustomHTTPClient(AndroidHttpClient.newInstance("Android 4.3 WeatherInformation Agent")),
@@ -202,11 +197,16 @@ public class CurrentFragment extends Fragment {
         super.onPause();
     }
 
-    private interface UnitsConversor {
+    private interface TempUnitsConversor {
        
        public double doConversion(final double value);
     }
-    
+
+    private interface WindUnitsConversor {
+       
+       public double doConversion(final double value);
+    }
+
     private void updateUI(final Current current) {
        
         final SharedPreferences sharedPreferences = PreferenceManager
@@ -216,13 +216,13 @@ public class CurrentFragment extends Fragment {
         // 1. Update units of measurement.
         // 1.1 Temperature
         String tempSymbol;
-        UnitsConversor tempUnitsConversor;
+        TempUnitsConversor tempUnitsConversor;
         String keyPreference = this.getResources().getString(R.string.weather_preferences_units_key);
         String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
         String[] values = this.getResources().getStringArray(R.array.weather_preferences_units_value);
         if (unitsPreferenceValue.equals(values[0])) {
                tempSymbol = values[0];
-               tempUnitsConversor = new UnitsConversor(){
+               tempUnitsConversor = new TempUnitsConversor(){
 
                                @Override
                                public double doConversion(final double value) {
@@ -232,7 +232,7 @@ public class CurrentFragment extends Fragment {
                };
         } else if (unitsPreferenceValue.equals(values[1])) {
                tempSymbol = values[1];
-               tempUnitsConversor = new UnitsConversor(){
+               tempUnitsConversor = new TempUnitsConversor(){
 
                                @Override
                                public double doConversion(final double value) {
@@ -242,7 +242,7 @@ public class CurrentFragment extends Fragment {
                };
         } else {
                tempSymbol = values[2];
-               tempUnitsConversor = new UnitsConversor(){
+               tempUnitsConversor = new TempUnitsConversor(){
 
                                @Override
                                public double doConversion(final double value) {
@@ -253,10 +253,30 @@ public class CurrentFragment extends Fragment {
         }
 
         // 1.2 Wind
+        String windSymbol;
+        WindUnitsConversor windUnitsConversor;
         keyPreference = this.getResources().getString(R.string.weather_preferences_wind_key);
-        final String windSymbol = sharedPreferences.getString(
-                       keyPreference,
-                       this.getResources().getStringArray(R.array.weather_preferences_wind)[0]);
+        unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
+        values = this.getResources().getStringArray(R.array.weather_preferences_wind);
+        if (unitsPreferenceValue.equals(values[0])) {
+               windSymbol = values[0];
+               windUnitsConversor = new WindUnitsConversor(){
+
+                       @Override
+                       public double doConversion(double value) {
+                               return value;
+                       }       
+               };
+        } else {
+               windSymbol = values[1];
+               windUnitsConversor = new WindUnitsConversor(){
+
+                       @Override
+                       public double doConversion(double value) {
+                               return value * 2.237;
+                       }       
+               };
+        }
 
 
         // 2. Formatters
@@ -312,7 +332,8 @@ public class CurrentFragment extends Fragment {
         String windValue = "";
         if ((current.getWind() != null)
                 && (current.getWind().getSpeed() != null)) {
-            final double conversion = (Double) current.getWind().getSpeed();
+            double conversion = (Double) current.getWind().getSpeed();
+            conversion = windUnitsConversor.doConversion(conversion);
             windValue = tempFormatter.format(conversion);
         }
         String rainValue = "";
@@ -354,11 +375,6 @@ public class CurrentFragment extends Fragment {
 
 
         // 4. Update UI.
-        ProgressBar progress = (ProgressBar) getActivity().findViewById(R.id.weather_current_progressbar);
-        progress.setVisibility(View.GONE);
-        TextView errorMessage = (TextView) getActivity().findViewById(R.id.weather_current_error_message);
-        errorMessage.setVisibility(View.GONE);
-        
         final TextView tempMaxView = (TextView) getActivity().findViewById(R.id.weather_current_temp_max);
         tempMaxView.setText(tempMax);
         final TextView tempMinView = (TextView) getActivity().findViewById(R.id.weather_current_temp_min);
@@ -369,53 +385,39 @@ public class CurrentFragment extends Fragment {
         final TextView descriptionView = (TextView) getActivity().findViewById(R.id.weather_current_description);
         descriptionView.setText(description);
         
-        ((TextView) getActivity().findViewById(R.id.weather_current_humidity)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_humidity));
         ((TextView) getActivity().findViewById(R.id.weather_current_humidity_value)).setText(humidityValue);
         ((TextView) getActivity().findViewById(R.id.weather_current_humidity_units)).setText(
                        this.getActivity().getApplicationContext().getString(R.string.text_units_percent));
         
-        ((TextView) getActivity().findViewById(R.id.weather_current_pressure)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_pressure));
         ((TextView) getActivity().findViewById(R.id.weather_current_pressure_value)).setText(pressureValue);
         ((TextView) getActivity().findViewById(R.id.weather_current_pressure_units)).setText(
                        this.getActivity().getApplicationContext().getString(R.string.text_units_hpa));
         
-        ((TextView) getActivity().findViewById(R.id.weather_current_wind)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_wind));
         ((TextView) getActivity().findViewById(R.id.weather_current_wind_value)).setText(windValue);
         ((TextView) getActivity().findViewById(R.id.weather_current_wind_units)).setText(windSymbol);
         
-        ((TextView) getActivity().findViewById(R.id.weather_current_rain)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_rain));
         ((TextView) getActivity().findViewById(R.id.weather_current_rain_value)).setText(rainValue);
         ((TextView) getActivity().findViewById(R.id.weather_current_rain_units)).setText(
                        this.getActivity().getApplicationContext().getString(R.string.text_units_mm3h));
         
-        ((TextView) getActivity().findViewById(R.id.weather_current_clouds)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_clouds));
         ((TextView) getActivity().findViewById(R.id.weather_current_clouds_value)).setText(cloudsValue);
         ((TextView) getActivity().findViewById(R.id.weather_current_clouds_units)).setText(
                        this.getActivity().getApplicationContext().getString(R.string.text_units_percent));
         
-        ((TextView) getActivity().findViewById(R.id.weather_current_snow)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_snow));
         ((TextView) getActivity().findViewById(R.id.weather_current_snow_value)).setText(snowValue);
         ((TextView) getActivity().findViewById(R.id.weather_current_snow_units)).setText(
                        this.getActivity().getApplicationContext().getString(R.string.text_units_mm3h));
         
-        ((TextView) getActivity().findViewById(R.id.weather_current_feelslike)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_feels_like));
         ((TextView) getActivity().findViewById(R.id.weather_current_feelslike_value)).setText(feelsLike);
         ((TextView) getActivity().findViewById(R.id.weather_current_feelslike_units)).setText(tempSymbol);
         
-        ((TextView) getActivity().findViewById(R.id.weather_current_sunrise)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_sun_rise));
         ((TextView) getActivity().findViewById(R.id.weather_current_sunrise_value)).setText(sunRiseTime);
 
-        ((TextView) getActivity().findViewById(R.id.weather_current_sunset)).setText(
-                       this.getActivity().getApplicationContext().getString(R.string.text_field_sun_set));
         ((TextView) getActivity().findViewById(R.id.weather_current_sunset_value)).setText(sunSetTime);
+        
+        this.getActivity().findViewById(R.id.weather_current_data_container).setVisibility(View.VISIBLE);
+        this.getActivity().findViewById(R.id.weather_current_progressbar).setVisibility(View.GONE);
+        this.getActivity().findViewById(R.id.weather_current_error_message).setVisibility(View.GONE);       
     }
     
     private boolean isDataFresh(final Date lastUpdate) {
@@ -437,54 +439,6 @@ public class CurrentFragment extends Fragment {
        return false;
     }
     
-    private void clearUI() {
-
-       // TODO: something better than this for clearing view?
-        ((TextView) getActivity().findViewById(R.id.weather_current_temp_max)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_temp_min)).setText("");
-        
-        ((ImageView) getActivity().findViewById(R.id.weather_current_picture)).setImageBitmap(null);
-        
-
-        ((TextView) getActivity().findViewById(R.id.weather_current_description)).setText("");
-        
-
-        ((TextView) getActivity().findViewById(R.id.weather_current_humidity)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_humidity_value)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_humidity_units)).setText("");
-       
-        ((TextView) getActivity().findViewById(R.id.weather_current_pressure)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_pressure_value)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_pressure_units)).setText("");
-        
-        ((TextView) getActivity().findViewById(R.id.weather_current_wind)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_wind_value)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_wind_units)).setText("");
-        
-        ((TextView) getActivity().findViewById(R.id.weather_current_rain)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_rain_value)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_rain_units)).setText("");
-
-        ((TextView) getActivity().findViewById(R.id.weather_current_clouds)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_clouds_value)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_clouds_units)).setText("");
-
-        ((TextView) getActivity().findViewById(R.id.weather_current_snow)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_snow_value)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_snow_units)).setText("");    
-        
-        ((TextView) getActivity().findViewById(R.id.weather_current_feelslike)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_feelslike_value)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_feelslike_units)).setText("");
-        
-        
-        ((TextView) getActivity().findViewById(R.id.weather_current_sunrise)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_sunrise_value)).setText("");
-        
-        ((TextView) getActivity().findViewById(R.id.weather_current_sunset)).setText("");
-        ((TextView) getActivity().findViewById(R.id.weather_current_sunset_value)).setText("");
-    }
-    
     // TODO: How could I show just one progress dialog when I have two fragments in tabs
     //       activity doing the same in background?
     //       I mean, if OverviewTask shows one progress dialog and CurrentTask does the same I will have
index 6ad22ba..b730ea1 100644 (file)
@@ -64,6 +64,20 @@ public class WeatherInformationPreferencesFragment extends PreferenceFragment
         }
         connectionPref.setSummary(humanValue);
         
+        // Wind
+        values = this.getResources().getStringArray(R.array.weather_preferences_wind);
+        humanValues = this.getResources().getStringArray(R.array.weather_preferences_wind_human_value);
+        keyPreference = this.getString(R.string.weather_preferences_wind_key);
+        connectionPref = this.findPreference(keyPreference);
+        value = this.getPreferenceManager().getSharedPreferences().getString(keyPreference, "");
+        humanValue = "";
+        if (value.equals(values[0])) {
+            humanValue = humanValues[0];
+        } else if (value.equals(values[1])) {
+            humanValue = humanValues[1];
+        }
+        connectionPref.setSummary(humanValue);
+        
         // Forecast days number
         values = this.getResources().getStringArray(R.array.weather_preferences_day_forecast);
         humanValues = this.getResources().getStringArray(R.array.weather_preferences_day_forecast_human_value);
@@ -126,19 +140,30 @@ public class WeatherInformationPreferencesFragment extends PreferenceFragment
     public void onSharedPreferenceChanged(
             final SharedPreferences sharedPreferences, final String key) {
        
-       // Units of Measurement
+       // Temperature units
+       String[] values = this.getResources().getStringArray(R.array.weather_preferences_units_value);
+       String[] humanValues = this.getResources().getStringArray(R.array.weather_preferences_units_human_value);
         String keyValue = this.getActivity().getApplicationContext().getString(
                 R.string.weather_preferences_units_key);
-
         if (key.equals(keyValue)) {
-            final Preference connectionPref = this.findPreference(key);
-            connectionPref.setSummary(sharedPreferences.getString(key, ""));
-            return;
+               final Preference connectionPref = this.findPreference(key);
+            final String value = sharedPreferences.getString(key, "");
+               String humanValue = "";
+               if (value.equals(values[0])) {
+                       humanValue = humanValues[0];
+               } else if (value.equals(values[1])) {
+                       humanValue = humanValues[1];
+               } else if (value.equals(values[2])) {
+                       humanValue = humanValues[2];
+               }
+
+               connectionPref.setSummary(humanValue);
+               return;
         }
 
         // Update Time Rate
-        String[] values = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate);
-        String[] humanValues = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate_human_value);
+        values = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate);
+        humanValues = this.getResources().getStringArray(R.array.weather_preferences_update_time_rate_human_value);
         keyValue = this.getActivity().getApplicationContext().getString(
                        R.string.weather_preferences_update_time_rate_key);
         if (key.equals(keyValue)) {
@@ -162,6 +187,24 @@ public class WeatherInformationPreferencesFragment extends PreferenceFragment
             return;
         }
 
+        // Wind
+        values = this.getResources().getStringArray(R.array.weather_preferences_wind);
+        humanValues = this.getResources().getStringArray(R.array.weather_preferences_wind_human_value);
+        keyValue = this.getString(R.string.weather_preferences_wind_key);
+        if (key.equals(keyValue)) {
+            final Preference connectionPref = this.findPreference(key);
+            final String value = sharedPreferences.getString(key, "");
+            String humanValue = "";
+            if (value.equals(values[0])) {
+               humanValue = humanValues[0];
+            } else if (value.equals(values[1])) {
+               humanValue = humanValues[1];
+            }
+        
+               connectionPref.setSummary(humanValue);
+               return;
+        }
+        
         // Forecast days number
         values = this.getResources().getStringArray(R.array.weather_preferences_day_forecast);
         humanValues = this.getResources().getStringArray(R.array.weather_preferences_day_forecast_human_value);
index f223018..40f11d9 100644 (file)
@@ -103,11 +103,16 @@ public class SpecificFragment extends Fragment {
         }
     }
 
-    private interface UnitsConversor {
+    private interface TempUnitsConversor {
        
        public double doConversion(final double value);
     }
-    
+
+    private interface WindUnitsConversor {
+       
+       public double doConversion(final double value);
+    }
+
     private void updateUI(final Forecast forecastWeatherData, final int chosenDay) {
 
         final SharedPreferences sharedPreferences = PreferenceManager
@@ -117,14 +122,14 @@ public class SpecificFragment extends Fragment {
         // 1. Update units of measurement.
         // 1.1 Temperature
         String tempSymbol;
-        UnitsConversor tempUnitsConversor;
+        TempUnitsConversor tempUnitsConversor;
         String keyPreference = this.getResources().getString(
                 R.string.weather_preferences_units_key);
-        final String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
+        String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
         String[] values = this.getResources().getStringArray(R.array.weather_preferences_units_value);
         if (unitsPreferenceValue.equals(values[0])) {
                tempSymbol = values[0];
-               tempUnitsConversor = new UnitsConversor(){
+               tempUnitsConversor = new TempUnitsConversor(){
 
                                @Override
                                public double doConversion(final double value) {
@@ -134,7 +139,7 @@ public class SpecificFragment extends Fragment {
                };
         } else if (unitsPreferenceValue.equals(values[1])) {
                tempSymbol = values[1];
-               tempUnitsConversor = new UnitsConversor(){
+               tempUnitsConversor = new TempUnitsConversor(){
 
                                @Override
                                public double doConversion(final double value) {
@@ -144,7 +149,7 @@ public class SpecificFragment extends Fragment {
                };
         } else {
                tempSymbol = values[2];
-               tempUnitsConversor = new UnitsConversor(){
+               tempUnitsConversor = new TempUnitsConversor(){
 
                                @Override
                                public double doConversion(final double value) {
@@ -155,10 +160,30 @@ public class SpecificFragment extends Fragment {
         }
 
         // 1.2 Wind
+        String windSymbol;
+        WindUnitsConversor windUnitsConversor;
         keyPreference = this.getResources().getString(R.string.weather_preferences_wind_key);
-        final String windSymbol = sharedPreferences.getString(
-                       keyPreference,
-                       this.getResources().getStringArray(R.array.weather_preferences_wind)[0]);
+        unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
+        values = this.getResources().getStringArray(R.array.weather_preferences_wind);
+        if (unitsPreferenceValue.equals(values[0])) {
+               windSymbol = values[0];
+               windUnitsConversor = new WindUnitsConversor(){
+
+                       @Override
+                       public double doConversion(double value) {
+                               return value;
+                       }       
+               };
+        } else {
+               windSymbol = values[1];
+               windUnitsConversor = new WindUnitsConversor(){
+
+                       @Override
+                       public double doConversion(double value) {
+                               return value * 2.237;
+                       }       
+               };
+        }
 
 
         // 2. Formatters
@@ -218,7 +243,8 @@ public class SpecificFragment extends Fragment {
         }
         String windValue = "";
         if (forecast.getSpeed() != null) {
-            final double conversion = (Double) forecast.getSpeed();
+            double conversion = (Double) forecast.getSpeed();
+            conversion = windUnitsConversor.doConversion(conversion);
             windValue = tempFormatter.format(conversion);
         }
         String rainValue = "";