void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
        {
            var builder = new AlertDialog.Builder(this);

            builder.SetTitle(arguments.Title);
            string[] items = arguments.Buttons.ToArray();
            builder.SetItems(items, (o, args) => arguments.Result.TrySetResult(items[args.Which]));

            if (arguments.Cancel != null)
            {
                builder.SetPositiveButton(arguments.Cancel, (o, args) => arguments.Result.TrySetResult(arguments.Cancel));
            }

            if (arguments.Destruction != null)
            {
                builder.SetNegativeButton(arguments.Destruction, (o, args) => arguments.Result.TrySetResult(arguments.Destruction));
            }

            AlertDialog dialog = builder.Create();

            builder.Dispose();
            //to match current functionality of renderer we set cancelable on outside
            //and return null
            dialog.SetCanceledOnTouchOutside(true);
            dialog.CancelEvent += (o, e) => arguments.SetResult(null);
            dialog.Show();
        }
Exemplo n.º 2
0
        //Alert handler to improve code cleanliness
        public AlertDialog CreateAlert(AlertType type, string alertMessage, string alertTitle)
        {
            if (type == AlertType.Error)
            {
                AlertDialog.Builder dialogConnection = new AlertDialog.Builder(this);
                dialog = dialogConnection.Create();
                dialog.SetTitle(alertTitle);
                dialog.SetMessage(alertMessage);
            }
            else if (type == AlertType.Load)
            {
                dialog = new EDMTDialogBuilder()
                         .SetContext(this)
                         .SetMessage(alertMessage)
                         .Build();
            }
            else if (type == AlertType.Info)
            {
                AlertDialog.Builder dialogConnection = new AlertDialog.Builder(this);
                var btnOk = Resources.GetText(Resource.String.btnOk);
                dialogConnection.SetPositiveButton(btnOk, (senderAlert, args) => {
                    dialogConnection.Dispose();
                });
                dialog = dialogConnection.Create();
                dialog.SetTitle(alertTitle);
                dialog.SetMessage(alertMessage);
                dialog.SetCanceledOnTouchOutside(true);
            }

            dialog.Show();

            return(dialog);
        }