Exemplo n.º 1
0
        private void BtnSearch_Click(object sender, System.EventArgs e)
        {
            try
            {
                // Searched for city typed \\
                string city = txtSearch.Text;

                RestHandler objrest = new RestHandler();
                root    = objrest.ExecuteRequest(city);
                rootDay = objrest.ExecuteRequestCurrent(city);

                LoadHamilton();
                Image();
                LoadDay(1);
                LoadDay(2);
                LoadDay(3);
                LoadDay(4);
                LoadDay(5);
            }
            catch
            {
                Toast.MakeText(this, txtSearch.Text + " not found please try a larger town", ToastLength.Long).Show();
                return;
            }
        }
Exemplo n.º 2
0
        private void BtnGPS_Click(object sender, System.EventArgs e)
        {
            // Gets current GPS location \\
            getGpsAsync();


            try
            {
                // Searched for city typed \\
                string city = txtSearch.Text;

                RestHandler objrest = new RestHandler();
                root    = objrest.ExecuteRequestlatlong(latitude, longitude);
                rootDay = objrest.ExecuteRequestCurrentlatlong(latitude, longitude);

                LoadHamilton();
                Image();
                LoadDay(1);
                LoadDay(2);
                LoadDay(3);
                LoadDay(4);
                LoadDay(5);
            }
            catch
            {
                Toast.MakeText(this, "GPS location not found please move closer to a town and try again", ToastLength.Long).Show();
                return;
            }
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            txtSearch      = FindViewById <EditText>(Resource.Id.txtSearch);
            btnSearch      = FindViewById <Button>(Resource.Id.btnSearch);
            btnGPS         = FindViewById <Button>(Resource.Id.btnGPS);
            txtCity        = FindViewById <TextView>(Resource.Id.txtCity);
            txtMain        = FindViewById <TextView>(Resource.Id.txtMain);
            txtTemp        = FindViewById <TextView>(Resource.Id.txtTemp);
            imgMain        = FindViewById <ImageView>(Resource.Id.imgMain);
            txtDescription = FindViewById <TextView>(Resource.Id.txtDescription);
            imgDay1        = FindViewById <ImageView>(Resource.Id.imgDay1);
            imgDay2        = FindViewById <ImageView>(Resource.Id.imgDay2);
            imgDay3        = FindViewById <ImageView>(Resource.Id.imgDay3);
            imgDay4        = FindViewById <ImageView>(Resource.Id.imgDay4);
            imgDay5        = FindViewById <ImageView>(Resource.Id.imgDay5);
            txtDay1        = FindViewById <TextView>(Resource.Id.txtDay1);
            txtDay2        = FindViewById <TextView>(Resource.Id.txtDay2);
            txtDay3        = FindViewById <TextView>(Resource.Id.txtDay3);
            txtDay4        = FindViewById <TextView>(Resource.Id.txtDay4);
            txtDay5        = FindViewById <TextView>(Resource.Id.txtDay5);
            txtDetails1    = FindViewById <TextView>(Resource.Id.txtDetails1);
            txtDetails2    = FindViewById <TextView>(Resource.Id.txtDetails2);
            txtDetails3    = FindViewById <TextView>(Resource.Id.txtDetails3);
            txtDetails4    = FindViewById <TextView>(Resource.Id.txtDetails4);
            txtDetails5    = FindViewById <TextView>(Resource.Id.txtDetails5);


            btnGPS.Click          += BtnGPS_Click;
            btnSearch.Click       += BtnSearch_Click;
            txtSearch.TextChanged += TxtSearch_TextChanged;

            // Call Hamilton \\
            RestHandler objrest = new RestHandler();

            root    = objrest.ExecuteRequest("Hamilton");
            rootDay = objrest.ExecuteRequestCurrent("Hamilton");

            LoadHamilton();
            Image();

            // 5 Day forcast \\
            int[] imresid = { Resource.Id.imgDay1, Resource.Id.imgDay2, Resource.Id.imgDay3, Resource.Id.imgDay4, Resource.Id.imgDay5 };

            for (int i = 0; i < 5; i++)
            {
                img[i] = FindViewById <ImageView>(imresid[i]);
            }
            LoadDay(1);
            LoadDay(2);
            LoadDay(3);
            LoadDay(4);
            LoadDay(5);
        }
Exemplo n.º 4
0
        public CurrentDay.RootObject ExecuteRequestCurrentlatlong(double lat, double lng)
        {
            var client = new RestClient("http://api.openweathermap.org/data/2.5/weather?APPID=eda779a0530f5471405b6257cb0bf2f1&lat=" + lat + "&lon=" + lng + "&units=metric");

            RestRequest   request  = new RestRequest();
            IRestResponse response = client.Execute(request);

            CurrentDay.RootObject obj = new CurrentDay.RootObject();
            obj = JsonConvert.DeserializeObject <CurrentDay.RootObject>(response.Content);

            return(obj);
        }