public Task <DateTime?> ShowDatePickerAsync(string title, DateTime?defaultDate, DateTime?minDate = null, DateTime?maxDate = null) { if (_datePickerDialog.IsShowing && _tcsDate != null) { return(_tcsDate.Task); } if (minDate.HasValue) { _datePickerDialog.DatePicker.MinDate = minDate.Value.ToUnixTimeMileseconds(); } if (maxDate.HasValue) { _datePickerDialog.DatePicker.MaxDate = maxDate.Value.ToUnixTimeMileseconds(); } if (defaultDate.HasValue && defaultDate.Value >= _datePickerDialog.DatePicker.MinDateTime && defaultDate.Value <= _datePickerDialog.DatePicker.MaxDateTime) { _datePickerDialog.DatePicker.DateTime = defaultDate.Value; } _tcsDate = new TaskCompletionSource <DateTime?>(); _datePickerDialog.SetTitle(title); _datePickerDialog.Show(); return(_tcsDate.Task); }
internal protected override void Open() { // Note: Month needs to be -1 since on Android months go from 0-11 // http://developer.android.com/reference/android/app/DatePickerDialog.OnDateSetListener.html#onDateSet(android.widget.DatePicker, int, int, int) _dialog = new DatePickerDialog( ContextHelper.Current, OnDateSet, Date.Year, Date.Month - 1, Date.Day ); //Removes title that is unnecessary as it is a duplicate -> http://stackoverflow.com/questions/33486643/remove-title-from-datepickerdialog _dialog.SetTitle(""); var minYearCalendar = Calendar.Instance; minYearCalendar.Set(MinYear.Year, MinYear.Month - 1, MinYear.Day, MinYear.Hour, MinYear.Minute, MinYear.Second); _dialog.DatePicker.MinDate = minYearCalendar.TimeInMillis; var maxYearCalendar = Calendar.Instance; maxYearCalendar.Set(MaxYear.Year, MaxYear.Month - 1, MaxYear.Day, MaxYear.Hour, MaxYear.Minute, MaxYear.Second); _dialog.DatePicker.MaxDate = maxYearCalendar.TimeInMillis; _dialog.DismissEvent += OnDismiss; _dialog.Show(); }
private void editDate(DateTimeOffset currentDate) { if (editDialog == null) { var datePickerDialog = new DatePickerDialog(this, Resource.Style.WheelDialogStyle, new DatePickerListener(currentDate, activeEditionChangedSubject.OnNext), currentDate.Year, currentDate.Month - 1, currentDate.Day); // FirstDayOfWeek days start with sunday at 1 and finish with saturday at 7 var normalizedBeginningOfWeek = (int)ViewModel.BeginningOfWeek + 1; datePickerDialog.DatePicker.FirstDayOfWeek = normalizedBeginningOfWeek; void updateDateBounds() { datePickerDialog.DatePicker.MinDate = minDateTime.ToUnixTimeMilliseconds(); datePickerDialog.DatePicker.MaxDate = maxDateTime.ToUnixTimeMilliseconds(); datePickerDialog.SetTitle(""); } updateDateBounds(); void resetAction() { updateDateBounds(); datePickerDialog.UpdateDate(currentDate.Year, currentDate.Month - 1, currentDate.Day); } editDialog = datePickerDialog; editDialog.DismissEvent += (_, __) => onCurrentEditDialogDismiss(resetAction); editDialog.Show(); } }
private void SetDatePickerText() { _reminderDatePickerText = this.FindViewById <EditText>(Resource.Id.reminderDatePickerEditText); _reminderDatePickerEditTextReadableValue = this.FindViewById <EditText>(Resource.Id.reminderDatePickerEditTextReadableValue); if (!string.IsNullOrEmpty(_reminderDatePickerText.Text)) { var reminderDate = Convert.ToDateTime(_reminderDatePickerText.Text); _reminderDatePickerEditTextReadableValue.Text = ReadableDateConverter.Convert(reminderDate); } _reminderDatePickerEditTextReadableValue.Focusable = false; _reminderDatePickerEditTextReadableValue.Click += delegate { var reminderDate = DateTime.Now; if (!string.IsNullOrEmpty(_reminderDatePickerText.Text)) { reminderDate = Convert.ToDateTime(_reminderDatePickerText.Text); } DatePickerDialog dialog = new DatePickerDialog(this, this, reminderDate.Year, reminderDate.Month - 1, reminderDate.Day); dialog.SetTitle(GetString(Resource.String.date_selection)); dialog.DatePicker.SetMinDate(DateTime.Now); dialog.Show(); }; }
/// <summary> /// Date alert build for adding entries to the calendar /// </summary> /// <param name="r">The recipe to add</param> protected void buildDateAlert(Recipe r) { calendarRecipe = r; DatePickerDialog datePickerDialog = new DatePickerDialog(this.Context, Android.Resource.Style.ThemeHoloLightDialogMinWidth); datePickerDialog.SetTitle(GetString(Resource.String.pickdate_text)); datePickerDialog.DateSet += DatePickerDialog_DateSet; datePickerDialog.Show(); }
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); }
private static BasisTimesUtils ShowDatePickerDialog(Context context, int themeId, string title, int year, int month, int day, IOnDatePickerListener onDateTimePickerListener) { datePickerDialog = new DatePickerDialog(context, themeId, new OnDateSetListener(onDateTimePickerListener), year, month - 1, day); datePickerDialog.SetOnCancelListener(new OnCancelListener(onDateTimePickerListener)); if (!TextUtils.IsEmpty(title)) { datePickerDialog.SetTitle(title); } datePickerDialog.Show(); return(new BasisTimesUtils()); }
/// <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); }
public void ShowShareFileDatePicker(string pathToNewFileShare) { homeActivity.HideProgressDialog(); var selectedExpirationDate = DateTime.Now.AddDays(7); //Selectie standaard op 7 dagen na vandaag var picker = new DatePickerDialog(homeActivity, (object sender, DatePickerDialog.DateSetEventArgs e) => { selectedExpirationDate = e.Date; if (selectedExpirationDate.Date <= DateTime.Now.Date) { homeActivity.HideProgressDialog(); Toast.MakeText(Android.App.Application.Context, "Gekozen vervaldatum moet na vandaag zijn. Probeer het a.u.b. opnieuw.", ToastLength.Long).Show(); } else { ThreadPool.QueueUserWorkItem(async o => { PublicUrl createdPublicUrl = await DataLayer.Instance.CreatePublicFileShare(pathToNewFileShare, selectedExpirationDate); if (createdPublicUrl != null) { //Open e-mail intent var emailIntent = new Intent(Android.Content.Intent.ActionSend); string bodyText = "Mijn gedeelde bestand: \n" + createdPublicUrl.publicUri + "\n \n" + "Deze link is geldig tot: " + selectedExpirationDate.ToString("dd-MM-yyyy"); emailIntent.PutExtra(Android.Content.Intent.ExtraSubject, "Publieke URL naar gedeeld LocalBox bestand"); emailIntent.PutExtra(Android.Content.Intent.ExtraText, bodyText); emailIntent.SetType("message/rfc822"); homeActivity.RunOnUiThread(() => { homeActivity.HideProgressDialog(); homeActivity.StartActivity(emailIntent); }); } else { homeActivity.HideProgressDialog(); Toast.MakeText(Android.App.Application.Context, "Bestand delen mislukt", ToastLength.Short).Show(); } }); } }, selectedExpirationDate.Year, selectedExpirationDate.Month - 1, selectedExpirationDate.Day); picker.SetTitle("Selecteer vervaldatum:"); picker.Show(); }
void DateSelect_OnClick(object sender, EventArgs eventArgs) { //var fkfkf = new DateTime(2012, 11, 13); _ddtime = new DatePickerDialog(this, OnDateSet, DateTime.Today.Year, DateTime.Today.Month - 1, DateTime.Today.Day ); _ddtime.DatePicker.DateTime = _selectedDate; _ddtime.SetTitle(""); _ddtime.Show(); //ddtime.DatePicker.DateTime = selected_Date; //ddtime.SetTitle(""); //ddtime.Show(); //frag. //frag.Show(FragmentManager, DatePickerFragment.TAG); }
protected internal override void Open() { var date = Date; // If we're setting the date to the null sentinel value, // we'll instead set it to the current date for the purposes // of where to place the user's position in the looping selectors. if (date.Ticks == DatePicker.DEFAULT_DATE_TICKS) { var temp = new Windows.Globalization.Calendar(); var calendar = new Windows.Globalization.Calendar( temp.Languages, CalendarIdentifier, temp.GetClock()); calendar.SetToNow(); date = calendar.GetDateTime(); } // Note: Month needs to be -1 since on Android months go from 0-11 // http://developer.android.com/reference/android/app/DatePickerDialog.OnDateSetListener.html#onDateSet(android.widget.DatePicker, int, int, int) _dialog = new DatePickerDialog( ContextHelper.Current, OnDateSet, date.Year, date.Month - 1, date.Day ); //Removes title that is unnecessary as it is a duplicate -> http://stackoverflow.com/questions/33486643/remove-title-from-datepickerdialog _dialog.SetTitle(""); var minYearCalendar = Calendar.Instance; minYearCalendar.Set(MinYear.Year, MinYear.Month - 1, MinYear.Day, MinYear.Hour, MinYear.Minute, MinYear.Second); _dialog.DatePicker.MinDate = minYearCalendar.TimeInMillis; var maxYearCalendar = Calendar.Instance; maxYearCalendar.Set(MaxYear.Year, MaxYear.Month - 1, MaxYear.Day, MaxYear.Hour, MaxYear.Minute, MaxYear.Second); _dialog.DatePicker.MaxDate = maxYearCalendar.TimeInMillis; _dialog.DismissEvent += OnDismiss; _dialog.Show(); }
private void SetupDatePicker(object sender, View.TouchEventArgs e) { if (e.Event.Action == MotionEventActions.Down) { DatePickerDialog ddtime = new DatePickerDialog(this, OnDateSet, DateTime.Today.Year, DateTime.Today.Month - 1, DateTime.Today.Day ); if (txtGoalDate.Text != "") { ddtime.DatePicker.DateTime = DateTime.ParseExact(txtGoalDate.Text, "MM-dd-yyyy", System.Globalization.CultureInfo.InvariantCulture); } //ddtime.DatePicker.DateTime = DateTime.Parse(txtGoalDate.Text); var origin = new DateTime(1970, 1, 1); ddtime.DatePicker.MinDate = (long)(DateTime.Now - origin).TotalMilliseconds; ddtime.DatePicker.MaxDate = (long)(DateTime.Now.Date.AddYears(3) - origin).TotalMilliseconds; ddtime.SetTitle(""); ddtime.Show(); } }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { // Use this to return your custom view for this Fragment // return inflater.Inflate(Resource.Layout.YourFragment, container, false); view = inflater.Inflate(Resource.Layout.FragmentCitas, container, false); Button btnGuardar = view.FindViewById <Button>(Resource.Id.btnGuardarCita); dateCita = view.FindViewById <Button>(Resource.Id.btnDateCita); timeCita = view.FindViewById <Button>(Resource.Id.btnTimeCita); especialidades = view.FindViewById <Spinner>(Resource.Id.cmbEspecialidades); especialistas = view.FindViewById <Spinner>(Resource.Id.cmbEspecialistas); //var data = new List<string> { "one", "two", "three" }; //ArrayAdapter adapter = new ArrayAdapter(view.Context, Resource.Id.cmbEspecialidades, data); //especialidades.Adapter = adapter; try { var especialidadesService = new EspecialidadesService(); var especialidadesList = especialidadesService.GetEspecialidades(); List <Especialidades> itemsNew = especialidadesList; List <string> items = new List <string>(); foreach (Especialidades x in especialidadesList) { items.Add(x.Name); } ArrayAdapter adapter = new ArrayAdapter(view.Context, Android.Resource.Layout.SimpleSpinnerItem, items); especialidades.Adapter = adapter; var especialistasService = new EspecialistasService(); var especialistasList = especialistasService.GetEspecialistas(); List <Especialistas> itemEspecialistas = especialistasList; foreach (Especialistas x in especialistasList) { itemsEsp.Add(new KeyValuePair <string, string>("Especialista: " + x.Name + " " + x.apellidos, x.Id.ToString())); } List <string> espName = new List <string>(); foreach (var item in itemsEsp) { espName.Add(item.Key); } var adapterEsp = new ArrayAdapter <string>(view.Context, Android.Resource.Layout.SimpleSpinnerItem, espName); especialistas.Adapter = adapterEsp; } catch (Exception e) { string tag = Convert.ToString(e); Log.Error(tag, "Error lis view"); Toast.MakeText(view.Context, "error" + e, ToastLength.Long).Show(); }; dateCita.Click += delegate { DateTime now = DateTime.Now; DatePickerDialog datePicker = new DatePickerDialog( view.Context, this, now.Year, now.Month, now.Day); datePicker.SetTitle("Fecha de cita"); datePicker.Show(); }; timeCita.Click += delegate { Calendar now = Calendar.Instance; TimePickerDialog datePicker = new TimePickerDialog( view.Context, this, now.Get(CalendarField.HourOfDay), now.Get(CalendarField.Minute), true ); datePicker.SetTitle("Hora de cita"); datePicker.Show(); }; string firstItem = especialidades.SelectedItem.ToString(); especialidadesName = firstItem; especialidades.ItemSelected += (s, e) => { // Toast.MakeText(view.Context, "" + e.Parent.GetItemAtPosition(e.Position).ToString(), ToastLength.Long).Show(); especialidadesName = e.Parent.GetItemAtPosition(e.Position).ToString(); }; especialistas.ItemSelected += new EventHandler <AdapterView.ItemSelectedEventArgs>(spinner_ItemSelected);; btnGuardar.Click += (s, e) => { ISharedPreferences preferences = GetSharedPreferences("SessionLogin", FileCreationMode.Private); var userId = preferences.GetString("SessionId", ""); //Toast.MakeText(this.Context, date + "hora: " + time + " especialidad: " + especialidadesName + "usuario" + userId+ " ID: "+idEspecialista, ToastLength.Long).Show(); var citas = _citasService.SetCitasRegister(date, time, especialidadesName, userId, idEspecialista); if (citas != null) { Toast.MakeText(this.Context, "Su cita se registro con exito ", ToastLength.Long).Show(); } else { Toast.MakeText(this.Context, "Erro al registrar ", ToastLength.Long).Show(); } }; return(view); }
public override View OnCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { View view = inflater.Inflate(Resource.Layout.datepicker_layout, container, false); // Find our View instances dateTextView = view.FindViewById <TextView>(Resource.Id.date_textview); Button dateButton = view.FindViewById <Button>(Resource.Id.date_button); modeDarkDate = view.FindViewById <CheckBox>(Resource.Id.mode_dark_date); modeCustomAccentDate = view.FindViewById <CheckBox>(Resource.Id.mode_custom_accent_date); vibrateDate = view.FindViewById <CheckBox>(Resource.Id.vibrate_date); dismissDate = view.FindViewById <CheckBox>(Resource.Id.dismiss_date); titleDate = view.FindViewById <CheckBox>(Resource.Id.title_date); showYearFirst = view.FindViewById <CheckBox>(Resource.Id.show_year_first); showVersion2 = view.FindViewById <CheckBox>(Resource.Id.show_version_2); switchOrientation = view.FindViewById <CheckBox>(Resource.Id.switch_orientation); limitSelectableDays = view.FindViewById <CheckBox>(Resource.Id.limit_dates); highlightDays = view.FindViewById <CheckBox>(Resource.Id.highlight_dates); defaultSelection = view.FindViewById <CheckBox>(Resource.Id.default_selection); view.FindViewById(Resource.Id.original_button).Click += (o, e) => { Calendar now = Calendar.Instance; new Android.App.DatePickerDialog( base.Activity, (object sender, Android.App.DatePickerDialog.DateSetEventArgs arg) => { Log.Debug("Orignal", "Got clicked"); }, now.Get(CalendarField.Year), now.Get(CalendarField.Month), now.Get(CalendarField.DayOfMonth) ).Show(); }; // Show a datepicker when the dateButton is clicked dateButton.Click += (o, e) => { Calendar now = Calendar.Instance; if (defaultSelection.Checked) { now.Add(CalendarField.Date, 7); } /* * It is recommended to always create a new instance whenever you need to show a Dialog. * The sample app is reusing them because it is useful when looking for regressions * during testing */ if (dpd == null) { dpd = DatePickerDialog.NewInstance( this, now.Get(CalendarField.Year), now.Get(CalendarField.Month), now.Get(CalendarField.DayOfMonth) ); } else { dpd.Initialize( this, now.Get(CalendarField.Year), now.Get(CalendarField.Month), now.Get(CalendarField.DayOfMonth) ); } dpd.ThemeDark = modeDarkDate.Checked; dpd.Vibrate(vibrateDate.Checked); dpd.DismissOnPause(dismissDate.Checked); dpd.ShowYearPickerFirst(showYearFirst.Checked); dpd.SetVersion(showVersion2.Checked ? DatePickerDialog.Version.Version2 : DatePickerDialog.Version.Version1); if (modeCustomAccentDate.Checked) { dpd.SetAccentColor("#9C27B0"); } if (titleDate.Checked) { dpd.SetTitle("DatePicker Title"); } if (highlightDays.Checked) { Calendar date1 = Calendar.Instance; Calendar date2 = Calendar.Instance; date2.Add(CalendarField.WeekOfMonth, -1); Calendar date3 = Calendar.Instance; date3.Add(CalendarField.WeekOfMonth, 1); Calendar[] days = { date1, date2, date3 }; dpd.SetHighlightedDays(days); } if (limitSelectableDays.Checked) { Calendar[] days = new Calendar[13]; for (int i = -6; i < 7; i++) { Calendar day = Calendar.Instance; day.Add(CalendarField.DayOfMonth, i * 2); days[i + 6] = day; } dpd.SetSelectableDays(days); } if (switchOrientation.Checked) { if (dpd.GetVersion() == DatePickerDialog.Version.Version1) { dpd.SetScrollOrientation(DatePickerDialog.ScrollOrientation.Horizontal); } else { dpd.SetScrollOrientation(DatePickerDialog.ScrollOrientation.Vertical); } } //dpd.SetOnCancelListener(dialog-> { // Log.Debug("DatePickerDialog", "Dialog was cancelled"); // dpd = null; //}); dpd.Show(RequireFragmentManager(), "Datepickerdialog"); }; return(view); }