コード例 #1
0
        private List <Classes.ItemDisplay> PopulateList(Classes.Forecast forecast)
        {
            DateTime unix;

            weatherList.Add(new Classes.ItemDisplay("Wind", CalculateWindSpeed(forecast.Wind.Speed) + "\n" + CalculateWindDirection(forecast.Wind.Deg)));
            weatherList.Add(new Classes.ItemDisplay("Cloudiness", (forecast.Weather[0].Description.Substring(0, 1).ToUpper()) + forecast.Weather[0].Description.Substring(1, forecast.Weather[0].Description.Length - 1) + ""));
            weatherList.Add(new Classes.ItemDisplay("Pressure", forecast.Main.Pressure + " hpa"));
            weatherList.Add(new Classes.ItemDisplay("Humidity", forecast.Main.Humidity + " %"));
            unix = (new DateTime(1970, 1, 1)).AddMilliseconds((double)forecast.Sys.Sunrise * 1000L);
            weatherList.Add(new Classes.ItemDisplay("Sunrise", string.Format("{0:t}", unix)));
            unix = (new DateTime(1970, 1, 1)).AddMilliseconds((double)forecast.Sys.Sunset * 1000L);
            weatherList.Add(new Classes.ItemDisplay("Sunset", string.Format("{0:t}", unix)));
            weatherList.Add(new Classes.ItemDisplay("Geo Coords", "[ " + forecast.Coord.Lat + ", " + forecast.Coord.Lon + " ]"));
            return(weatherList);
        }
コード例 #2
0
        protected async override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            SetContentView(Resource.Layout.Weather_Detail);

            ProgressBar loader = FindViewById <ProgressBar>(Resource.Id.loader);
            DateTime    time   = (new DateTime(1970, 1, 1, 2, 0, 0)).AddMilliseconds((double)forecast.DT * 1000L);

            searchedCityName = Intent.GetStringExtra("City");
            TextView cityName  = FindViewById <TextView>(Resource.Id.cityName);
            TextView tempDeg   = FindViewById <TextView>(Resource.Id.tempDeg);
            TextView condition = FindViewById <TextView>(Resource.Id.condition);
            TextView updated   = FindViewById <TextView>(Resource.Id.updated);
            View     line      = FindViewById <View>(Resource.Id.view);

            icon = FindViewById <ImageView>(Resource.Id.weatherIcon);

            while (true)
            {
                loader.Visibility = ViewStates.Visible;

                forecast = await getForecast.toForecast(searchedCityName);

                if (forecast.Name != null)
                {
                    cityName.Text = ("Weather in " + forecast.Name + ", " + forecast.Sys.Country);
                    String iconURL     = "http://openweathermap.org/img/w/" + forecast.Weather[0].Icon + ".png";
                    var    imageBitmap = GetImageFromUrl(iconURL);
                    icon.SetImageBitmap(imageBitmap);

                    tempDeg.Text   = ((forecast.Main.Temp - 273.15) + " °C");
                    condition.Text = ((forecast.Weather[0].Description.Substring(0, 1).ToUpper()) + forecast.Weather[0].Description.Substring(1, forecast.Weather[0].Description.Length - 1) + "");
                    updated.Text   = ("Last updated: " + string.Format("{0:g}", time));

                    //Populating list view start
                    ListView           myListView         = FindViewById <ListView>(Resource.Id.listView);
                    WeatherListAdapter weatherListAdapter = new WeatherListAdapter(this, PopulateList(forecast));
                    myListView.Adapter   = weatherListAdapter;
                    loader.Visibility    = ViewStates.Invisible;
                    cityName.Visibility  = ViewStates.Visible;
                    tempDeg.Visibility   = ViewStates.Visible;
                    condition.Visibility = ViewStates.Visible;
                    updated.Visibility   = ViewStates.Visible;
                    line.Visibility      = ViewStates.Visible;
                    break;
                }
            }
        }