-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMainPage.xaml.cs
57 lines (50 loc) · 1.44 KB
/
MainPage.xaml.cs
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
namespace Phoneword;
public partial class MainPage : ContentPage
{
public MainPage()
{
InitializeComponent();
}
string translatedNumber;
private void OnTranslate(object sender, EventArgs e)
{
string enteredNumber = PhoneNumberText.Text;
translatedNumber = Core.PhonewordTranslator.ToNumber(enteredNumber);
if (!string.IsNullOrEmpty(translatedNumber))
{
CallButton.IsEnabled = true;
CallButton.Text = "Call " + translatedNumber;
}
else
{
CallButton.IsEnabled = false;
CallButton.Text = "Call";
}
}
async void OnCall(object sender, System.EventArgs e)
{
if (await this.DisplayAlert(
"Dial a number",
"Would you like to call" + translatedNumber + "?",
"Yes",
"No"))
{
try
{
PhoneDialer.Open(translatedNumber);
}
catch (ArgumentException)
{
await DisplayAlert("Unable to dial", "Phone number was not valid", "OK");
}
catch (FeatureNotSupportedException)
{
await DisplayAlert("Unable to dial", "Phone dialing not supported.", "OK");
}
catch (Exception)
{
await DisplayAlert("Unable to dial", "Phone dialing failed.", "OK");
}
}
}
}