Ejemplo n.º 1
0
 void SetToday()
 {
     if (_picker.MinimumDate.ToDateTime() <= DateTime.Today && _picker.MaximumDate.ToDateTime() >= DateTime.Today)
     {
         _picker.SetDate(DateTime.Today.ToNSDate(), true);
     }
 }
Ejemplo n.º 2
0
        private void BindDatePicker(UIDatePicker v)
        {
            if (startStopView == null)
            {
                return;
            }

            var currentValue = v.Date.ToDateTime().ToUtc();

            switch (startStopView.Selected)
            {
            case TimeKind.Start:
                if (currentValue != model.StartTime)
                {
                    v.SetDate(model.StartTime.ToNSDate(), !v.Hidden);
                }
                break;

            case TimeKind.Stop:
                if (currentValue != model.StopTime)
                {
                    v.SetDate(model.StopTime.Value.ToNSDate(), !v.Hidden);
                }
                break;
            }
        }
Ejemplo n.º 3
0
 public void Cancel()
 {
     if (_picker != null)
     {
         _picker.SetDate(_initialTime, false);
         _picker.EndEditing(false);
     }
 }
Ejemplo n.º 4
0
 private void refreshPicker()
 {
     if (TaskItem.CompletionDate == null)
     {
         saveButton.Title = "Mark Complete";
         CompleteTimePicker.SetDate(ViewControllerHelper.DateTimeUtcToNSDate(DateTime.UtcNow), true);
     }
     else
     {
         saveButton.Title = "Mark Incomplete";
         CompleteTimePicker.SetDate(ViewControllerHelper.DateTimeUtcToNSDate(Util.GetInstance().GetServerTime(TaskItem.CompletionDate.Value)), true);
     }
 }
Ejemplo n.º 5
0
        void UpdateDateFromModel(bool animate)
        {
            if (_picker.Date.ToDateTime().Date != Element.Date.Date)
            {
                _picker.SetDate(Element.Date.ToNSDate(), animate);
            }

            //can't use Element.Format because it won't display the correct format if the region and language are set differently
            if (String.IsNullOrWhiteSpace(Element.Format) || Element.Format.Equals("d") || Element.Format.Equals("D"))
            {
                NSDateFormatter dateFormatter = new NSDateFormatter();
                if (Element.Format?.Equals("D") == true)
                {
                    dateFormatter.DateStyle = NSDateFormatterStyle.Long;
                    var strDate = dateFormatter.StringFor(_picker.Date);
                    Control.Text = strDate;
                }
                else
                {
                    dateFormatter.DateStyle = NSDateFormatterStyle.Short;
                    var strDate = dateFormatter.StringFor(_picker.Date);
                    Control.Text = strDate;
                }
            }
            else if (Element.Format.Contains("/"))
            {
                Control.Text = Element.Date.ToString(Element.Format, CultureInfo.InvariantCulture);
            }
            else
            {
                Control.Text = Element.Date.ToString(Element.Format);
            }
        }
        private void ConfigureDatePicker()
        {
            datePicker = new UIDatePicker
            {
                Mode        = UIDatePickerMode.Date,
                Date        = (NSDate)AllItemsViewModel.GetInitialPickerDate(),
                MinimumDate = (NSDate)AllItemsViewModel.GetStartOfPayPeriod(),
                MaximumDate = (NSDate)AllItemsViewModel.GetEndOfPayPeriod(),
                TimeZone    = NSTimeZone.LocalTimeZone
            };

            // Whenever the date changes, set the date text field to the value of the picker
            datePicker.ValueChanged += (sender, e) =>
            {
                txtDateField.Text = ((DateTime)datePicker.Date).ToLocalTime().ToString(ProjectSettings.DateFormat);
            };

            txtDateField.Text      = ((DateTime)datePicker.Date).ToLocalTime().ToString(ProjectSettings.DateFormat);
            txtDateField.InputView = datePicker;

            if (EditingItem != null)
            {
                // If the user is editing this entry, set the picker to the previously selected date
                txtDateField.Text = EditingItem.JobDate.ToLocalTime().ToString(ProjectSettings.DateFormat);
                datePicker.SetDate((NSDate)EditingItem.JobDate, false);
            }
        }
Ejemplo n.º 7
0
 public static void UpdateDate(this UIDatePicker picker, IDatePicker datePicker)
 {
     if (picker != null && picker.Date.ToDateTime().Date != datePicker.Date.Date)
     {
         picker.SetDate(datePicker.Date.ToNSDate(), false);
     }
 }
Ejemplo n.º 8
0
        protected override void OnLoaded()
        {
            base.OnLoaded();

            _picker = this.FindSubviewsOfType <UIDatePicker>()
                      .FirstOrDefault();

            var parent = _picker.FindFirstParent <FrameworkElement>();

            if (_picker != null)
            {
                _picker.Mode     = UIDatePickerMode.Date;
                _picker.TimeZone = NSTimeZone.LocalTimeZone;
                _picker.Calendar = new NSCalendar(NSCalendarType.Gregorian);
                _picker.SetDate(Date.Date.ToNSDate(), animated: false);

                //Removing the date picker and adding it is what enables the lines to appear. Seems to be a side effect of adding it as a view.
                if (parent != null)
                {
                    parent.RemoveChild(_picker);
                    parent.AddSubview(_picker);
                }

                RegisterValueChanged();
            }
        }
Ejemplo n.º 9
0
        void UpdateDate()
        {
            var date = DatePickerDialog.GetDate(Element).ToNSDate();

            _picker.SetDate(date, false);
            _preSelectedDate = date;
        }
Ejemplo n.º 10
0
 void UpdateDateFromModel(bool animate)
 {
     if (_picker.Date.ToDateTime() != Element.Date)
     {
         _picker.SetDate(Element.Date.ToNSDate(), animate);
     }
     Control.Text = Element.Date.ToString(Element.Format);
 }
Ejemplo n.º 11
0
 internal void Cancel()
 {
     if (_initialValue is {} initialDate)
     {
         _picker?.SetDate(initialDate, false);
     }
     _picker?.EndEditing(false);
 }
 public DateSelectionViewController()
 {
     Title       = "Select a date range";
     StartPicker = new UIDatePicker();
     StartPicker.SetDate((NSDate) new DateTime(1998, 1, 1, 0, 0, 0, DateTimeKind.Local), false);
     EndPicker = new UIDatePicker();
     EndPicker.SetDate((NSDate) new DateTime(1998, 1, 31, 0, 0, 0, DateTimeKind.Local), false);
 }
Ejemplo n.º 13
0
        private void BindDatePicker(UIDatePicker v)
        {
            if (startStopView == null)
            {
                return;
            }

            switch (startStopView.Selected)
            {
            case TimeKind.Start:
                v.SetDate(model.StartTime.ToNSDate(), !v.Hidden);
                break;

            case TimeKind.Stop:
                v.SetDate(model.StopTime.Value.ToNSDate(), !v.Hidden);
                break;
            }
        }
Ejemplo n.º 14
0
        partial void OnDateChangedPartialNative(DateTimeOffset oldDate, DateTimeOffset newDate)
        {
            // Animate to cover up the small delay in setting the date when the flyout is opened
            var animated = !UIDevice.CurrentDevice.CheckSystemVersion(10, 0);

            _picker?.SetDate(
                DateTime.SpecifyKind(newDate.DateTime, DateTimeKind.Local).ToNSDate(),
                animated: animated
                );
        }
Ejemplo n.º 15
0
        private void SetPickerTime(TimeSpan newTime)
        {
            if (_picker == null)
            {
                return;
            }

            // Because the UIDatePicker is set to use LocalTimeZone,
            // we need to get the offset and apply it to the requested time.
            var offset = TimeSpan.FromSeconds(_picker.TimeZone.GetSecondsFromGMT);

            // Because the UIDatePicker applies the local timezone offset automatically when we set it,
            // we need to compensate with a negated offset. This will show the time
            // as if it was provided with no offset.
            var timeWithOffset = newTime.Add(offset.Negate());
            var nsDate         = timeWithOffset.ToNSDate();

            _picker.SetDate(nsDate, animated: false);
        }
Ejemplo n.º 16
0
        public DateSelectionViewController()
        {
            Title = "Select a date range";

            // Configured here because these need to be initialized before the view is loaded/presented.
            StartPicker = new UIDatePicker();
            StartPicker.SetDate((NSDate) new DateTime(1998, 1, 1, 0, 0, 0, DateTimeKind.Local), false);
            EndPicker = new UIDatePicker();
            EndPicker.SetDate((NSDate) new DateTime(1998, 1, 31, 0, 0, 0, DateTimeKind.Local), false);
        }
Ejemplo n.º 17
0
        private void Schedule_ScheduleTapped(object sender, CellTappedEventArgs e)
        {
            editor.Hidden      = false;
            schedule.Hidden    = true;
            indexOfAppointment = -1;
            if (e.ScheduleAppointment != null)
            {
                for (int i = 0; i < (schedule.ItemsSource as ObservableCollection <ScheduleAppointment>).Count; i++)
                {
                    if ((schedule.ItemsSource as ObservableCollection <ScheduleAppointment>)[i] == e.ScheduleAppointment)
                    {
                        indexOfAppointment = int.Parse(i.ToString());
                        break;
                    }
                }

                selectedAppointment = e.ScheduleAppointment;
                labelSubject.Text   = selectedAppointment.Subject;
                labelLocation.Text  = selectedAppointment.Location;
                String startDate = DateTime.Parse(selectedAppointment.StartTime.ToString()).ToString();
                buttonStartDate.SetTitle(startDate, UIControlState.Normal);
                pickerStartDate.SetDate(selectedAppointment.StartTime, true);
                String endDate = DateTime.Parse(selectedAppointment.EndTime.ToString()).ToString();
                buttonEndDate.SetTitle(endDate, UIControlState.Normal);
                pickerEndDate.SetDate(selectedAppointment.EndTime, true);
                editor.EndEditing(true);
            }
            else
            {
                List <UIColor> colorCollection = new List <UIColor>();
                colorCollection.Add(UIColor.FromRGB(0xA2, 0xC1, 0x39));
                colorCollection.Add(UIColor.FromRGB(0xD8, 0x00, 0x73));
                labelSubject.Text  = "Subject";
                labelLocation.Text = "Location";
                String startDate = DateTime.Parse(e.Date.ToString()).ToString();
                pickerStartDate.SetDate(e.Date, true);
                buttonStartDate.SetTitle(startDate, UIControlState.Normal);
                String endDate = DateTime.Parse(e.Date.AddSeconds(3600).ToString()).ToString();
                pickerEndDate.SetDate(e.Date.AddSeconds(3600), true);
                buttonEndDate.SetTitle(endDate, UIControlState.Normal);
            }
        }
        private void UpdateDateFromModel(bool animate)
        {
            var date = new DateTime(Element.DateTicks);

            if (_picker.Date.ToDateTime() != date)
            {
                _picker.SetDate(date.ToNSDate(), animate);
            }

            Control.Text = date.ToString(Element.Format);
        }
Ejemplo n.º 19
0
 private void Schedule_ScheduleTapped(object sender, CellTappedEventArgs e)
 {
     editor.Hidden      = false;
     schedule.Hidden    = true;
     indexOfAppointment = -1;
     if (e.ScheduleAppointment != null)
     {
         for (nuint i = 0; i < schedule.Appointments.Count; i++)
         {
             if (schedule.Appointments.GetItem <ScheduleAppointment>(i) == e.ScheduleAppointment)
             {
                 indexOfAppointment = int.Parse(i.ToString());
                 break;
             }
         }
         selectedAppointment = (e.ScheduleAppointment);
         label_subject.Text  = selectedAppointment.Subject;
         label_location.Text = selectedAppointment.Location;
         String _sDate = DateTime.Parse((selectedAppointment.StartTime.ToString())).ToString();
         button_startDate.SetTitle(_sDate, UIControlState.Normal);
         picker_startDate.SetDate(selectedAppointment.StartTime, true);
         String _eDate = DateTime.Parse((selectedAppointment.EndTime.ToString())).ToString();
         button_endDate.SetTitle(_eDate, UIControlState.Normal);
         picker_endDate.SetDate(selectedAppointment.EndTime, true);
         editor.EndEditing(true);
     }
     else
     {
         List <UIColor> colorCollection = new List <UIColor>();
         colorCollection.Add(UIColor.FromRGB(0xA2, 0xC1, 0x39));
         colorCollection.Add(UIColor.FromRGB(0xD8, 0x00, 0x73));
         label_subject.Text  = "Subject";
         label_location.Text = "Location";
         String _sDate = DateTime.Parse((e.Date.ToString())).ToString();
         picker_startDate.SetDate(e.Date, true);
         button_startDate.SetTitle(_sDate, UIControlState.Normal);
         String _eDate = DateTime.Parse((e.Date.AddSeconds(3600).ToString())).ToString();
         picker_endDate.SetDate(e.Date.AddSeconds(3600), true);
         button_endDate.SetTitle(_eDate, UIControlState.Normal);
     }
 }
Ejemplo n.º 20
0
 protected virtual void BindDatePicker(UIDatePicker datePicker, DateTime?minDate, DateTime?maxDate)
 {
     if (minDate != null)
     {
         datePicker.MinimumDate = minDate.Value.ToNSDateUTC();
     }
     if (maxDate != null)
     {
         datePicker.SetDate((maxDate.Value.AddDays(-1).ToNSDateUTC()), false);
         datePicker.MaximumDate = maxDate.Value.ToNSDateUTC();
     }
 }
 /// <summary>
 /// Updates the date from model.
 /// </summary>
 /// <param name="animate">if set to <c>true</c> [animate].</param>
 private void UpdateDateFromModel(bool animate)
 {
     if (Element.Date.HasValue)
     {
         var date = Element.Date.Value;
         _picker.SetDate(date.ToNSDate(), animate);
         Control.Text = date.ToString(Element.Format);
     }
     else
     {
         Control.Text = Element.NullText;
     }
 }
Ejemplo n.º 22
0
        private void UpdatePickerValue(DateTimeOffset value, bool animated = false)
        {
            var components = new NSDateComponents()
            {
                Year  = value.Year,
                Month = value.Month,
                Day   = value.Day,
            };
            var date = _picker.Calendar.DateFromComponents(components);

            _picker.SetDate(date, animated);
            _initialValue = date;
        }
Ejemplo n.º 23
0
 private void UpdateDate()
 {
     if (blankPicker.DateSet)
     {
         blankPicker.Text = Control.Text = blankPicker.Date.Date.ToString(blankPicker.Format);
         if (_picker.Date.ToDateTime().Date != blankPicker.Date.Date)
         {
             _picker.SetDate(blankPicker.Date.Date.ToNSDate(), false);
         }
     }
     else
     {
         blankPicker.Text = Control.Text = string.Empty;
     }
 }
Ejemplo n.º 24
0
        private void SetDateOfBirth()
        {
            if (ViewModel.Person.DateOfBirth.HasValue)
            {
                var dob = ViewModel.Person.DateOfBirth.Value;
                dateOfBirthButton.SetTitle(dob.ToString("MMMM d, yyyy"), UIControlState.Normal);
            }
            else
            {
                dateOfBirthButton.SetTitle(ViewModel.Mode == Core.AppMode.Agent ? "Tap to set Birth Date" : string.Empty, UIControlState.Normal);
            }

            var dt = ViewModel.Person.DateOfBirth.HasValue ? ViewModel.Person.DateOfBirth.Value : DateTime.Now;

            _datePicker.SetDate(DateTime.SpecifyKind(dt, DateTimeKind.Utc), false);
        }
Ejemplo n.º 25
0
            protected internal override void NativeInit()
            {
                if (this.NativeUIElement == null)
                {
                    var nativePicker = new UIDatePicker
                    {
                        Locale      = NSLocale.FromLocaleIdentifier(CultureInfo.CurrentUICulture.Name.Replace('-', '_')),
                        MaximumDate = ConvertDate(parent.MaxYear),
                        MinimumDate = ConvertDate(parent.MinYear),
                        Mode        = UIDatePickerMode.Date
                    };
                    nativePicker.SetDate(ConvertDate(parent.Date), false);
                    nativePicker.ValueChanged += OnDateChanged;
                    this.NativeUIElement       = nativePicker;
                }

                base.NativeInit();
            }
Ejemplo n.º 26
0
        public void Nulls()
        {
            using (UIDatePicker dp = new UIDatePicker()) {
                dp.Calendar    = null;
                dp.Locale      = null;
                dp.MinimumDate = null;
                dp.MaximumDate = null;
                dp.TimeZone    = null;

                // some null checks are done, otherwise we end up with
                // Objective-C exception thrown.  Name: NSInternalInconsistencyException Reason: Invalid parameter not satisfying: date
                Assert.Throws <ArgumentNullException> (delegate {
                    dp.Date = null;
                });
                Assert.Throws <ArgumentNullException> (delegate {
                    dp.SetDate(null, true);
                });
            }
        }
Ejemplo n.º 27
0
        partial void OnDateChangedPartialNative(DateTimeOffset oldDate, DateTimeOffset newDate)
        {
            // We have to change the DateTimeOffset to something readable by the UIDatePicker.
            // First, we remove the offset to keep only the date.
            // Then, we add 24 hours (1 day) when the offset is negative (timezone east of GMT) because the UIDatePicker is wrong by 1 day in this case.
            var ajustedDate = newDate
                              .ToOffset(TimeSpan.Zero)
                              .Add(newDate.Offset);

            if (newDate.Offset.TotalSeconds < 0)
            {
                ajustedDate = ajustedDate.AddHours(24);
            }
            var nsDate = ajustedDate.Date.ToNSDate();

            // Animate to cover up the small delay in setting the date when the flyout is opened
            var animated = !UIDevice.CurrentDevice.CheckSystemVersion(10, 0);

            _picker?.SetDate(nsDate, animated: animated);
        }
Ejemplo n.º 28
0
        void  SetTimePicker()
        {
            UIDatePicker picker = new UIDatePicker
            {
                Mode = UIDatePickerMode.DateAndTime
            };

            picker.SetDate(NSDate.Now, true);
            picker.AddTarget(this, new Selector("DateChange:"), UIControlEvent.ValueChanged);
            Control.InputView = picker;
            UIToolbar       toolbar = (UIToolbar)Control.InputAccessoryView;
            UIBarButtonItem done    = new UIBarButtonItem("Done", UIBarButtonItemStyle.Done, (object sender, EventArgs click) =>
            {
                Control.Text = SelectedValue;
                toolbar.RemoveFromSuperview();
                picker.RemoveFromSuperview();
                Control.ResignFirstResponder();
                MessagingCenter.Send <Object, string>(this, "pickerSelected", SelectedValue);
            });
            UIBarButtonItem empty = new UIBarButtonItem(UIBarButtonSystemItem.FlexibleSpace, null);

            toolbar.Items = new UIBarButtonItem[] { empty, done };
        }
Ejemplo n.º 29
0
 private void SetPickerTime(TimeSpan time)
 {
     _picker?.SetDate(time.ToNSDate(), animated: false);
 }
Ejemplo n.º 30
0
        private void BindDatePicker (UIDatePicker v)
        {
            if (startStopView == null)
                return;

            var currentValue = v.Date.ToDateTime ().ToUtc ();

            switch (startStopView.Selected) {
            case TimeKind.Start:
                if (currentValue != model.StartTime) {
                    v.SetDate (model.StartTime.ToNSDate (), !v.Hidden);
                }
                break;
            case TimeKind.Stop:
                if (currentValue != model.StopTime) {
                    v.SetDate (model.StopTime.Value.ToNSDate (), !v.Hidden);
                }
                break;
            }
        }
Ejemplo n.º 31
0
 /// <summary>
 /// Updates the date from model.
 /// </summary>
 /// <param name="animate">if set to <c>true</c> [animate].</param>
 private void UpdateDateFromModel(bool animate)
 {
     _picker.SetDate(Element.Date.ToNSDate(), animate);
     Control.Text = Element.Date.ToString(Element.Format);
 }
        private void BindDatePicker (UIDatePicker v)
        {
            if (startStopView == null)
                return;

            switch (startStopView.Selected) {
            case TimeKind.Start:
                v.SetDate (model.StartTime.ToNSDate (), !v.Hidden);
                break;
            case TimeKind.Stop:
                v.SetDate (model.StopTime.Value.ToNSDate (), !v.Hidden);
                break;
            }
        }