Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,42 @@
* ForecastIO code provider. It converts the owm weather code to the unified code system provided by this library
*
* @author Francesco Azzola
* @author Chris Watts
* */
public class ForecastIOCodeProvider implements IWeatherCodeProvider {
@Override
public WeatherCode getWeatherCode(String weatherCode) {
return null;
if (weatherCode == null)
return WeatherCode.NOT_AVAILABLE;

if (weatherCode.equalsIgnoreCase("clear-day"))
return WeatherCode.SUNNY;
else if (weatherCode.equalsIgnoreCase("clear-night"))
return WeatherCode.CLEAR_NIGHT;
else if (weatherCode.equalsIgnoreCase("rain"))
return WeatherCode.SHOWERS;
else if (weatherCode.equalsIgnoreCase("snow"))
return WeatherCode.SNOW;
else if (weatherCode.equalsIgnoreCase("sleet"))
return WeatherCode.SLEET;
else if (weatherCode.equalsIgnoreCase("wind"))
return WeatherCode.WINDY;
else if (weatherCode.equalsIgnoreCase("fog"))
return WeatherCode.FOGGY;
else if (weatherCode.equalsIgnoreCase("cloudy"))
return WeatherCode.CLOUDY;
else if (weatherCode.equalsIgnoreCase("partly-cloudy-day"))
return WeatherCode.PARTLY_CLOUDY_DAY;
else if (weatherCode.equalsIgnoreCase("partly-cloudy-night"))
return WeatherCode.PARTLY_CLOUDY_NIGHT;
else if (weatherCode.equalsIgnoreCase("hail"))
return WeatherCode.HAIL;
else if (weatherCode.equalsIgnoreCase("thunderstorm"))
return WeatherCode.THUNDERSTORMS;
else if (weatherCode.equalsIgnoreCase("tornado"))
return WeatherCode.TORNADO;
else
return WeatherCode.NOT_AVAILABLE;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ public class ForecastIOWeatherProvider implements IWeatherProvider {
private CurrentWeather cWeather;
private WeatherHourForecast whf;
private WeatherForecast forecast;
private IWeatherCodeProvider codeProvider;
private long lastUpdate;


Expand Down Expand Up @@ -136,7 +137,7 @@ public void setConfig(WeatherConfig config) {

@Override
public void setWeatherCodeProvider(IWeatherCodeProvider codeProvider) {

this.codeProvider = codeProvider;
}

@Override
Expand Down Expand Up @@ -243,7 +244,13 @@ private Weather parseWeather(JSONObject jsonWeather) throws JSONException {
weather.currentCondition.setDescr(jsonWeather.optString("summary"));
weather.currentCondition.setIcon(jsonWeather.optString("icon"));


if (codeProvider != null) {
try {
weather.currentCondition.setWeatherCode(codeProvider.getWeatherCode(weather.currentCondition.getIcon()));
} catch (Throwable t) {
weather.currentCondition.setWeatherCode(WeatherCode.NOT_AVAILABLE);
}
}

weather.rain[0].setAmmount((float) jsonWeather.optDouble("precipIntensity"));

Expand Down