Beispiel #1
0
        private void ItemOptionsClick(object sender, int position)
        {
            if (position < 0)
            {
                return;
            }

            var builder = new AlertDialog.Builder(this);

            builder.SetItems(Resource.Array.authContextMenu, (alertSender, args) =>
            {
                switch (args.Which)
                {
                case 0:
                    OpenRenameDialog(position);
                    break;

                case 1:
                    OpenIconDialog(position);
                    break;

                case 2:
                    OpenCategoriesDialog(position);
                    break;

                case 3:
                    OpenDeleteDialog(position);
                    break;
                }
            });

            var dialog = builder.Create();

            dialog.Show();
        }
Beispiel #2
0
            void OnActionSheetRequested(Page sender, ActionSheetArguments arguments)
            {
                // Verify that the page making the request is part of this activity
                if (!PageIsInThisContext(sender))
                {
                    return;
                }

                var builder = new AlertDialog.Builder(Activity);

                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();
            }
Beispiel #3
0
 public void SetItems(string[] items, EventHandler <DialogClickEventArgs> handler)
 {
     if (_useAppCompat)
     {
         _appcompatBuilder.SetItems(items, handler);
     }
     else
     {
         _legacyBuilder.SetItems(items, handler);
     }
 }
        public Dialog Build(AppCompatActivity activity, ActionSheetConfig config)
        {
            var dlg = new AppCompatAlertDialog.Builder(activity, config.AndroidStyleId ?? 0)
                      .SetTitle(config.Title);

            //.SetCustomTitle(new TextView(activity) {
            //    Text = config.Title,
            //    TextSize = 18.0f
            //});

            if (config.ItemIcon != null || config.Options.Any(x => x.ItemIcon != null))
            {
                var adapter = new ActionSheetListAdapter(activity, Android.Resource.Layout.SelectDialogItem,
                                                         Android.Resource.Id.Text1, config);
                dlg.SetAdapter(adapter, (s, a) => config.Options[a.Which].Action?.Invoke());
            }
            else
            {
                var array = config
                            .Options
                            .Select(x => x.Text)
                            .ToArray();

                dlg.SetItems(array, (s, args) => config.Options[args.Which].Action?.Invoke());
            }

            if (config.Destructive != null)
            {
                dlg.SetNegativeButton(config.Destructive.Text, (s, a) => config.Destructive.Action?.Invoke());
            }

            if (config.Cancel != null)
            {
                dlg.SetNeutralButton(config.Cancel.Text, (s, a) => config.Cancel.Action?.Invoke());
            }

            return(dlg.Create());
        }