-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMainActivity.cs
More file actions
58 lines (51 loc) · 2.63 KB
/
Copy pathMainActivity.cs
File metadata and controls
58 lines (51 loc) · 2.63 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
using Android.App;
using Android.Content;
using Android.Net;
using Android.OS;
using Android.Widget;
using Core;
namespace Phoneword
{
[Activity(Label = "Phoneword", MainLauncher = true, Icon = "@drawable/icon")]
public class MainActivity : Activity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
SetContentView(Resource.Layout.Main);
var phoneNumberText = FindViewById<EditText>(Resource.Id.PhoneNumberText);
var translateButton = FindViewById<Button>(Resource.Id.TranslateButton);
var callButton = FindViewById<Button>(Resource.Id.CallButton);
callButton.Enabled = false;
string translatedNumber = string.Empty;
translateButton.Click += (sender, args) =>
{
translatedNumber = PhonewordTranslator.ToNumber(phoneNumberText.Text);
if (string.IsNullOrWhiteSpace(translatedNumber))
{
callButton.Text = "Call";
callButton.Enabled = false;
}
else
{
callButton.Text = "Call " + translatedNumber;
callButton.Enabled = true;
}
};
callButton.Click += (sender, e) =>
{
var callDialog = new AlertDialog.Builder(this);
callDialog.SetMessage("Call " + translatedNumber + "?");
callDialog.SetNeutralButton("Call",
delegate
{
var callIntent = new Intent(Intent.ActionCall);
callIntent.SetData(Uri.Parse("tel:" + translatedNumber));
StartActivity(callIntent);
});
callDialog.SetNegativeButton("Cancel", delegate { });
callDialog.Show();
};
}
}
}