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"
<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>
<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>
<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…</string>
<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">
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
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)
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
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)
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
} 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);
}
}
}
.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();
} 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")),
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
// 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) {
};
} else if (unitsPreferenceValue.equals(values[1])) {
tempSymbol = values[1];
- tempUnitsConversor = new UnitsConversor(){
+ tempUnitsConversor = new TempUnitsConversor(){
@Override
public double doConversion(final double value) {
};
} else {
tempSymbol = values[2];
- tempUnitsConversor = new UnitsConversor(){
+ tempUnitsConversor = new TempUnitsConversor(){
@Override
public double doConversion(final double value) {
}
// 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
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 = "";
// 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);
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) {
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
}
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);
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)) {
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);
}
}
- 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
// 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) {
};
} else if (unitsPreferenceValue.equals(values[1])) {
tempSymbol = values[1];
- tempUnitsConversor = new UnitsConversor(){
+ tempUnitsConversor = new TempUnitsConversor(){
@Override
public double doConversion(final double value) {
};
} else {
tempSymbol = values[2];
- tempUnitsConversor = new UnitsConversor(){
+ tempUnitsConversor = new TempUnitsConversor(){
@Override
public double doConversion(final double value) {
}
// 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
}
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 = "";