示例#1
0
        public static DatePickerDialog Build(Activity activity, DatePromptConfig config)
        {
            var dateTime = config.SelectedDate ?? DateTime.Now;
            var dialog   = new DatePickerDialog(
                IsBrokenSamsungDevice()
                    ? new ContextThemeWrapper(activity, Resource.Style.ThemeHoloLightDialog)
                    : activity,
                (sender, args) => { },
                dateTime.Year,
                dateTime.Month - 1,
                dateTime.Day
                );

            dialog.SetCancelable(false);

            if (!String.IsNullOrWhiteSpace(config.Title))
            {
                dialog.SetTitle(config.Title);
            }

            if (config.MinimumDate != null)
            {
                dialog.DatePicker.MinDate = config.MinimumDate.Value.ToUnixTimestamp();
            }

            if (config.MaximumDate != null)
            {
                dialog.DatePicker.MaxDate = config.MaximumDate.Value.ToUnixTimestamp();
            }

            if (config.IsCancellable)
            {
                dialog.SetButton(
                    (int)DialogButtonType.Negative,
                    new SpannableString(config.CancelText),
                    (sender, args) => config
                    .OnAction?
                    .Invoke(new DatePromptResult(
                                false,
                                dialog.DatePicker.DateTime.Date
                                ))
                    );
            }
            dialog.SetButton(
                (int)DialogButtonType.Positive,
                new SpannableString(config.OkText),
                (sender, args) => config
                .OnAction?
                .Invoke(new DatePromptResult(
                            true,
                            dialog.DatePicker.DateTime.Date
                            ))
                );
            return(dialog);
        }
示例#2
0
        /// <summary>
        /// ShowMessage
        /// </summary>
        /// <returns></returns>
        public async Task <DateTimeOffset> ShowDateDialog(string title)
        {
            var tcs        = new TaskCompletionSource <DateTimeOffset>();
            var dateDialog = new DatePickerDialog(CrossCurrentActivity.Current.Activity, Resource.Style.AppCompatDialogStyle,
                                                  (sender, args) => { tcs.TrySetResult(args.Date); }, DateTime.Now.Year, DateTime.Now.Month,
                                                  DateTime.Now.Day);

            dateDialog.SetTitle(title);
            dateDialog.SetCancelable(true);
            dateDialog.Show();
            return(await tcs.Task);
        }
        public static DatePickerDialog Build(Activity activity, DatePromptConfig config)
        {
            var dateTime = config.SelectedDate ?? DateTime.Now;
            var dialog   = new DatePickerDialog(
                activity,
                (sender, args) => { },
                dateTime.Year,
                dateTime.Month + 1,
                dateTime.Day
                );

            dialog.SetCancelable(false);

            if (!String.IsNullOrWhiteSpace(config.Title))
            {
                dialog.SetTitle(config.Title);
            }

            if (config.MinimumDate != null)
            {
                dialog.DatePicker.MinDate = config.MinimumDate.Value.ToUnixTimestamp();
            }

            if (config.MaximumDate != null)
            {
                dialog.DatePicker.MaxDate = config.MaximumDate.Value.ToUnixTimestamp();
            }

            if (config.IsCancellable)
            {
                dialog.SetButton(
                    (int)DialogButtonType.Negative,
                    new SpannableString(config.CancelText),
                    (sender, args) =>
                {
                    config.OnResult?.Invoke(new DatePromptResult(false, dialog.DatePicker.DateTime.Date));
                }
                    );
            }
            dialog.SetButton(
                (int)DialogButtonType.Positive,
                new SpannableString(config.OkText),
                (sender, args) =>
            {
                config.OnResult?.Invoke(new DatePromptResult(true, dialog.DatePicker.DateTime.Date));
            }
                );
            return(dialog);
        }
 //METHOD: Create dialog for Date Picker.
         #pragma warning disable
 protected override Dialog OnCreateDialog(int id)
 {
         #pragma warning restore
     DatePickerDialog dpd = new DatePickerDialog(this, HandleDateSet, todays_date.Year,
                                                 todays_date.Month - 1, todays_date.Day);
     dpd.SetMessage("Requests issued within 2 days will add a $15.00 fee.");
     dpd.SetIcon(Resource.Drawable.ic_action_time);
     dpd.SetCanceledOnTouchOutside(false);
     dpd.SetCancelable(false);
                 #pragma warning disable
     dpd.SetButton("Cancel", dpd);
     dpd.SetButton2("Confirm", dpd);
                 #pragma warning restore
     return(dpd);
 }
示例#5
0
 public static DatePickerDialog ShowDatePickerDialog(Context ctx, TextView text)
 {
     try
     {
         var cal        = Calendar.GetInstance(Android.Icu.Util.TimeZone.Default);
         var listener   = new OnDateSetListener(text);
         var datePicker = new DatePickerDialog(ctx, listener,
                                               cal.Get(CalendarField.Year),
                                               cal.Get(CalendarField.Month),
                                               cal.Get(CalendarField.DayOfMonth));
         datePicker.SetCancelable(false);
         datePicker.Show();
     }
     catch (Exception ex)
     {
         ShowDialog(ctx, "An error occured while showing Date Picker\n\n Error Details:\n" + ex, "Exception");
     }
     return(null);
 }