WeatherRequest, holding both
information, the
library will select the city id to create the query.| Openweathermap | Yes |
| Weatherunderground Weather.com |
Yes |
| Yahoo! Weather | Yes |
| Forecast.io | Yes |
WeatherRequest req = new WeatherRequest(cityId);
weatherClient.getCurrentCondition(req, new WeatherClient.WeatherEventListener() {
@Override
public void onWeatherRetrieved(CurrentWeather cWeather) {
Weather weather = cWeather.weather;
// The weather condition object is ready and we can use it
}
@Override
public void onWeatherError(WeatherLibException t) {
// Something went wrong maybe we should inform the user
}
@Override
public void onConnectionError(Throwable t) {
// There was a connection error
}
});
onWeatherRetrieved(CurrentWeather cWeather) is called as soon as the data
is ready.
public class Weather {
public Location location = new Location();
public Condition currentCondition = new Condition();
public Temperature temperature = new Temperature();
public Wind wind = new Wind();
public Rain[] rain = {new Rain(), new Rain()};
public Snow snow = new Snow();
public Clouds clouds = new Clouds();
..
}
onWeatherRetrieved in your Android weather app, you
should fill your Android UI app:
weatherClient.getCurrentCondition(req, new WeatherClient.WeatherEventListener() {
@Override
public void onWeatherRetrieved(CurrentWeather cWeather) {
Weather weather = cWeather.weather;
getListener().requestCompleted();
cityText.setText(weather.location.getCity() + "," + weather.location.getCountry());
condDescr.setText(weather.currentCondition.getCondition() + "(" + weather.currentCondition.getDescr() + ")");
LogUtils.LOGD("SwA", "Temp [" + temp + "]");
LogUtils.LOGD("SwA", "Val [" + weather.temperature.getTemp() + "]");
temp.setText("" + ((int) weather.temperature.getTemp()));
unitTemp.setText(cWeather.getUnit().tempUnit);
colorTextLine.setBackgroundResource(WeatherUtil.getResource(weather.temperature.getTemp(), config));
hum.setText(weather.currentCondition.getHumidity() + "%");
tempMin.setText(weather.temperature.getMinTemp() + cWeather.getUnit().tempUnit);
tempMax.setText(weather.temperature.getMaxTemp() + cWeather.getUnit().tempUnit);
windSpeed.setText(weather.wind.getSpeed() + cWeather.getUnit().speedUnit);
windDeg.setText((int) weather.wind.getDeg() + "° (" + WindDirection.getDir((int) weather.wind.getDeg()) + ")");
press.setText(weather.currentCondition.getPressure() + cWeather.getUnit().pressureUnit);
sunrise.setText(WeatherUtil.convertDate(weather.location.getSunrise()));
sunset.setText(WeatherUtil.convertDate(weather.location.getSunset()));
....
}
}