示例#1
0
        /// <summary>
        /// Method to intialize all the elements for view creation
        /// </summary>
        /// <param name="inflater"></param>
        /// <param name="container"></param>
        /// <param name="savedInstanceState"></param>
        /// <returns></returns>
        public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState)
        {
            try
            {
                if (Visiblity)
                {
                    mobjView = inflater.Inflate(Resource.Layout.CurrentWeather, container, false);
                    tvTime = mobjView.FindViewById<TextView>(Resource.Id.TimeText);
                    tvTemperature = mobjView.FindViewById<TextView>(Resource.Id.tempText);
                    tvhumidity = mobjView.FindViewById<TextView>(Resource.Id.humidText);
                    tvWeatherConditions = mobjView.FindViewById<TextView>(Resource.Id.condText);

                    mobjCurrentWeather = WeatherReport.GetCurrentInstance();

                    tvTime.Text = mobjCurrentWeather.Time.ToString(GlobalConstants.DateTimeFormat);
                    tvTemperature.Text = mobjCurrentWeather.Temperature.ToString() + GlobalConstants.FahrenheitKeyword;
                    tvhumidity.Text = mobjCurrentWeather.Humidity.ToString() + GlobalConstants.PercentageSymbol;
                    tvWeatherConditions.Text = mobjCurrentWeather.WeatherCondition;
                }
                return mobjView;
            }
            catch (Exception ex)
            {
                Toast.MakeText(Activity , GlobalConstants.ErrorMessage+ex.ToString(), ToastLength.Short);
            }
            return mobjView;
        }
示例#2
0
        /// <summary>
        /// Gets the current instance of this class
        /// </summary>
        /// <returns></returns>
        public static WeatherResponse GetCurrentInstance()
        {
            if (_currentWeather == null)
            {

                if (_currentWeather == null)
                {
                    _currentWeather = new WeatherResponse();
                }
            }
            return _currentWeather;
        }
示例#3
0
        /// <summary>
        /// Parses the weather data, then writes temperature, humidity, conditions, and 
        // location to the screen.
        /// </summary>
        /// <param name="json"></param>
        private void JSONParser(string json)
        {
            try
            {
                currentWeather = WeatherReport.GetCurrentInstance();
                JObject jsonResponseObject = JObject.Parse(json);
                JObject jsonCurrentObject = (JObject)jsonResponseObject["currently"];

                currentWeather.Time = unixTime.AddSeconds(Convert.ToDouble(jsonCurrentObject["time"].ToString())).ToLocalTime();
                currentWeather.WeatherCondition = Convert.ToString(jsonCurrentObject["summary"]);
                currentWeather.Temperature = Convert.ToDouble(jsonCurrentObject["temperature"].ToString());
                currentWeather.Humidity = Convert.ToDouble(jsonCurrentObject["humidity"].ToString());

                JObject jsonHourlyObject = (JObject)jsonResponseObject["hourly"];
                JArray jsonHourlyArray = (JArray)jsonHourlyObject["data"];

                hourlyWeather = WeatherReport.GetHourlyInstance();

                foreach (JObject jsonTempObj in jsonHourlyArray)
                {
                    WeatherResponse tempWeather = new WeatherResponse();
                    tempWeather.WeatherCondition = Convert.ToString(jsonTempObj["summary"]);
                    tempWeather.Temperature = Convert.ToDouble(jsonTempObj["temperature"].ToString());
                    tempWeather.Humidity = Convert.ToDouble(jsonTempObj["humidity"].ToString());
                    tempWeather.Time = unixTime.AddSeconds(Convert.ToDouble(jsonTempObj["time"].ToString())).ToLocalTime();
                    hourlyWeather.Add(tempWeather);
                }

                JObject jsonDailyObject = (JObject)jsonResponseObject["daily"];
                JArray jsonDailyArray = (JArray)jsonDailyObject["data"];

                dailyWeather = WeatherReport.GetDailynstance(); ;
                foreach (JObject jsonTempObj in jsonDailyArray)
                {
                    DayWeatherReport tempWeather = new DayWeatherReport();
                    tempWeather.Time = unixTime.AddSeconds(Convert.ToDouble(jsonTempObj["time"].ToString())).ToLocalTime();
                    tempWeather.WeatherCondition = Convert.ToString(jsonTempObj["summary"]);
                    tempWeather.MinTemperature = Convert.ToDouble(jsonTempObj["temperatureMin"].ToString());
                    tempWeather.MaxTemperature = Convert.ToDouble(jsonTempObj["temperatureMax"].ToString());
                    tempWeather.Humidity = Convert.ToDouble(jsonTempObj["humidity"].ToString());
                    dailyWeather.Add(tempWeather);
                }
            }

            catch (JsonException ex)
            {
                Toast.MakeText(this, GlobalConstants.ErrorMessage + ex.ToString(), ToastLength.Short);
            }
            catch( Exception ex)
            {
                Toast.MakeText(this, GlobalConstants.ErrorMessage + ex.ToString(), ToastLength.Short);
            }
        }