Пример #1
1
 void showAlert(AlertDialog.Builder builder)
 {
     alert = builder.Create();
     alert.Show();
     var acceptButton = alert.GetButton((int)DialogButtonType.Positive);
     acceptButton.Click += saveNewDrink;
     var cancelButton = alert.GetButton((int)DialogButtonType.Negative);
     cancelButton.Click += (sender, e) => { alert.Dismiss(); };
 }
 protected void ShowDialog()
 {
     var builder = new AlertDialog.Builder(Context)
         .SetTitle(Title)
         .SetNeutralButton(EDIT, delegate { });
     InitializePositiveAndNegativeButtons(builder);
     CheckItemsSource();
     InitializeDialogItems(builder, Items);
     dialog = builder.Create();
     dialog.Show();
     var neutralButton = dialog.GetButton((int)DialogButtonType.Neutral);
     neutralButton.SetOnClickListener(new ClickListener(ShowEditingDialog));
 }
 private static void UpdateEnabledChanged(AlertDialog alertDialog, DialogButtonType dialogButtonType, bool isEnabled)
 {
     var button = alertDialog.GetButton((int)dialogButtonType);
     button.Enabled = isEnabled;
 }
Пример #4
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void handleNothingButton(object sender, DialogClickEventArgs e)
        {
            Android.App.AlertDialog objAlertDialog = sender as Android.App.AlertDialog;
            Button btnClicked = objAlertDialog.GetButton(e.Which);

            if (btnClicked.Text == "Aceptar")
            {
                System.Environment.Exit(0);
            }
        }
Пример #5
0
        public void mostrarVentanaAgregartexto(int idCampo, string titulo)
        {
            //Se crea el layoutInflater en base a la actividad que esta ejecutando el fragmento actual
            LayoutInflater layoutInflater = LayoutInflater.From(this);
            //Se crea la vista que contiene los controles que muestra la ventana de observaciones
            View contenedorVentanaModal = layoutInflater.Inflate(Resource.Layout.VentanaObservaciones, null);

            //Se instancia el constructor de la ventana
            Android.App.AlertDialog.Builder constructorVentana = new Android.App.AlertDialog.Builder(this);
            constructorVentana.SetView(contenedorVentanaModal);//Se agrega la vista que va a mostrar la ventana de observaciones

            //Se crea la instancia del edit text donde se colocara la observación
            Android.Widget.EditText observacion = (Android.Widget.EditText)contenedorVentanaModal.FindViewById(Resource.Id.txtObservacionesVentana);
            //Se cambia el titulo de la ventana
            Android.Widget.TextView tituloVentana = (Android.Widget.TextView)contenedorVentanaModal.FindViewById(Resource.Id.txtTituloVentana);
            tituloVentana.Text = titulo;

            //Se crea la instancia del edit text al que se le asignara el texto de la ventana
            Android.Widget.EditText campoTexto = (Android.Widget.EditText) this.FindViewById(idCampo);
            //Se evalua el campo de texto, si no esta vacio se asigna al campo de texto de la ventana
            if (campoTexto.Text != "")
            {
                observacion.Text = campoTexto.Text;//Se realiza la asignación del texto
            }
            //Se agregan los eventos para los botones de cancelar y de Aceptar
            constructorVentana.SetCancelable(false).SetPositiveButton("Aceptar", (sender, args) => {
                //Al presionar el botón de Aceptar se asigna el texto agregado en la ventana
                //en el campo de texto
                campoTexto.Text = observacion.Text;
            }).SetNegativeButton("Cancelar", (sender, args) => {
                //Evento al presionar el botón de cancelar
            }).SetNeutralButton("Borrar todo", (System.EventHandler <DialogClickEventArgs>)null);

            //Se crea la ventana de dialogo y se instancia con el constructor de la ventana creado anteriormente
            Android.App.AlertDialog ventana = constructorVentana.Create();
            ventana.Show();//Se muestra la ventana

            //Se crea una instancia del botón neutral de la ventana
            var btnBorrar = ventana.GetButton((int)DialogButtonType.Neutral);

            //Se crea el evento al presionar el botón de borrar
            btnBorrar.Click += (sender, args) => {
                observacion.Text = "";//Se limpia el texto de la ventana
            };
        }
Пример #6
0
        public void SaveToFile()
        {
            AlertDialog.Builder dialogBuilder = new AlertDialog.Builder(this);
            dialogBuilder.SetTitle("Save to file");

            View     views = LayoutInflater.Inflate(Resource.Layout.AlertDialog_Save, null);
            EditText input = (EditText)views.FindViewById(Resource.Id.edit);

            int counter = 0;

            Java.Lang.StringBuilder tempName = new Java.Lang.StringBuilder(curSaveName);
            while (true)
            {
                File file = new File(global::Android.OS.Environment.ExternalStorageDirectory + "/ChineseReader/", tempName.ToString() + ".txt");
                if (file.Exists())
                {
                    counter++;
                    tempName.SetLength(0);
                    tempName.Append(curSaveName).Append('(').Append(Convert.ToChar(counter)).Append(')');
                }
                else
                {
                    input.SetText(tempName, TextView.BufferType.Spannable);
                    break;
                }
            }

            dialogBuilder.SetView(views);
            dialogBuilder.SetPositiveButton("Save", delegate { });
            dialogBuilder.SetNegativeButton("Cancel", delegate { });

            AlertDialog alert = dialogBuilder.Show();

            dumpStartButton        = alert.GetButton((int)DialogButtonType.Positive);
            dumpStartButton.Click += (sender, e) =>
            {
                try
                {
                    View view = (View)sender;

                    File dir = new File(global::Android.OS.Environment.ExternalStorageDirectory + "/ChineseReader/");
                    if (!dir.Exists())
                    {
                        dir.Mkdirs();
                    }

                    if (((RadioButton)views.FindViewById(Resource.Id.radio_text)).Checked)
                    {
                        string path = dir.AbsolutePath + "/" + input.Text.ToString() + ".txt";

                        if (annoMode == ANNOTATE_FILE)
                        {
                            System.IO.FileStream fis = new System.IO.FileStream(curFilePath, System.IO.FileMode.Open, System.IO.FileAccess.Read);
                            System.IO.FileStream fos = new System.IO.FileStream(path, System.IO.FileMode.Create, System.IO.FileAccess.Write);
                            CopyFile(fis, fos);
                            fis.Close();
                            fos.Close();
                        }
                        else
                        {
                            System.IO.StreamWriter fw = new System.IO.StreamWriter(path);
                            fw.Write(pastedText.Substring(0, pastedText.Length));
                            fw.Flush();
                            fw.Close();
                        }

                        Toast.MakeText(Application, "Saved to " + path, ToastLength.Long).Show();
                    }
                    else if (((RadioButton)views.FindViewById(Resource.Id.radio_pinyin)).Checked)
                    {
                        string path = dir.AbsolutePath + "/" + input.Text.ToString() + ".txt";

                        view.Enabled                = false;
                        dumpFilePath                = path;
                        dumpFileWriter              = new System.IO.StreamWriter(path);
                        dumpProgress                = (ProgressBar)views.FindViewById(Resource.Id.progress);
                        dumpProgressText            = (TextView)views.FindViewById(Resource.Id.progress_text);
                        dumpProgress.Visibility     = ViewStates.Visible;
                        dumpProgressText.Visibility = ViewStates.Visible;
                        dumpCancelled               = false;
                        DumpPinyin(0, 0);
                    }
                    else if (((RadioButton)views.FindViewById(Resource.Id.radio_both)).Checked)
                    {
                        string path = dir.AbsolutePath + "/" + input.Text.ToString() + ".tsv";

                        view.Enabled                = false;
                        dumpFilePath                = path;
                        dumpFileWriter              = new System.IO.StreamWriter(path);
                        dumpProgress                = (ProgressBar)views.FindViewById(Resource.Id.progress);
                        dumpProgressText            = (TextView)views.FindViewById(Resource.Id.progress_text);
                        dumpProgress.Visibility     = ViewStates.Visible;
                        dumpProgressText.Visibility = ViewStates.Visible;
                        dumpCancelled               = false;
                        DumpBoth(0, 0);
                    }
                }
                catch (Exception ex)
                {
                    Toast.MakeText(Application, ex.Message, ToastLength.Long).Show();
                }
            };

            Button dumpCancelButton = alert.GetButton((int)DialogButtonType.Negative);

            dumpCancelButton.Click += (sender, e) =>
            {
                dumpCancelled = true;

                alert.Dismiss();
            };
        }