From b43fea8af787141c76c7e5ceb76ff2952dd92fd4 Mon Sep 17 00:00:00 2001 From: ermau Date: Wed, 21 Aug 2013 14:04:49 -0400 Subject: [PATCH] Improve Android sample --- .../MainActivity.cs | 33 +++++++++++-------- .../Properties/AndroidManifest.xml | 5 ++- .../Resources/Resource.designer.cs | 23 ++++++------- .../Resources/layout/Main.axml | 5 --- .../Xamarin.Auth Sample (Android).csproj | 2 +- 5 files changed, 33 insertions(+), 35 deletions(-) diff --git a/samples/Xamarin.Auth.Sample.Android/MainActivity.cs b/samples/Xamarin.Auth.Sample.Android/MainActivity.cs index 9cb40e8b0..d7e988ebe 100644 --- a/samples/Xamarin.Auth.Sample.Android/MainActivity.cs +++ b/samples/Xamarin.Auth.Sample.Android/MainActivity.cs @@ -23,38 +23,45 @@ void LoginToFacebook (bool allowCancel) // If authorization succeeds or is canceled, .Completed will be fired. auth.Completed += (s, ee) => { if (!ee.IsAuthenticated) { - this.facebookStatus.Text = "Not Authenticated"; + var builder = new AlertDialog.Builder (this); + builder.SetMessage ("Not Authenticated"); + builder.SetPositiveButton ("Ok", (o, e) => { }); + builder.Create().Show(); return; } // Now that we're logged in, make a OAuth2 request to get the user's info. var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, ee.Account); request.GetResponseAsync().ContinueWith (t => { - if (t.IsFaulted) - this.facebookStatus.Text = "Error: " + t.Exception.InnerException.Message; - else if (t.IsCanceled) - this.facebookStatus.Text = "Canceled"; - else - { + var builder = new AlertDialog.Builder (this); + if (t.IsFaulted) { + builder.SetTitle ("Error"); + builder.SetMessage (t.Exception.Flatten().InnerException.ToString()); + } else if (t.IsCanceled) + builder.SetTitle ("Task Canceled"); + else { var obj = JsonValue.Parse (t.Result.GetResponseText()); - this.facebookStatus.Text = "Logged in as " + obj["name"]; + + builder.SetTitle ("Logged in"); + builder.SetMessage ("Name: " + obj["name"]); } - }, uiScheduler); + + builder.SetPositiveButton ("Ok", (o, e) => { }); + builder.Create().Show(); + }, UIScheduler); }; var intent = auth.GetUI (this); - StartActivityForResult (intent, 42); + StartActivity (intent); } - private TextView facebookStatus; - private readonly TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext(); + private static readonly TaskScheduler UIScheduler = TaskScheduler.FromCurrentSynchronizationContext(); protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); SetContentView (Resource.Layout.Main); - this.facebookStatus = FindViewById (Resource.Id.FacebookTextView); var facebook = FindViewById