protected async void LoadFiveDaysData(string cname) { try { AndHUD.Shared.Show(this, "Loading…"); objRest = new RESTHandler(@"http://api.openweathermap.org/data/2.5/forecast/daily?q=" + cname + ",NZ&units=metric&mode=xml&APPID=c994843656995893a09a3f2f8d1451cd"); var Response = await objRest.ExecuteFiveDaysAsync(); txtTemp1.Text = Math.Round(Convert.ToDecimal(Response.Forecast.Time [1].Temperature.Max), 0) + "°C / " + Math.Round(Convert.ToDecimal(Response.Forecast.Time [1].Temperature.Min), 0) + "°C"; txtTemp2.Text = Math.Round(Convert.ToDecimal(Response.Forecast.Time [2].Temperature.Max), 0) + "°C / " + Math.Round(Convert.ToDecimal(Response.Forecast.Time [2].Temperature.Min), 0) + "°C"; txtTemp3.Text = Math.Round(Convert.ToDecimal(Response.Forecast.Time [3].Temperature.Max), 0) + "°C / " + Math.Round(Convert.ToDecimal(Response.Forecast.Time [3].Temperature.Min), 0) + "°C"; txtTemp4.Text = Math.Round(Convert.ToDecimal(Response.Forecast.Time [4].Temperature.Max), 0) + "°C / " + Math.Round(Convert.ToDecimal(Response.Forecast.Time [4].Temperature.Min), 0) + "°C"; txtDate1.Text = Convert.ToDateTime(Response.Forecast.Time[1].Day).ToString("dd/MM"); txtDate2.Text = Convert.ToDateTime(Response.Forecast.Time[2].Day).ToString("dd/MM"); txtDate3.Text = Convert.ToDateTime(Response.Forecast.Time[3].Day).ToString("dd/MM"); txtDate4.Text = Convert.ToDateTime(Response.Forecast.Time[4].Day).ToString("dd/MM"); lstImages.Add(imgWeather0); lstImages.Add(imgWeather1); lstImages.Add(imgWeather2); lstImages.Add(imgWeather3); lstImages.Add(imgWeather4); lstTextViews.Add(txtTime); lstTextViews.Add(txtDate1); lstTextViews.Add(txtDate2); lstTextViews.Add(txtDate3); lstTextViews.Add(txtDate4); for (int i = 1; i < 5; i++) { if (Response.Forecast.Time[i].Symbol.Var == "01d") { lstImages[i].SetImageResource(Resource.Drawable.weather_clear); } else if (Response.Forecast.Time[i].Symbol.Var == "01n") { lstImages[i].SetImageResource(Resource.Drawable.weather_clear); } if (Response.Forecast.Time[i].Symbol.Var == "02d") { lstImages[i].SetImageResource(Resource.Drawable.weather_few_clouds); } else if (Response.Forecast.Time[i].Symbol.Var == "02n") { lstImages[i].SetImageResource(Resource.Drawable.weather_few_clouds); } if (Response.Forecast.Time[i].Symbol.Var == "03d") { lstImages[i].SetImageResource(Resource.Drawable.weather_clouds); } else if (Response.Forecast.Time[i].Symbol.Var == "03n") { lstImages[i].SetImageResource(Resource.Drawable.weather_clouds); } if (Response.Forecast.Time[i].Symbol.Var == "04d") { lstImages[i].SetImageResource(Resource.Drawable.weather_clouds); } else if (Response.Forecast.Time[i].Symbol.Var == "04n") { lstImages[i].SetImageResource(Resource.Drawable.weather_clouds); } if (Response.Forecast.Time[i].Symbol.Var == "09d" || Response.Forecast.Time[i].Symbol.Var == "09n") { lstImages[i].SetImageResource(Resource.Drawable.weather_showers_scattered_day); } if (Response.Forecast.Time[i].Symbol.Var == "10d") { lstImages[i].SetImageResource(Resource.Drawable.weather_showers_day); } else if (Response.Forecast.Time[i].Symbol.Var == "10n") { lstImages[i].SetImageResource(Resource.Drawable.weather_showers_day); } if (Response.Forecast.Time[i].Symbol.Var == "11d" || Response.Forecast.Time[i].Symbol.Var == "11d") { lstImages[i].SetImageResource(Resource.Drawable.weather_storm); } if (Response.Forecast.Time[i].Symbol.Var == "13d" || Response.Forecast.Time[i].Symbol.Var == "13d") { lstImages[i].SetImageResource(Resource.Drawable.weather_snow); } if (Response.Forecast.Time[i].Symbol.Var == "50d" || Response.Forecast.Time[i].Symbol.Var == "50d") { lstImages[i].SetImageResource(Resource.Drawable.weather_mist); } if (Convert.ToString(Convert.ToDateTime(Response.Forecast.Time[i].Day).DayOfWeek) == "Monday") { lstTextViews[i].Text = "Mon"; } if (Convert.ToString(Convert.ToDateTime(Response.Forecast.Time[i].Day).DayOfWeek) == "Tuesday") { lstTextViews[i].Text = "Tue"; } if (Convert.ToString(Convert.ToDateTime(Response.Forecast.Time[i].Day).DayOfWeek) == "Wednesday") { lstTextViews[i].Text = "Wed"; } if (Convert.ToString(Convert.ToDateTime(Response.Forecast.Time[i].Day).DayOfWeek) == "Thursday") { lstTextViews[i].Text = "Thu"; } if (Convert.ToString(Convert.ToDateTime(Response.Forecast.Time[i].Day).DayOfWeek) == "Friday") { lstTextViews[i].Text = "Fri"; } if (Convert.ToString(Convert.ToDateTime(Response.Forecast.Time[i].Day).DayOfWeek) == "Saturday") { lstTextViews[i].Text = "Sat"; } if (Convert.ToString(Convert.ToDateTime(Response.Forecast.Time[i].Day).DayOfWeek) == "Sunday") { lstTextViews[i].Text = "Sun"; } } AndHUD.Shared.Dismiss(this); } catch (Exception e) { Console.WriteLine("FiveDays Error: " + e.Message); } }
public async void LoadOneDayData(string cname) { try { AndHUD.Shared.Show(this, "Loading…"); objRest = new RESTHandler(@"http://api.openweathermap.org/data/2.5/find?q=" + cname + ",NZ&units=metric&mode=xml&APPID=c994843656995893a09a3f2f8d1451cd"); var ODResponse = await objRest.ExecuteOneDayAsync(); RunOnUiThread(() => { txtCity.Text = ODResponse.List.Item.City.Name; }); txtTemperature.Text = Math.Round(Convert.ToDecimal(ODResponse.List.Item.Temperature.Value), 0) + "°C"; txtDescription.Text = ODResponse.List.Item.Weather.Value; if (ODResponse.List.Item.Weather.Icon == "01d") { imgWeather0.SetImageResource(Resource.Drawable.weather_clear); } else if (ODResponse.List.Item.Weather.Icon == "01n") { imgWeather0.SetImageResource(Resource.Drawable.weather_clear_night); } if (ODResponse.List.Item.Weather.Icon == "02d") { imgWeather0.SetImageResource(Resource.Drawable.weather_few_clouds); } else if (ODResponse.List.Item.Weather.Icon == "02n") { imgWeather0.SetImageResource(Resource.Drawable.weather_few_clouds_night); } if (ODResponse.List.Item.Weather.Icon == "03d") { imgWeather0.SetImageResource(Resource.Drawable.weather_clouds); } else if (ODResponse.List.Item.Weather.Icon == "03n") { imgWeather0.SetImageResource(Resource.Drawable.weather_clouds_night); } if (ODResponse.List.Item.Weather.Icon == "04d") { imgWeather0.SetImageResource(Resource.Drawable.weather_clouds); } else if (ODResponse.List.Item.Weather.Icon == "04n") { imgWeather0.SetImageResource(Resource.Drawable.weather_clouds_night); } if (ODResponse.List.Item.Weather.Icon == "09d" || ODResponse.List.Item.Weather.Icon == "09n") { imgWeather0.SetImageResource(Resource.Drawable.weather_showers_scattered_day); } if (ODResponse.List.Item.Weather.Icon == "10d") { imgWeather0.SetImageResource(Resource.Drawable.weather_showers_day); } else if (ODResponse.List.Item.Weather.Icon == "10n") { imgWeather0.SetImageResource(Resource.Drawable.weather_showers_night); } if (ODResponse.List.Item.Weather.Icon == "11d" || ODResponse.List.Item.Weather.Icon == "11n") { imgWeather0.SetImageResource(Resource.Drawable.weather_storm); } if (ODResponse.List.Item.Weather.Icon == "13d" || ODResponse.List.Item.Weather.Icon == "13n") { imgWeather0.SetImageResource(Resource.Drawable.weather_snow); } if (ODResponse.List.Item.Weather.Icon == "50d" || ODResponse.List.Item.Weather.Icon == "50n") { imgWeather0.SetImageResource(Resource.Drawable.weather_mist); } AndHUD.Shared.Dismiss(this); } catch (Exception e) { Console.WriteLine("OneDay Error: " + e.Message); } }