Example #1
0
        internal void ShowDialog <T>(string caption, string message, DialogButton <T> positive, DialogButton <T> negative = null, DialogButton <T> neutral = null)
        {
            using (var builder = new AlertDialog.Builder(_activity))
            {
                builder.SetMessage(message);

                if (caption != null)
                {
                    builder.SetTitle(caption);
                }

                builder.SetPositiveButton(positive.Caption, (sender, e) => positive.Execute());

                if (negative != null)
                {
                    builder.SetNegativeButton(negative.Caption, (sender, e) => negative.Execute());
                }

                if (neutral != null)
                {
                    builder.SetNeutralButton(neutral.Caption, (sender, e) => neutral.Execute());
                }

                builder.SetCancelable(false);
                AlertDialog dialog = builder.Show();
                dialog.DismissEvent += DisposeDialog;
                Dialogs.Push(dialog);
            }
        }
Example #2
0
        void ShowSelectionDialog(string caption, KeyValuePair <object, string>[] items, int index, DialogButton <object> positive, DialogButton <object> negative)
        {
            using (var builder = new AlertDialog.Builder(_activity))
            {
                builder.SetTitle(caption);

                var rows = new string[items.Length];
                for (int i = 0; i < items.Length; i++)
                {
                    rows[i] = items[i].Value;
                }

                var adapt = new ArrayAdapter <string>(_activity, Android.Resource.Layout.SelectDialogSingleChoice, rows);

                builder.SetSingleChoiceItems(adapt, index, (e, args) => { });

                builder.SetPositiveButton(positive.Caption, (sender, e) =>
                {
                    int pos = ((AlertDialog)sender).ListView.CheckedItemPosition;
                    if (pos < items.Length)
                    {
                        object result = items[pos].Key;
                        positive.Execute(result);
                    }
                });

                builder.SetNegativeButton(negative.Caption, (sender, e) => negative.Execute());

                builder.SetCancelable(false);
                AlertDialog dialog = builder.Show();
                dialog.DismissEvent += DisposeDialog;
                Dialogs.Push(dialog);
            }
        }
Example #3
0
            public override void Dismissed(UIActionSheet actionSheet, int buttonIndex)
            {
                // if user uses gallery, camera, etc, application will crash, because UINavigationController does not presented
                if (_items.Length > buttonIndex /*because last button is cancel*/)
                {
                    _positive.Execute(_items [buttonIndex].Key);
                }
                else
                {
                    _negative.Execute();
                }

                _list.Remove(actionSheet);
                actionSheet.Dispose();
            }
Example #4
0
            public override void Dismissed(UIAlertView alertview, int buttonIndex)
            {
                // if user uses gallery, camera, etc, application will crash, because UINavigationController does not presented
                if (buttonIndex == 0)
                {
                    _positive.Execute();
                }
                else if (buttonIndex == 1)
                {
                    _negative.Execute();
                }
                else if (buttonIndex == 2)
                {
                    _neutral.Execute();
                }

                _alertViews.Remove(alertview);
                alertview.Dispose();
            }
Example #5
0
        public void ShowDateTimeDialog(string caption, UIDatePickerMode mode, DateTime current, DialogButton <DateTime> positive, DialogButton <DateTime> negative)
        {
            Version version = new Version(UIDevice.CurrentDevice.SystemVersion);

            if (version.Major >= 7)
            {
                DatePicker picker = new DatePicker();
                picker.Title = caption;
                picker.NativeDatePicker.Mode = mode;
                picker.NativeDatePicker.Date = current;
                picker.DoneTitle             = positive.Caption;
                picker.CancelTitle           = negative.Caption;
                picker.Click += (object sender, UIButtonEventArgs e) => {
                    var      dateTime = (sender as DatePicker).NativeDatePicker.Date;
                    DateTime result   = dateTime != null?System.DateTime.SpecifyKind(dateTime, DateTimeKind.Utc).ToLocalTime() : System.DateTime.MinValue;

                    if (e.ButtonIndex == 0)
                    {
                        positive.Execute(result);
                    }
                    else if (e.ButtonIndex == 1)
                    {
                        negative.Execute(result);
                    }
                };

                picker.Show(_context.MainController.View, (ScreenController)_context.MainController.VisibleViewController);
            }
            else
            {
                var alertView = new UIAlertView(caption, "", null, positive.Caption, negative.Caption);
                alertView.Show();
                _alertViews.Add(alertView);

                UIDatePicker datePicker = new UIDatePicker();
                datePicker.Frame = new System.Drawing.RectangleF(10, alertView.Bounds.Size.Height, 270, 150);
                datePicker.Mode  = UIDatePickerMode.Date;
                datePicker.Date  = current;
                alertView.AddSubview(datePicker);

                UIDatePicker timePicker = new UIDatePicker();
                timePicker.Frame = new System.Drawing.RectangleF(10, alertView.Bounds.Size.Height + 150 + 20, 270, 150);
                timePicker.Mode  = UIDatePickerMode.Time;
                timePicker.Date  = current;
                alertView.AddSubview(timePicker);

                alertView.Clicked += (object sender, UIButtonEventArgs e) => {
                    DateTime date   = System.DateTime.SpecifyKind(datePicker.Date, DateTimeKind.Unspecified);
                    DateTime time   = System.DateTime.SpecifyKind(timePicker.Date, DateTimeKind.Utc).ToLocalTime();
                    DateTime result = new DateTime(date.Year, date.Month, date.Day, time.Hour, time.Minute, time.Second);
                    if (e.ButtonIndex == 0)
                    {
                        positive.Execute(result);
                    }
                    else if (e.ButtonIndex == 1)
                    {
                        negative.Execute(result);
                    }

                    var av = (UIAlertView)sender;
                    _alertViews.Remove(av);
                    av.Dispose();
                };

                alertView.Bounds = new System.Drawing.RectangleF(0, 0, 290, alertView.Bounds.Size.Height + 150 + 150 + 20 + 30);
            }
        }
Example #6
0
        void ShowDateTimeDialog(string caption, DateTime current, bool date, bool time
                                , DialogButton <DateTime> positive, DialogButton <DateTime> negative)
        {
            using (var builder = new AlertDialog.Builder(_activity))
            {
                builder.SetTitle(caption);
                using (var ll = new LinearLayout(_activity))
                {
                    ll.Orientation = Orientation.Vertical;
                    if (date)
                    {
                        using (var dtv = new Android.Widget.TextView(_activity))
                            using (var dp = new DatePicker(_activity))
                            {
                                dtv.Text = D.DATE;
                                dtv.SetTextSize(Android.Util.ComplexUnitType.Sp, 30);
                                dtv.Gravity = GravityFlags.Center;
                                ll.AddView(dtv);

                                dp.Id = DatePicker;
                                var minDate = new DateTime(1900, 1, 1);
                                dp.DateTime = current > minDate ? current : minDate;
                                ll.AddView(dp);
                            }
                    }
                    if (time)
                    {
                        using (var ttv = new Android.Widget.TextView(_activity))
                            using (var tp = new TimePicker(_activity))
                            {
                                ttv.Text = D.TIME;
                                ttv.SetTextSize(Android.Util.ComplexUnitType.Sp, 30);
                                ttv.Gravity = GravityFlags.Center;
                                ll.AddView(ttv);

                                tp.Id = TimePicker;
                                tp.SetIs24HourView(new Java.Lang.Boolean(true));
                                tp.CurrentHour   = new Java.Lang.Integer(current.Hour);
                                tp.CurrentMinute = new Java.Lang.Integer(current.Minute);
                                ll.AddView(tp);
                            }
                    }
                    builder.SetView(ll);
                }

                builder.SetPositiveButton(positive.Caption, (sender, e) =>
                {
                    var alertDialog = (AlertDialog)sender;
                    DateTime result = DateTimeFromDialog(alertDialog);
                    positive.Execute(result);
                });

                builder.SetNegativeButton(negative.Caption, (sender, e) =>
                {
                    var alertDialog = (AlertDialog)sender;
                    DateTime result = DateTimeFromDialog(alertDialog);
                    negative.Execute(result);
                });

                builder.SetCancelable(false);
                AlertDialog dialog = builder.Show();
                dialog.DismissEvent += DisposeDialog;
                Dialogs.Push(dialog);
            }
        }