Ejemplo n.º 1
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);


            // Set our view from the "main" layout resource
            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;
            var TranslatedNumber = string.Empty;

            TranslateButton.Click += (object senser, System.EventArgs e) =>
            {
                var Translator = new PhoneTranslator();
                TranslatedNumber = Translator.ToNumber(PhoneNumberText.Text);
                if (string.IsNullOrWhiteSpace(TranslatedNumber))
                {
                    CallButton.Text    = "Llamar";
                    CallButton.Enabled = false;
                }
                else
                {
                    CallButton.Text    = $"Llamar al {TranslatedNumber}";
                    CallButton.Enabled = true;
                }
            };

            CallButton.Click += (object sender, System.EventArgs e) =>
            {
                var CallDialog = new AlertDialog.Builder(this);
                CallDialog.SetMessage($"Llamar al numero  {TranslatedNumber}?");

                CallDialog.SetNeutralButton("Llamar", delegate {
                    var CallIntent = new Android.Content.Intent(Android.Content.Intent.ActionCall);

                    CallIntent.SetData(Android.Net.Uri.Parse($"tel:{TranslatedNumber}"));
                    StartActivity(CallIntent);
                });
                CallDialog.SetNegativeButton("Cancelar", delegate { });

                CallDialog.Show();
            };
            Validate();
        }
Ejemplo n.º 2
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            var TranslatedNumber = string.Empty;

            // Perform any additional setup after loading the view, typically from a nib.

            TranslateButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                var Translator = new PhoneTranslator();
                TranslatedNumber = Translator.ToNumber(PhoneNumberText.Text);
                if (string.IsNullOrWhiteSpace(TranslatedNumber))
                {
                    //No hay numero a llamar
                    CallButton.SetTitle("Llamar", UIControlState.Normal);
                    CallButton.Enabled = false;
                }
                else
                {
                    //Hay un posible numero telefonico a llamar
                    CallButton.SetTitle($"llamar al {TranslatedNumber}", UIControlState.Normal);
                    CallButton.Enabled = true;
                }
            };

            CallButton.TouchUpInside += (object sender, EventArgs e) =>
            {
                var URL = new Foundation.NSUrl($"tel:{TranslatedNumber}");
                //Utilizar el manejador de URL con el prefijo tel: para invocar
                //a la aplicacion Phone de Apple, de lo contrario mostrar un dialogo de alerta.
                if (!UIApplication.SharedApplication.OpenUrl(URL))
                {
                    var Alert = UIAlertController.Create("No soportado",
                                                         "El esquema 'tel:' no es soportado en este dispositivo",
                                                         UIAlertControllerStyle.Alert);
                    Alert.AddAction(UIAlertAction.Create("Ok",
                                                         UIAlertActionStyle.Default, null));
                    PresentViewController(Alert, true, null);
                }
            };
        }