android:layout_gravity="start"
android:layout_margin="5dp"
android:gravity="start"
- android:text="FEELS LIKE"
+ android:text="@string/text_field_feels_like"
android:textAlignment="textStart"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/weather_time_of_day_color_title"
android:id="@+id/weather_current_snow"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="SNOW"
+ android:text="@string/text_field_snow"
android:gravity="end"
android:layout_gravity="end"
android:textAlignment="textEnd"
android:layout_gravity="start"
android:layout_margin="5dp"
android:gravity="start"
- android:text="HUMIDITY"
+ android:text="@string/text_field_humidity"
android:textAlignment="textStart"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/weather_time_of_day_color_title"
android:id="@+id/weather_current_rain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="RAIN"
+ android:text="@string/text_field_rain"
android:layout_gravity="end"
android:gravity="end"
android:textAlignment="textEnd"
android:id="@+id/weather_current_wind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="WIND"
+ android:text="@string/text_field_wind"
android:layout_gravity="start"
android:gravity="start"
android:textAlignment="textStart"
android:id="@+id/weather_current_clouds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="CLOUDS"
+ android:text="@string/text_field_clouds"
android:layout_gravity="end"
android:gravity="end"
android:textAlignment="textEnd"
android:id="@+id/weather_current_pressure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="PRESSURE"
+ android:text="@string/text_field_pressure"
android:layout_gravity="center"
android:gravity="center"
android:textAlignment="center"
android:id="@+id/weather_current_sunrise"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="SUN RISE"
+ android:text="@string/text_field_sun_rise"
android:layout_gravity="center"
android:gravity="center"
android:textAlignment="center"
android:id="@+id/weather_current_sunset"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="SUN SET"
+ android:text="@string/text_field_sun_set"
android:layout_gravity="center"
android:gravity="center"
android:textAlignment="center"
android:layout_gravity="start"
android:layout_margin="5dp"
android:gravity="start"
- android:text="HUMIDITY"
+ android:text="@string/text_field_humidity"
android:textAlignment="textStart"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="@color/weather_time_of_day_color_title"
android:id="@+id/weather_specific_rain"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="RAIN"
+ android:text="@string/text_field_rain"
android:layout_gravity="end"
android:gravity="end"
android:textAlignment="textEnd"
android:id="@+id/weather_specific_wind"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="WIND"
+ android:text="@string/text_field_wind"
android:layout_gravity="start"
android:gravity="start"
android:textAlignment="textStart"
android:id="@+id/weather_specific_clouds"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="CLOUDS"
+ android:text="@string/text_field_clouds"
android:layout_gravity="end"
android:gravity="end"
android:textAlignment="textEnd"
android:id="@+id/weather_specific_pressure"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
- android:text="PRESSURE"
+ android:text="@string/text_field_pressure"
android:layout_gravity="center"
android:gravity="center"
android:textAlignment="center"
<?xml version="1.0" encoding="utf-8"?>
<resources>
<string-array name="weather_preferences_units_value">
- <item>Celsius</item>
- <item>Fahrenheit</item>
+ <item>ºC</item>
+ <item>ºF</item>
+ <item>K</item>
</string-array>
<string-array name="weather_preferences_units_human_value">
<item>Celsius</item>
<item>Fahrenheit</item>
+ <item>Kelvin</item>
</string-array>
<string-array name="weather_preferences_language_value">
<item>ar</item>
<item>half day</item>
<item>one day</item>
</string-array>
- <string-array name="weather_preferences_refresh_interval">
+ <string-array name="weather_preferences_refresh_interval">
<item>300000</item>
<item>900000</item>
<item>1800000</item>
<item>half day</item>
<item>one day</item>
</string-array>
+ <string-array name="weather_preferences_wind">
+ <item>m/s</item>
+ <item>mph</item>
+ </string-array>
+ <string-array name="weather_preferences_wind_human_value">
+ <item>meter per second</item>
+ <item>miles per hour</item>
+ </string-array>
</resources>
<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_fahrenheit">Fahrenheit</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_day_forecast">Forecast days number</string>
<string name="weather_preferences_refresh_interval_key">weather_preferences_refresh_interval</string>
<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="city_not_found">city not found</string>
<string name="country_not_found">country not found</string>
<string name="progress_dialog_generic_message">Please wait…</string>
<string name="weather_map_button_getlocation">Get Location</string>
<string name="text_units_mm3h">mm 3h</string>
<string name="text_units_percent">%</string>
- <string name="text_units_centigrade">ºC</string>
- <string name="text_units_ms">m/s</string>
<string name="text_units_hpa">hpa</string>
<string name="text_field_remote_error">No data available</string>
</resources>
android:entryValues="@array/weather_preferences_units_value"
android:selectable="true"
android:persistent="true"
- android:defaultValue="Celsius" />
+ android:defaultValue="@string/weather_preferences_units_celsius" />
+ <ListPreference android:key="@string/weather_preferences_wind_key"
+ android:entryValues="@array/weather_preferences_wind_human_value"
+ android:entries="@array/weather_preferences_wind"
+ android:title="@string/weather_preferences_wind"/>
</PreferenceCategory>
<PreferenceCategory android:title="@string/weather_preferences_notifications">
<SwitchPreference android:key="@string/weather_preferences_notifications_switch_key"
super.onPause();
}
+ private interface UnitsConversor {
+
+ public double doConversion(final double value);
+ }
+
private void updateUI(final Current current) {
final SharedPreferences sharedPreferences = PreferenceManager
// 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;
+ // 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";
+
+ // 1.2 Wind
+ 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]);
// 2. Formatters
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)
String feelsLike = "";
if (current.getMain().getTemp() != null) {
double conversion = (Double) current.getMain().getTemp();
- conversion = conversion - tempUnits;
+ conversion = tempUnitsConversor.doConversion(conversion);
feelsLike = tempFormatter.format(conversion);
}
String sunRiseTime = "";
((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(
- this.getActivity().getApplicationContext().getString(R.string.text_units_ms));
+ ((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_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(
- this.getActivity().getApplicationContext().getString(R.string.text_units_centigrade));
+ ((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));
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("");
}
}
+ private interface UnitsConversor {
+
+ public double doConversion(final double value);
+ }
+
private void updateUI(final Forecast forecastWeatherData) {
final SharedPreferences sharedPreferences = PreferenceManager
// TODO: repeating the same code in Overview, Specific and Current!!!
// 1. Update units of measurement.
- boolean isFahrenheit = false;
- String keyPreference = this.getResources()
- .getString(R.string.weather_preferences_units_key);
- final String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "Celsius");
- final String celsius = this.getResources().getString(
- R.string.weather_preferences_units_celsius);
- if (unitsPreferenceValue.equals(celsius)) {
- isFahrenheit = false;
+ String symbol;
+ UnitsConversor unitsConversor;
+ String keyPreference = this.getResources().getString(
+ R.string.weather_preferences_units_key);
+ final String unitsPreferenceValue = sharedPreferences.getString(keyPreference, "");
+ String[] values = this.getResources().getStringArray(R.array.weather_preferences_units_value);
+ if (unitsPreferenceValue.equals(values[0])) {
+ symbol = values[0];
+ unitsConversor = new UnitsConversor(){
+
+ @Override
+ public double doConversion(final double value) {
+ return value - 273.15;
+ }
+
+ };
+ } else if (unitsPreferenceValue.equals(values[1])) {
+ symbol = values[1];
+ unitsConversor = new UnitsConversor(){
+
+ @Override
+ public double doConversion(final double value) {
+ return (value * 1.8) - 459.67;
+ }
+
+ };
} else {
- isFahrenheit = true;
+ symbol = values[2];
+ unitsConversor = new UnitsConversor(){
+
+ @Override
+ public double doConversion(final double value) {
+ return value;
+ }
+
+ };
}
- final double tempUnits = isFahrenheit ? 0 : 273.15;
- final String symbol = isFahrenheit ? "ºF" : "ºC";
// 2. Update number day forecast.
- int mDayForecast;
- keyPreference = this.getResources()
- .getString(R.string.weather_preferences_day_forecast_key);
+ keyPreference = this.getResources().getString(R.string.weather_preferences_day_forecast_key);
final String dayForecast = sharedPreferences.getString(keyPreference, "5");
- mDayForecast = Integer.valueOf(dayForecast);
+ final int mDayForecast = Integer.valueOf(dayForecast);
// 3. Formatters
Double maxTemp = null;
if (forecast.getTemp().getMax() != null) {
maxTemp = (Double) forecast.getTemp().getMax();
- maxTemp = maxTemp - tempUnits;
+ maxTemp = unitsConversor.doConversion(maxTemp);
}
Double minTemp = null;
if (forecast.getTemp().getMin() != null) {
minTemp = (Double) forecast.getTemp().getMin();
- minTemp = minTemp - tempUnits;
+ minTemp = unitsConversor.doConversion(minTemp);
}
if ((maxTemp != null) && (minTemp != null)) {
this.addPreferencesFromResource(R.xml.weather_preferences);
- // 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 keyPreference = this.getActivity().getApplicationContext().getString(
R.string.weather_preferences_units_key);
Preference connectionPref = this.findPreference(keyPreference);
- connectionPref.setSummary(this.getPreferenceManager()
- .getSharedPreferences().getString(keyPreference, ""));
+ String value = this.getPreferenceManager().getSharedPreferences()
+ .getString(keyPreference, "");
+ 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);
// 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);
keyPreference = this.getActivity().getApplicationContext().getString(
R.string.weather_preferences_update_time_rate_key);
connectionPref = this.findPreference(keyPreference);
- String value = this.getPreferenceManager().getSharedPreferences()
+ value = this.getPreferenceManager().getSharedPreferences()
.getString(keyPreference, "");
- String humanValue = "";
+ humanValue = "";
if (value.equals(values[0])) {
humanValue = humanValues[0];
} else if (value.equals(values[1])) {
}
}
-
+ private interface UnitsConversor {
+
+ public double doConversion(final double value);
+ }
+
private void updateUI(final Forecast forecastWeatherData, final int chosenDay) {
final SharedPreferences sharedPreferences = PreferenceManager
// TODO: repeating the same code in Overview, Specific and Current!!!
// 1. Update units of measurement.
- boolean isFahrenheit = false;
- final String keyPreference = this.getResources().getString(
+ // 1.1 Temperature
+ String tempSymbol;
+ UnitsConversor tempUnitsConversor;
+ 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)) {
- isFahrenheit = false;
+ 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 {
- isFahrenheit = true;
+ tempSymbol = values[2];
+ tempUnitsConversor = new UnitsConversor(){
+
+ @Override
+ public double doConversion(final double value) {
+ return value;
+ }
+
+ };
}
- final double tempUnits = isFahrenheit ? 0 : 273.15;
- final String symbol = isFahrenheit ? "ºF" : "ºC";
-
-
+
+ // 1.2 Wind
+ 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]);
+
+
// 2. Formatters
final DecimalFormat tempFormatter = (DecimalFormat) NumberFormat.getNumberInstance(Locale.US);
tempFormatter.applyPattern("#####.#####");
String tempMax = "";
if (forecast.getTemp().getMax() != null) {
double conversion = (Double) forecast.getTemp().getMax();
- conversion = conversion - tempUnits;
- tempMax = tempFormatter.format(conversion) + symbol;
+ conversion = tempUnitsConversor.doConversion(conversion);
+ tempMax = tempFormatter.format(conversion) + tempSymbol;
}
String tempMin = "";
if (forecast.getTemp().getMin() != null) {
double conversion = (Double) forecast.getTemp().getMin();
- conversion = conversion - tempUnits;
- tempMin = tempFormatter.format(conversion) + symbol;
+ conversion = tempUnitsConversor.doConversion(conversion);
+ tempMin = tempFormatter.format(conversion) + tempSymbol;
}
Bitmap picture;
if ((forecast.getWeather().size() > 0) && (forecast.getWeather().get(0).getIcon() != null)
String tempDay = "";
if (forecast.getTemp().getDay() != null) {
double conversion = (Double) forecast.getTemp().getDay();
- conversion = conversion - tempUnits;
- tempDay = tempFormatter.format(conversion) + symbol;
+ conversion = tempUnitsConversor.doConversion(conversion);
+ tempDay = tempFormatter.format(conversion) + tempSymbol;
}
String tempMorn = "";
if (forecast.getTemp().getMorn() != null) {
double conversion = (Double) forecast.getTemp().getMorn();
- conversion = conversion - tempUnits;
- tempMorn = tempFormatter.format(conversion) + symbol;
+ conversion = tempUnitsConversor.doConversion(conversion);
+ tempMorn = tempFormatter.format(conversion) + tempSymbol;
}
String tempEve = "";
if (forecast.getTemp().getEve() != null) {
double conversion = (Double) forecast.getTemp().getEve();
- conversion = conversion - tempUnits;
- tempEve = tempFormatter.format(conversion) + symbol;
+ conversion = tempUnitsConversor.doConversion(conversion);
+ tempEve = tempFormatter.format(conversion) + tempSymbol;
}
String tempNight = "";
if (forecast.getTemp().getNight() != null) {
double conversion = (Double) forecast.getTemp().getNight();
- conversion = conversion - tempUnits;
- tempNight = tempFormatter.format(conversion) + symbol;
+ conversion = tempUnitsConversor.doConversion(conversion);
+ tempNight = tempFormatter.format(conversion) + tempSymbol;
}
humidityValueView.setText(humidityValue);
final TextView pressureValueView = (TextView) getActivity().findViewById(R.id.weather_specific_pressure_value);
pressureValueView.setText(pressureValue);
- final TextView windValueView = (TextView) getActivity().findViewById(R.id.weather_specific_wind_value);
- windValueView.setText(windValue);
+ ((TextView) getActivity().findViewById(R.id.weather_specific_wind_value)).setText(windValue);;
+ ((TextView) getActivity().findViewById(R.id.weather_specific_wind_units)).setText(windSymbol);
final TextView rainValueView = (TextView) getActivity().findViewById(R.id.weather_specific_rain_value);
rainValueView.setText(rainValue);
final TextView cloudsValueView = (TextView) getActivity().findViewById(R.id.weather_specific_clouds_value);