Example #1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

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

            // Get our button from the layout resource,
            // and attach an event to it
            Button button = FindViewById <Button> (Resource.Id.myButton);

            this.cancellation = new CancellationTokenSource();
            var reachability = new Reachability();

            reachability.Ping("http://www.yahoo.com", cancellation.Token, this).ContinueWith(t =>
            {
                Log.Info(t.ToString(), "Ping has ended");
            });

            reachability.IsHostReachable("http://dev.virtualearth.net", TimeSpan.FromMinutes(1)).ContinueWith(t =>
            {
                button.Enabled = t.Result;
            });

            DependencyResolver.Current.RegisterService <IJsonSerializer>(new SimplyMobile.Text.JsonNet.JsonSerializer());
            DependencyResolver.Current.RegisterService <IRestClient>(t =>
                                                                     new JsonClient(new HttpClient(new OkHttpNetworkHandler()),
                                                                                    t.GetService <IJsonSerializer>())
                                                                     );

            button.Click += async delegate
            {
                var bingClient = new BingClient(
                    "Apcl0Dzk-uwuqlIpDPjGLaA0oHXERDiGBuE3Vzxx3peRCr8gmSRPr-J6cij7U1pZ",
                    DependencyResolver.Current.GetService <IRestClient>()
                    );

                var response = await bingClient.Get(47.64054, -122.12934);

                if (response.StatusCode == System.Net.HttpStatusCode.OK)
                {
                    System.Diagnostics.Debug.WriteLine(response.Value.Copyright);
                    CreateIntent(response.Value);
                }
                else
                {
                    System.Diagnostics.Debug.WriteLine(response.Error.Message);
                }
            };
        }