예제 #1
0
        public async void BtnGetWeather_ClickAsync(object sender, System.EventArgs e)
        {
            cityName = etCity.Text.ToString();
            if (etCity.Text.ToString().Length > 0)
            {
                progressBar.Visibility = ViewStates.Visible;
                WeatherService weatherService = new WeatherService();
                var            result         = await weatherService.GetWeather(etCity.Text.ToString());

                //WeatherInfo.RootObject weatherInfo = new WeatherInfo.RootObject();
                //weatherInfo = result;
                if (result == null)
                {
                    progressBar.Visibility = ViewStates.Invisible;
                    Toast.MakeText(Application, "Cannot load data", ToastLength.Short).Show();
                }
                else
                {
                    progressBar.Visibility = ViewStates.Invisible;
                    Intent weather_details = new Intent(this, typeof(WeatherDetailsActivity));
                    weather_details.PutExtra("DATA", JsonConvert.SerializeObject(result));
                    StartActivity(weather_details);
                }
            }
            else
            {
                Toast.MakeText(Application, "Please type a city name", ToastLength.Short).Show();
            }
        }
예제 #2
0
        private static Current getWeatherXML()
        {
            Current current = new Current();
            WeatherService <Current> weatherService = new WeatherService <Current>();

            current = weatherService.GetWeather(true);
            return(current);
        }
예제 #3
0
        private static RootObject getWeatherJSON()
        {
            RootObject rootObject = new RootObject();
            WeatherService <RootObject> weatherService = new WeatherService <RootObject>();

            rootObject = weatherService.GetWeather(false);
            return(rootObject);
        }
예제 #4
0
        private void searchButton_Click(object sender, RoutedEventArgs e)
        {
            if (textBoxSearch.Text.Length == 0)
            {
                return;
            }
            if (textBoxSearch.Text == PlaceholderSearch)
            {
                return;
            }
            WeatherResult wr = WeatherService.GetWeather(textBoxSearch.Text);

            if (wr != null)
            {
                labelCityNameZip.Content = wr.cityState + " " + wr.zipCode;

                labelCityLatLong.Content = "Latitude/Longitude: "
                                           + wr.latitude + "/" + wr.longitude;

                labelWeatherCondition.Content = wr.weather;

                labelElevation.Content = "Elevation: " + wr.elevation;

                labelLastUpdated.Content = wr.lastUpdated;

                labelTemperature.Content = "Temperature: " + wr.temperature;

                labelFeelsLike.Content = "Feels Like: " + wr.feelsLike;

                labelWind.Content = "Wind: " + wr.wind;

                labelWindDirection.Content = "Wind Direction: " + wr.windDirection;

                labelHumidity.Content = "Humidity: " + wr.humidity;

                labelVisibility.Content = "Visibility: " + wr.visibility;

                labelUV.Content = "UV: " + wr.uv;

                labelPrecipitation.Content = "Precipitation: " + wr.precipitation;

                setWeatherImage(wr.iconURL, wr.icon);
            }
        }