protected void ShowErrorForNativeUIAlert(string v) { if (this.ShowErrors) { global::Android.Content.Context c = global::Android.App.Application.Context; new Plugin.Threading.UIThreadRunInvoker(c).BeginInvokeOnUIThread ( () => { var b = new global::Android.App.AlertDialog.Builder(c); b.SetMessage(v); b.SetTitle("Warning"); b.SetNeutralButton ( "OK", (s, e) => { ((global::Android.App.AlertDialog)s).Cancel(); } ); var alert = b.Create(); alert.Show(); } ); return; } }
protected override void OnCreate(Bundle savedInstanceState) { base.OnCreate(savedInstanceState); Xamarin.Essentials.Platform.Init(this, savedInstanceState); // 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.btnTranslate); var CallButton = FindViewById <Button>(Resource.Id.btnCall); CallButton.Enabled = false; var TranslatedNumber = string.Empty; TranslateButton.Click += (object sender, System.EventArgs e) => { var Translator = new PhoneApp.Translator.PhoneTranslator(); TranslatedNumber = Translator.ToNumber(PhoneNumberText.Text); if (string.IsNullOrWhiteSpace(TranslatedNumber)) { // No hay número a llamar CallButton.Text = "Llamar"; CallButton.Enabled = false; } else { // Hay un posible número telefónico a llamar CallButton.Text = $"Llamar al {TranslatedNumber}"; CallButton.Enabled = true; } }; CallButton.Click += (object sender, System.EventArgs e) => { // Intentar marcar el número telefónico var CallDialog = new global::Android.App.AlertDialog.Builder(this); CallDialog.SetMessage($"Llamar al número {TranslatedNumber}?"); CallDialog.SetNeutralButton("Llamar", delegate { // Crear un intento para marcar el número telefónico var CallIntent = new global::Android.Content.Intent( global::Android.Content.Intent.ActionCall); CallIntent.SetData( global::Android.Net.Uri.Parse($"tel:{TranslatedNumber}")); StartActivity(CallIntent); }); CallDialog.SetNegativeButton("Cancelar", delegate { }); // Mostrar el cuadro de diálogo al usuario y esperar una respuesta. CallDialog.Show(); }; }
private void BtnResetAll_Click(object sender, System.EventArgs e) { var a = new global::Android.App.AlertDialog.Builder(this).Create(); a.SetTitle(Resources.GetString(Resource.String.caution)); a.SetMessage(Resources.GetString(Resource.String.reset_all_warn)); a.SetButton(Resources.GetString(Resource.String.ok), (s, d) => { File.Delete(Path.Combine(IOHelper.GetDataPath(), "config.pc")); System.Environment.Exit(0); }); a.SetButton2(Resources.GetString(Resource.String.cancel), (s, d) => { }); a.Show(); }