Skip to content
This repository was archived by the owner on May 1, 2024. It is now read-only.

Commit b43fea8

Browse files
committed
Improve Android sample
1 parent 856941a commit b43fea8

File tree

5 files changed

+33
-35
lines changed

5 files changed

+33
-35
lines changed

samples/Xamarin.Auth.Sample.Android/MainActivity.cs

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -23,38 +23,45 @@ void LoginToFacebook (bool allowCancel)
2323
// If authorization succeeds or is canceled, .Completed will be fired.
2424
auth.Completed += (s, ee) => {
2525
if (!ee.IsAuthenticated) {
26-
this.facebookStatus.Text = "Not Authenticated";
26+
var builder = new AlertDialog.Builder (this);
27+
builder.SetMessage ("Not Authenticated");
28+
builder.SetPositiveButton ("Ok", (o, e) => { });
29+
builder.Create().Show();
2730
return;
2831
}
2932

3033
// Now that we're logged in, make a OAuth2 request to get the user's info.
3134
var request = new OAuth2Request ("GET", new Uri ("https://graph.facebook.com/me"), null, ee.Account);
3235
request.GetResponseAsync().ContinueWith (t => {
33-
if (t.IsFaulted)
34-
this.facebookStatus.Text = "Error: " + t.Exception.InnerException.Message;
35-
else if (t.IsCanceled)
36-
this.facebookStatus.Text = "Canceled";
37-
else
38-
{
36+
var builder = new AlertDialog.Builder (this);
37+
if (t.IsFaulted) {
38+
builder.SetTitle ("Error");
39+
builder.SetMessage (t.Exception.Flatten().InnerException.ToString());
40+
} else if (t.IsCanceled)
41+
builder.SetTitle ("Task Canceled");
42+
else {
3943
var obj = JsonValue.Parse (t.Result.GetResponseText());
40-
this.facebookStatus.Text = "Logged in as " + obj["name"];
44+
45+
builder.SetTitle ("Logged in");
46+
builder.SetMessage ("Name: " + obj["name"]);
4147
}
42-
}, uiScheduler);
48+
49+
builder.SetPositiveButton ("Ok", (o, e) => { });
50+
builder.Create().Show();
51+
}, UIScheduler);
4352
};
4453

4554
var intent = auth.GetUI (this);
46-
StartActivityForResult (intent, 42);
55+
StartActivity (intent);
4756
}
4857

49-
private TextView facebookStatus;
50-
private readonly TaskScheduler uiScheduler = TaskScheduler.FromCurrentSynchronizationContext();
58+
private static readonly TaskScheduler UIScheduler = TaskScheduler.FromCurrentSynchronizationContext();
5159

5260
protected override void OnCreate (Bundle bundle)
5361
{
5462
base.OnCreate (bundle);
5563
SetContentView (Resource.Layout.Main);
5664

57-
this.facebookStatus = FindViewById<TextView> (Resource.Id.FacebookTextView);
5865
var facebook = FindViewById<Button> (Resource.Id.FacebookButton);
5966
facebook.Click += delegate { LoginToFacebook(true);};
6067

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<manifest xmlns:android="http://schemas.android.com/apk/res/android" android:versionCode="1" android:versionName="1.0" package="Xamarin.Auth.Sample.Android">
3-
<uses-sdk android:minSdkVersion="7" />
4-
<application android:label="Xamarin.Auth Sample (Android)">
5-
</application>
3+
<uses-sdk android:minSdkVersion="8" />
4+
<application android:label="Xamarin.Auth Sample (Android)"></application>
65
<uses-permission android:name="android.permission.INTERNET" />
76
</manifest>

samples/Xamarin.Auth.Sample.Android/Resources/Resource.designer.cs

Lines changed: 10 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

samples/Xamarin.Auth.Sample.Android/Resources/layout/Main.axml

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,9 +13,4 @@
1313
android:layout_width="fill_parent"
1414
android:layout_height="wrap_content"
1515
android:id="@+id/FacebookButtonNoCancel" />
16-
<TextView
17-
android:textAppearance="?android:attr/textAppearanceMedium"
18-
android:layout_width="fill_parent"
19-
android:layout_height="wrap_content"
20-
android:id="@+id/FacebookTextView" />
2116
</LinearLayout>

samples/Xamarin.Auth.Sample.Android/Xamarin.Auth Sample (Android).csproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<AndroidApplication>True</AndroidApplication>
1616
<AndroidResgenFile>Resources\Resource.designer.cs</AndroidResgenFile>
1717
<AssemblyName>Xamarin.Auth.Sample.Android</AssemblyName>
18-
<TargetFrameworkVersion>v4.0.3</TargetFrameworkVersion>
18+
<TargetFrameworkVersion>v2.2</TargetFrameworkVersion>
1919
<AndroidManifest>Properties\AndroidManifest.xml</AndroidManifest>
2020
</PropertyGroup>
2121
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">

0 commit comments

Comments
 (0)