示例#1
0
        public Task <int> ShowOptions(string title, string message, MessageboxShowType showType, params MessageboxOption[] options)
        {
            var tcs = new TaskCompletionSource <int>();

            var topVC = ((AppDelegate)UIApplication.SharedApplication.Delegate).Presenter.GetTopMostViewController();

            UIAlertController alertViewController = null;

            if (showType == MessageboxShowType.Center)
            {
                alertViewController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
            }
            else
            {
                alertViewController = UIAlertController.Create(title, message, UIAlertControllerStyle.Alert);
            }

            if (options != null)
            {
                for (int i = 0; i < options.Length; i++)
                {
                    var           returnIdx = i;
                    UIAlertAction action;
                    switch (options[i].Type)
                    {
                    case MessageboxOptionType.Cancel:
                        action = UIAlertAction.Create(options[i].Text, UIAlertActionStyle.Cancel, (obj) => tcs.TrySetResult(returnIdx));
                        break;

                    case MessageboxOptionType.Default:
                        action = UIAlertAction.Create(options[i].Text, UIAlertActionStyle.Default, (obj) => tcs.TrySetResult(returnIdx));
                        break;

                    case MessageboxOptionType.Destruction:
                        action = UIAlertAction.Create(options[i].Text, UIAlertActionStyle.Destructive, (obj) => tcs.TrySetResult(returnIdx));
                        break;

                    default:
                        action = UIAlertAction.Create(options[i].Text, UIAlertActionStyle.Default, (obj) => tcs.TrySetResult(returnIdx));
                        break;
                    }
                    alertViewController.AddAction(action);
                }
            }

            topVC.InvokeOnMainThread(() =>
            {
                topVC.PresentViewController(alertViewController, true, null);
            });

            return(tcs.Task);
        }
示例#2
0
        public Task <int> ShowOptions(string title, string message, MessageboxShowType showType, params MessageboxOption[] options)
        {
            var         tcs     = new TaskCompletionSource <int>();
            var         context = Mvx.Resolve <IDroidService>().CurrentContext;
            AlertDialog dialog  = null;

            LayoutInflater _inflatorservice = (LayoutInflater)context.GetSystemService(Context.LayoutInflaterService);
            LinearLayout   layout           = _inflatorservice.Inflate(Resource.Layout.MessageBox, null) as LinearLayout;

            TextView tvTitle   = layout.FindViewById <TextView>(Resource.Id.title);
            TextView tvMessage = layout.FindViewById <TextView>(Resource.Id.message);
            TextView tvBtn1    = layout.FindViewById <TextView>(Resource.Id.btn1);
            TextView tvBtn2    = layout.FindViewById <TextView>(Resource.Id.btn2);
            TextView tvBtn3    = layout.FindViewById <TextView>(Resource.Id.btn3);
            TextView tvBtn4    = layout.FindViewById <TextView>(Resource.Id.btn4);

            tvTitle.SetText(title, TextView.BufferType.Spannable);
            tvMessage.SetText(message, TextView.BufferType.Spannable);

            tvBtn1.SetText(options[1].Text, TextView.BufferType.Spannable);
            tvBtn2.SetText(options[2].Text, TextView.BufferType.Spannable);
            tvBtn3.SetText(options[3].Text, TextView.BufferType.Spannable);
            tvBtn4.SetText(options[0].Text, TextView.BufferType.Spannable);

            tvBtn1.Click += (sender, args) =>
            {
                if (dialog != null)
                {
                    dialog.Hide();
                }
                tcs.SetResult(1);
            };
            tvBtn2.Click += (sender, args) =>
            {
                if (dialog != null)
                {
                    dialog.Hide();
                }
                tcs.SetResult(2);
            };
            tvBtn3.Click += (sender, args) =>
            {
                if (dialog != null)
                {
                    dialog.Hide();
                }
                tcs.SetResult(3);
            };
            tvBtn4.Click += (sender, args) =>
            {
                if (dialog != null)
                {
                    dialog.Hide();
                }
                tcs.SetResult(0);
            };

            var dialogBuider = new AlertDialog.Builder(context);

            dialogBuider.SetView(layout);

            dialog = dialogBuider.Create();
            dialog.Show();

            return(tcs.Task);
        }