void UpdateUsersAge()
        {
            NSError error;
            NSDate  dateOfBirth = HealthStore.GetDateOfBirth(out error);

            if (error != null)
            {
                Console.WriteLine("An error occured fetching the user's age information. " +
                                  "In your app, try to handle this gracefully. The error was: {0}", error);
                return;
            }

            if (dateOfBirth == null)
            {
                return;
            }

            var now = NSDate.Now;

            NSDateComponents ageComponents = NSCalendar.CurrentCalendar.Components(NSCalendarUnit.Year, dateOfBirth, now,
                                                                                   NSCalendarOptions.WrapCalendarComponents);

            nint usersAge = ageComponents.Year;

            ageHeightValueLabel.Text = string.Format("{0} years", usersAge);
        }
Esempio n. 2
0
        private void EditorView_TouchUpInside(object sender, EventArgs e)
        {
            scheduleEditor.Editor.Hidden = false;
            schedule.Hidden   = true;
            headerView.Hidden = true;
            tableView.Hidden  = true;

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
            NSDate startDate = calendar.DateFromComponents(components);

            scheduleEditor.label_subject.Text  = "Subject";
            scheduleEditor.label_location.Text = "Location";
            String _sDate = DateTime.Parse((startDate.ToString())).ToString();

            scheduleEditor.picker_startDate.SetDate(startDate, true);
            scheduleEditor.button_startDate.SetTitle(_sDate, UIControlState.Normal);
            String _eDate = DateTime.Parse((startDate.AddSeconds(3600).ToString())).ToString();

            scheduleEditor.picker_endDate.SetDate(startDate.AddSeconds(3600), true);
            scheduleEditor.button_endDate.SetTitle(_eDate, UIControlState.Normal);
        }
Esempio n. 3
0
        public void IssueNotificationAsync(string id, UNNotificationContent content, DateTime triggerDateTime, Action <UNNotificationRequest> requestCreated = null)
        {
            UNCalendarNotificationTrigger trigger = null;

            // we're going to specify an absolute trigger date below. if this time is in the past by the time
            // the notification center processes it (race condition), then the notification will not be scheduled.
            // so ensure that we leave some time to avoid the race condition by triggering an immediate notification
            // for any trigger date that is not greater than several seconds into the future.
            if (triggerDateTime > DateTime.Now + iOSCallbackScheduler.CALLBACK_NOTIFICATION_HORIZON_THRESHOLD)
            {
                NSDateComponents triggerDateComponents = new NSDateComponents
                {
                    Year     = triggerDateTime.Year,
                    Month    = triggerDateTime.Month,
                    Day      = triggerDateTime.Day,
                    Hour     = triggerDateTime.Hour,
                    Minute   = triggerDateTime.Minute,
                    Second   = triggerDateTime.Second,
                    Calendar = NSCalendar.CurrentCalendar,
                    TimeZone = NSTimeZone.LocalTimeZone
                };

                trigger = UNCalendarNotificationTrigger.CreateTrigger(triggerDateComponents, false);
            }

            UNNotificationRequest notificationRequest = UNNotificationRequest.FromIdentifier(id, content, trigger);

            requestCreated?.Invoke(notificationRequest);
            IssueNotificationAsync(notificationRequest);
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
            this.CurrentFrame = new CGRect(0, 0, UIScreen.MainScreen.Bounds.Size.Width, UIScreen.MainScreen.Bounds.Size.Height);
            this.AddButton();
            //Creating an instance for SfSchedule control
            SFSchedule schedule = new SFSchedule();

            schedule.Frame        = new CGRect(0, removeExceptionAppointment.Frame.Bottom, this.CurrentFrame.Size.Width, this.CurrentFrame.Size.Height - removeExceptionAppointment.Frame.Bottom);
            schedule.ScheduleView = SFScheduleView.SFScheduleViewWeek;

            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);
            NSDate     today    = NSDate.Now;
            // Get the year, month, day from the date
            NSDateComponents startDateComponents = calendar.Components(NSCalendarUnit.Year |
                                                                       NSCalendarUnit.Month |
                                                                       NSCalendarUnit.Day, today);

            // Set the year, month, day, hour, minute, second
            startDateComponents.Year   = 2017;
            startDateComponents.Month  = 09;
            startDateComponents.Day    = 03;
            startDateComponents.Hour   = 10;
            startDateComponents.Minute = 0;
            startDateComponents.Second = 0;

            //setting start time for the event
            NSDate startDate = calendar.DateFromComponents(startDateComponents);

            //setting end time for the event
            NSDate endDate = startDate.AddSeconds(2 * 60 * 60);

            // set moveto date to schedule
            schedule.MoveToDate(startDate);

            // Set the exception dates.
            var exceptionDate1 = startDate;
            var exceptionDate2 = startDate.AddSeconds(2 * 24 * 60 * 60);

            exceptionDate3 = startDate.AddSeconds(4 * 24 * 60 * 60);

            // Add Schedule appointment
            ScheduleAppointment recurrenceAppointment = new ScheduleAppointment();

            recurrenceAppointment.Id                       = 1;
            recurrenceAppointment.StartTime                = startDate;
            recurrenceAppointment.EndTime                  = endDate;
            recurrenceAppointment.Subject                  = (NSString)"Occurs Daily";
            recurrenceAppointment.AppointmentBackground    = UIColor.Blue;
            recurrenceAppointment.RecurrenceRule           = (NSString)"FREQ=DAILY;COUNT=20";
            recurrenceAppointment.RecurrenceExceptionDates = new System.Collections.ObjectModel.ObservableCollection <NSDate> {
                exceptionDate1,
                exceptionDate2,
                exceptionDate3
            };

            scheduleAppointmentCollection.Add(recurrenceAppointment);
            schedule.ItemsSource = scheduleAppointmentCollection;
            this.View.AddSubview(schedule);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a scheduled toast notification with the required values.
        /// </summary>
        /// <param name="content">Text content.</param>
        /// <param name="title">Toast title.</param>
        /// <param name="deliveryTime">When to display the toast.</param>
        /// <returns></returns>
        public static ScheduledToastNotification CreateScheduledToastNotification(string content, string title, DateTimeOffset deliveryTime)
        {
#if WINDOWS_UWP || WINDOWS_APP || WINDOWS_PHONE_APP || WINDOWS_PHONE_81
            XmlDocument doc          = Windows.UI.Notifications.ToastNotificationManager.GetTemplateContent(ToastTemplateType.ToastText02);
            var         textElements = doc.GetElementsByTagName("text");
            textElements[0].InnerText = title;
            textElements[1].InnerText = content;
            return(new ScheduledToastNotification(new Windows.UI.Notifications.ScheduledToastNotification(doc, deliveryTime)));
#elif WINDOWS_PHONE
            throw new PlatformNotSupportedException();
#elif __ANDROID__
            throw new PlatformNotSupportedException();
#elif __MAC__
            NSUserNotification notification = new NSUserNotification();
            notification.Title           = title;
            notification.InformativeText = content;
            notification.SoundName       = NSUserNotification.NSUserNotificationDefaultSoundName;
            notification.DeliveryDate    = deliveryTime.ToNSDate();
            return(notification);
#elif __UNIFIED__
            UNMutableNotificationContent notificationContent = new UNMutableNotificationContent();
            notificationContent.Title = title;
            notificationContent.Body  = content;
            notificationContent.Sound = UNNotificationSound.Default;
            NSDateComponents dc = NSCalendar.CurrentCalendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day | NSCalendarUnit.Hour | NSCalendarUnit.Minute | NSCalendarUnit.Second, deliveryTime.ToNSDate());
            UNCalendarNotificationTrigger trigger = UNCalendarNotificationTrigger.CreateTrigger(dc, false);

            return(new ScheduledToastNotification(notificationContent, trigger));
#else
            return(new ScheduledToastNotification(content, title, deliveryTime));
#endif
        }
Esempio n. 6
0
        public override void ViewDidLoad()
        {
            this.CreateEvents();

            base.ViewDidLoad();

            this.calendarDataSource = new CalendarDataSource(this);

            this.CalendarView = new TKCalendar(this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.CalendarView.DataSource       = this.calendarDataSource;
            this.View.AddSubview(this.CalendarView);

            NSDate           date       = NSDate.Now;
            NSDateComponents components = new NSDateComponents();

            components.Year           = -1;
            this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, NSCalendarOptions.None);
            components.Year           = 1;
            this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, NSCalendarOptions.None);

            TKCalendarMonthPresenter presenter = (TKCalendarMonthPresenter)this.CalendarView.Presenter;

            if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                presenter.InlineEventsViewMode = TKCalendarInlineEventsViewMode.Popover;
            }
            else
            {
                presenter.InlineEventsViewMode = TKCalendarInlineEventsViewMode.Inline;
            }
            presenter.InlineEventsView             = new MyInlineEventsView();
            presenter.InlineEventsView.MaxHeight   = 140;
            presenter.InlineEventsView.FixedHeight = false;
        }
        public void IssueNotificationAsync(string id, UNNotificationContent content, TimeSpan delay, Action <UNNotificationRequest> requestCreated = null)
        {
            UNCalendarNotificationTrigger trigger = null;

            // a non-positive delay indicates an immediate notification, which is achieved with a null trigger.
            if (delay.Ticks > 0)
            {
                // we're going to specify an absolute date below based on the current time and the given delay. if this time is in the past by the time
                // the notification center processes it (race condition), then the notification will not be scheduled. so ensure that we leave some time
                // and avoid the race condition.
                if (delay.TotalSeconds < 5)
                {
                    delay = TimeSpan.FromSeconds(5);
                }

                DateTime         triggerDateTime       = DateTime.Now + delay;
                NSDateComponents triggerDateComponents = new NSDateComponents
                {
                    Year   = triggerDateTime.Year,
                    Month  = triggerDateTime.Month,
                    Day    = triggerDateTime.Day,
                    Hour   = triggerDateTime.Hour,
                    Minute = triggerDateTime.Minute,
                    Second = triggerDateTime.Second
                };

                trigger = UNCalendarNotificationTrigger.CreateTrigger(triggerDateComponents, false);
            }

            UNNotificationRequest notificationRequest = UNNotificationRequest.FromIdentifier(id, content, trigger);

            requestCreated?.Invoke(notificationRequest);
            IssueNotificationAsync(notificationRequest);
        }
        public void SchedulingNotifications(string Title, string Subtitle, string Body, string requestID, DateTime inputDate, Page page)
        {
            bool alertsAllowed = true;

            UNUserNotificationCenter.Current.GetNotificationSettings((settings) =>
            {
                alertsAllowed = (settings.AlertSetting == UNNotificationSetting.Enabled);
            });

            var content = new UNMutableNotificationContent();

            content.Title    = Title;
            content.Subtitle = Subtitle;
            content.Body     = Body;
            content.Badge    = 1;

            var date = new NSDateComponents();

            date.Hour  = inputDate.Hour;
            date.Day   = inputDate.Day;
            date.Month = inputDate.Month;
            date.Year  = inputDate.Year;

            var trigger = UNCalendarNotificationTrigger.CreateTrigger(date, true);

            var request = UNNotificationRequest.FromIdentifier(requestID, content, trigger);

            UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => {
                if (err != null)
                {
                    // Do something with error...
                }
            });
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            commonHelper = new CommonHelper();
            this.NavigationItem.Title = "Last Worn Date";

            // create next button
            nextButton = new UIBarButtonItem("Other Details", UIBarButtonItemStyle.Plain, NextButtonClickAction);
            NavigationItem.SetRightBarButtonItem(nextButton, true);

            // create previous button
            prevButton = new UIBarButtonItem("ItemType", UIBarButtonItemStyle.Plain, PrevButtonClickAction);
            NavigationItem.SetLeftBarButtonItem(prevButton, true);


            var calendar    = new NSCalendar(NSCalendarType.Gregorian);
            var currentDate = NSDate.Now;
            var components  = new NSDateComponents();

            components.Year = -60;

            NSDate minDate = calendar.DateByAddingComponents(components, NSDate.Now, NSCalendarOptions.None);

            Console.WriteLine("ViewDidLoad, before AddScreenLayout wardrobeObj" + wardrobeObj.ItemType);



            AddScreenLayout();
        }
Esempio n. 10
0
        private void EditorView_TouchUpInside(object sender, EventArgs e)
        {
            ScheduleEditor.Editor.Hidden = false;
            Schedule.Hidden   = true;
            HeaderView.Hidden = true;
            TableView.Hidden  = true;

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);
            NSDate startDate = calendar.DateFromComponents(components);

            ScheduleEditor.LabelSubject.Text  = "Subject";
            ScheduleEditor.LabelLocation.Text = "Location";
            String startDate1 = DateTime.Parse(startDate.ToString()).ToString();

            ScheduleEditor.PickerStartDate.SetDate(startDate, true);
            ScheduleEditor.ButtonStartDate.SetTitle(startDate1, UIControlState.Normal);
            String endDate = DateTime.Parse(startDate.AddSeconds(3600).ToString()).ToString();

            ScheduleEditor.PickerEndDate.SetDate(startDate.AddSeconds(3600), true);
            ScheduleEditor.ButtonEndDate.SetTitle(endDate, UIControlState.Normal);
        }
Esempio n. 11
0
		public override void ViewDidLoad ()
		{
			this.CreateEvents ();

			base.ViewDidLoad ();

			this.calendarDataSource = new CalendarDataSource (this);

			this.CalendarView = new TKCalendar (this.View.Bounds);
			this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
			this.CalendarView.DataSource = this.calendarDataSource;
			this.View.AddSubview (this.CalendarView);

			NSDate date = NSDate.Now;
			NSDateComponents components = new NSDateComponents ();
			components.Year = -1;
			this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);
			components.Year = 1;
			this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);

			TKCalendarMonthPresenter presenter = (TKCalendarMonthPresenter)this.CalendarView.Presenter;
			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
				presenter.InlineEventsViewMode = TKCalendarInlineEventsViewMode.Popover;
			} else {
				presenter.InlineEventsViewMode = TKCalendarInlineEventsViewMode.Inline;
			}
			presenter.InlineEventsView = new MyInlineEventsView ();
			presenter.InlineEventsView.MaxHeight = 140;
			presenter.InlineEventsView.FixedHeight = false;
		}
Esempio n. 12
0
        //public int NumberOfNotifi()
        //{
        //    int output = 0;
        //    foreach (var item in tasks)
        //    {
        //        if (item.Notification)
        //        {
        //            if (0 <= DateTime.Compare(DateTime.Now, Extensions.NSDateToDateTime(item.DateAndTime)))
        //            {
        //                output++;
        //            }
        //        }
        //    }
        //    return output;
        //}

        private void AddNewNotification(Task task)
        {
            var content = new UNMutableNotificationContent();

            content.Title = task.Name + " - " + task.Cattegory;
            content.Body  = task.ShortLabel;
            content.Badge = 0;

            NSDateComponents dateNotifiComp = new NSDateComponents();
            DateTime         dateNotifi     = Extensions.NSDateToDateTime(task.DateAndTime);

            dateNotifiComp.Minute = dateNotifi.Minute;
            dateNotifiComp.Hour   = dateNotifi.Hour;
            dateNotifiComp.Day    = dateNotifi.Day;
            dateNotifiComp.Month  = dateNotifi.Month;
            dateNotifiComp.Year   = dateNotifi.Year;

            var trigger = UNCalendarNotificationTrigger.CreateTrigger(dateNotifiComp, false);

            dateNotifi = dateNotifi.AddSeconds(-dateNotifi.Second);
            var requestID = task.Name + dateNotifi.ToString();
            var request   = UNNotificationRequest.FromIdentifier(requestID, content, trigger);

            Console.WriteLine(requestID);

            UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => {
                if (err != null)
                {
                    System.Console.WriteLine(err);
                }
            });
        }
Esempio n. 13
0
        // Sets the cell's text to represent an exact time condition.
        public void SetOrder(TimeConditionOrder order, NSDateComponents dateComponents)
        {
            var date       = NSCalendar.CurrentCalendar.DateFromComponents(dateComponents);
            var timeString = DateFormatter.StringFor(date);

            SetOrder(order, timeString, "Relative to Time");
        }
Esempio n. 14
0
        private void UpdatMinMaxYears()
        {
            if (_picker == null)
            {
                return;
            }

            var calendar = new NSCalendar(NSCalendarType.Gregorian);
            var maximumDateComponents = new NSDateComponents
            {
                Day   = MaxYear.Day,
                Month = MaxYear.Month,
                Year  = MaxYear.Year
            };

            _picker.MaximumDate = calendar.DateFromComponents(maximumDateComponents);

            var minimumDateComponents = new NSDateComponents
            {
                Day   = MinYear.Day,
                Month = MinYear.Month,
                Year  = MinYear.Year
            };

            _picker.MinimumDate = calendar.DateFromComponents(minimumDateComponents);
        }
Esempio n. 15
0
        public override void ViewDidLoad()
        {
            this.AddOption ("Russian", SelectRussian);
            this.AddOption ("German", SelectGerman);
            this.AddOption ("Hebrew", SelectHebrew);
            this.AddOption ("Chinese", SelectChinese);
            this.AddOption ("Islamic", SelectIslamic);

            this.SelectedOption = 2;

            base.ViewDidLoad ();

            this.CalendarView = new TKCalendar (this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
            this.View.AddSubview (this.CalendarView);

            NSDate date = NSDate.Now;
            NSDateComponents components = new NSDateComponents ();
            components.Year = -1;
            this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);
            components.Year = 1;
            this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);

            this.SelectHebrew (this, EventArgs.Empty);
        }
		public static HomeKitCondition CreateExactTime (TimeConditionOrder order, NSDateComponents components)
		{
			return new HomeKitCondition {
				ExactTimeData = new Tuple<TimeConditionOrder, NSDateComponents> (order, components),
				Type = HomeKitConditionType.ExactTime
			};
		}
Esempio n. 17
0
        public void ScheduleNewPicture(DateTime timeSetting)
        {
            string id      = NotificationType.NewPicture.ToString();
            var    content = new UNMutableNotificationContent
            {
                Title    = Notifications.Title.NewPicture,
                Subtitle = "",
                Body     = Notifications.Body.NewPicture,
                Badge    = 0,
            };

            var newPictureTime = timeSetting.ToLocalTime();
            var time           = new NSDateComponents
            {
                Year   = newPictureTime.Year,
                Month  = newPictureTime.Month,
                Day    = newPictureTime.Day,
                Hour   = newPictureTime.Hour,
                Minute = newPictureTime.Minute,
                Second = newPictureTime.Second
            };
            var trigger = UNCalendarNotificationTrigger.CreateTrigger(time, false);

            var req = UNNotificationRequest.FromIdentifier(id, content, trigger);

            UNUserNotificationCenter.Current.AddNotificationRequest(req, null);
        }
Esempio n. 18
0
        public override void ViewDidLoad()
        {
            this.AddOption("Russian", SelectRussian);
            this.AddOption("German", SelectGerman);
            this.AddOption("Hebrew", SelectHebrew);
            this.AddOption("Chinese", SelectChinese);
            this.AddOption("Islamic", SelectIslamic);

            this.SelectedOption = 2;

            base.ViewDidLoad();

            this.CalendarView = new TKCalendar(this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
            this.View.AddSubview(this.CalendarView);

            NSDate           date       = NSDate.Now;
            NSDateComponents components = new NSDateComponents();

            components.Year           = -1;
            this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, NSCalendarOptions.None);
            components.Year           = 1;
            this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, NSCalendarOptions.None);

            this.SelectHebrew(this, EventArgs.Empty);
        }
Esempio n. 19
0
 public static HomeKitCondition CreateExactTime(TimeConditionOrder order, NSDateComponents components)
 {
     return(new HomeKitCondition {
         ExactTimeData = new Tuple <TimeConditionOrder, NSDateComponents> (order, components),
         Type = HomeKitConditionType.ExactTime
     });
 }
Esempio n. 20
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.CalendarView = new TKCalendar(this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.CalendarView.Delegate         = new CalendarDelegate(this);
            this.CalendarView.SelectionMode    = TKCalendarSelectionMode.Range;
            this.View.AddSubview(this.CalendarView);

            NSDateComponents components = new NSDateComponents();

            components.Day = 1;

            NSDate date = NSDate.Now;

            this.UnselectableDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            components.Day = 3;
            NSDate startDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            components.Day = 6;
            NSDate endDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            components.Year           = -5;
            this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            components.Year           = 5;
            this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            this.CalendarView.SelectedDatesRange = new TKDateRange(startDate, endDate);
        }
Esempio n. 21
0
        private void SetMonthSettings()
        {
            monthSettings = new MonthViewSettings();

            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            schedule.MonthViewSettings  = monthSettings;
            monthSettings.BlackoutDates = new NSMutableArray();
            if (switchBlackOutDates != null && switchBlackOutDates.On)
            {
                components.Day -= 3;
                for (int i = 0; i < 3; i++)
                {
                    NSDate startDate = calendar.DateFromComponents(components);
                    components.Day += 1;
                    schedule.MonthViewSettings.BlackoutDates.Add(startDate);
                }
            }

            if (switchWeekNumber != null && switchWeekNumber.On)
            {
                schedule.MonthViewSettings.ShowWeekNumber = true;
            }
            else
            {
                schedule.MonthViewSettings.ShowWeekNumber = false;
            }
        }
Esempio n. 22
0
        static void Main(string[] args)
        {
            NSApplication.Init();

            NSDate now = NSDate.Now;
            DateTime cNow = DateTime.UtcNow;
            NSCalendar cal = NSCalendar.CurrentCalendar;
            NSDateComponents weekComponents = new NSDateComponents();

            List<LotteryEntry> entries = new List<LotteryEntry>();
            for (int i = 0; i < 10; i++) {

                weekComponents.Week = i;
                NSDate iWeeksFromNow = cal.DateByAddingComponents(weekComponents, now, NSCalendarOptions.None);

                DateTime cWeeksFromNow = cNow.AddDays(i*7);

                LotteryEntry newEntry = new LotteryEntry(iWeeksFromNow, cWeeksFromNow);
                entries.Add(newEntry);
            }

            foreach (LotteryEntry entry in entries) {
                Debug.WriteLine("{0}", entry);
            }

            NSApplication.Main(args);
        }
Esempio n. 23
0
		List<WeatherModel> addPopulationData()
		{
			List<WeatherModel> array = new List<WeatherModel>();

			NSDate now = NSDate.Now;


			string[] imagesArray = new string[] { "Cloudy.png", "Humid.png", "Rainy.png", "Warm.png", "Windy.png", "Cloudy.png", "Humid.png" };
			for (int i = 0; i < 7; i++)
			{
				int daysToAdd = i;
				NSDateComponents components = new NSDateComponents();
				components.Day = daysToAdd;

				NSCalendar gregorian =  NSCalendar.CurrentCalendar;

				NSDate newDate2 = gregorian.DateByAddingComponents(components, now, NSCalendarOptions.None);
				NSDateFormatter dateFormatter = new NSDateFormatter();
				dateFormatter.DateFormat = "EEEE, MMMM dd";

				NSDateFormatter dateFormatter1 = new NSDateFormatter();
				dateFormatter1.DateFormat = "EEEE";
				array.Add(new WeatherModel((NSString)dateFormatter.StringFor(newDate2), (NSString)imagesArray[i], (NSString)new Random().Next(10, 40).ToString(), (NSString)dateFormatter1.StringFor(newDate2)));
			}

			return array;
		}
Esempio n. 24
0
		public override void ViewDidLoad ()
		{
			this.AddOption ("Year", SelectYear);
			this.AddOption ("Month", SelectMonth);
			this.AddOption ("Month Names", SelectMonthNames);
			this.AddOption ("Year Numbers", SelectYearNumbers);
			this.AddOption ("Flow", SelectFlow);
			this.AddOption ("Week view", SelectWeekView);

			base.ViewDidLoad ();

			NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
			calendar.FirstWeekDay = 2;
			NSDate date = NSDate.Now;
			NSDateComponents components = new NSDateComponents ();
			components.Year = -10;
			NSDate minDate = calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);
			components.Year = 10;
			NSDate maxDate = calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);

			this.CalendarView = new TKCalendar (this.View.Bounds);
			this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
			this.View.AddSubview (this.CalendarView);

			this.calendarDelegate = new CalendarDelegate(this);

			this.CalendarView.Delegate = calendarDelegate;
			this.CalendarView.ViewMode = TKCalendarViewMode.Year;
			this.CalendarView.Calendar = calendar;
			this.CalendarView.MinDate = minDate;
			this.CalendarView.MaxDate = maxDate;
			this.CalendarView.NavigateToDate (date, false);
		}
Esempio n. 25
0
        static void Main(string[] args)
        {
            NSApplication.Init();

            NSDate           now            = NSDate.Now;
            DateTime         cNow           = DateTime.UtcNow;
            NSCalendar       cal            = NSCalendar.CurrentCalendar;
            NSDateComponents weekComponents = new NSDateComponents();

            List <LotteryEntry> entries = new List <LotteryEntry>();

            for (int i = 0; i < 10; i++)
            {
                weekComponents.Week = i;
                NSDate iWeeksFromNow = cal.DateByAddingComponents(weekComponents, now, NSCalendarOptions.None);

                DateTime cWeeksFromNow = cNow.AddDays(i * 7);

                LotteryEntry newEntry = new LotteryEntry(iWeeksFromNow, cWeeksFromNow);
                entries.Add(newEntry);
            }

            foreach (LotteryEntry entry in entries)
            {
                Debug.WriteLine("{0}", entry);
            }

            NSApplication.Main(args);
        }
        public CalendarBlackoutDates()
        {
            //Calendar
            calendar1              = new SFCalendar();
            calendar1.ViewMode     = SFCalendarViewMode.SFCalendarViewModeMonth;
            calendar1.HeaderHeight = 40;
            this.AddSubview(calendar1);

            //Setting BlackOutDates
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;
            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second

            calendar1.BlackoutDates = new NSMutableArray();

            for (int i = 0; i < 5; i++)
            {
                NSDate startDate = calendar.DateFromComponents(components);
                components.Day += 1;
                calendar1.BlackoutDates.Add(startDate);
            }

            appView = new UITableView();
            appView.RegisterClassForCellReuse(typeof(UITableViewCell), "Cell");
            if ((UIDevice.CurrentDevice).UserInterfaceIdiom == UIUserInterfaceIdiom.Pad)
            {
                calendarView.AddSubview(calendar1);
                this.AddSubview(calendarView);
            }
            this.AddSubview(appView);
        }
Esempio n. 27
0
        public void SetSpecificReminder(string title, string message, DateTime dateTime)
        {
            // TODO add this check further up the line, so that the user can't create reminders unless approved
            if (CheckApproval() == true)
            {
                var content = new UNMutableNotificationContent();
                content.Title = title;
                content.Body  = message;
                content.Badge = 1;

                var dateComp = new NSDateComponents();
                dateComp.Year   = dateTime.Year;
                dateComp.Day    = dateTime.Day;
                dateComp.Hour   = dateTime.Hour;
                dateComp.Minute = dateTime.Minute;
                dateComp.Second = dateTime.Second;

                var trigger   = UNCalendarNotificationTrigger.CreateTrigger(dateComp, false);
                var requestID = "testRequest";
                var request   = UNNotificationRequest.FromIdentifier(requestID, content, trigger);

                UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) => {
                    if (err != null)
                    {
                        // Do something with error...
                    }
                });
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);

            calendar.FirstWeekDay = 2;
            NSDate           date       = NSDate.Now;
            NSDateComponents components = new NSDateComponents();

            components.Year = -10;
            NSDate minDate = calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            components.Year = 10;
            NSDate maxDate = calendar.DateByAddingComponents(components, date, (NSCalendarOptions)0);

            this.CalendarView = new TKCalendar(this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.View.AddSubview(this.CalendarView);

            this.CalendarView.Delegate = new CalendarDelegate(this);
            this.CalendarView.ViewMode = TKCalendarViewMode.Year;
            this.CalendarView.Calendar = calendar;
            this.CalendarView.MinDate  = minDate;
            this.CalendarView.MaxDate  = maxDate;
            this.CalendarView.NavigateToDate(date, false);
        }
Esempio n. 29
0
        public void ScheduleDailyNotification(DateTime notificationTime)
        {
            var content = new UNMutableNotificationContent()
            {
                Title    = "Daily Reflection",
                Subtitle = "",
                Body     = "Time for the daily reflection!",
                Badge    = 1
            };

            var time = notificationTime.TimeOfDay;

            var dateComponents = new NSDateComponents
            {
                Hour   = time.Hours,
                Minute = time.Minutes
            };

            var trigger = UNCalendarNotificationTrigger.CreateTrigger(dateComponents, repeats: true);

            var request = UNNotificationRequest.FromIdentifier(MessageId.ToString(), content, trigger);

            CancelNotifications();

            UNUserNotificationCenter.Current.AddNotificationRequest(request, (err) =>
            {
                if (err != null)
                {
                    throw new Exception($"Failed to schedule notification: {err}");
                }
            });
        }
Esempio n. 30
0
        private void CalendarDrawMonthCell(object sender, DrawMonthCellEventArgs e)
        {
            NSCalendar date  = NSCalendar.CurrentCalendar;
            NSDate     today = new NSDate();

            NSDateComponents monthCellDateComponents = date.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, e.MonthCell.Date);
            NSDateComponents todayDateComponents = date.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            UIButton button = new UIButton();

            button.SetTitle(monthCellDateComponents.Day.ToString(), UIControlState.Normal);
            button.SetTitleColor(UIColor.Black, UIControlState.Normal);

            if (e.MonthCell.IsCurrentMonth)
            {
                if (monthCellDateComponents.Day == todayDateComponents.Day && monthCellDateComponents.Month == todayDateComponents.Month && monthCellDateComponents.Year == todayDateComponents.Year)
                {
                    //// customized paricular date by setting differernt background color
                    button.BackgroundColor = UIColor.Red;
                }
                else
                {
                    button.BackgroundColor = UIColor.LightGray;
                }

                e.MonthCell.View = button;
            }
        }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();

            this.CalendarView = new TKCalendar(new RectangleF());
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.CalendarView.Delegate         = calendarDelegate;
            this.View.AddSubview(this.CalendarView);

            NSDate           date       = NSDate.Now;
            NSDateComponents components = new NSDateComponents();

            components.Year           = -1;
            this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, NSCalendarOptions.None);
            components.Year           = 1;
            this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents(components, date, NSCalendarOptions.None);

            UIImage img = UIImage.FromBundle("calendar_header.png");

            TKCalendarMonthPresenter presenter = (TKCalendarMonthPresenter)this.CalendarView.Presenter;

            presenter.Style.TitleCellHeight      = 20;
            presenter.HeaderView.ContentMode     = UIViewContentMode.ScaleToFill;
            presenter.HeaderView.BackgroundColor = UIColor.FromPatternImage(img);
        }
 async void ScheduleReminderNotification(TriggeredReminder reminder, int badge)
 {
     UNMutableNotificationContent content = new UNMutableNotificationContent()
     {
         Title = reminder.Appointment.Subject,
         Body  = CreateMessageContent(reminder),
         Sound = UNNotificationSound.Default,
         Badge = badge,
     };
     NSDateComponents dateComponents = new NSDateComponents()
     {
         Second   = reminder.AlertTime.Second,
         Minute   = reminder.AlertTime.Minute,
         Hour     = reminder.AlertTime.Hour,
         Day      = reminder.AlertTime.Day,
         Month    = reminder.AlertTime.Month,
         Year     = reminder.AlertTime.Year,
         TimeZone = NSTimeZone.SystemTimeZone,
     };
     UNCalendarNotificationTrigger trigger =
         UNCalendarNotificationTrigger.CreateTrigger(dateComponents, false);
     string identifier             = NotificationCenter.SerializeReminder(reminder);
     UNNotificationRequest request =
         UNNotificationRequest.FromIdentifier(identifier, content, trigger);
     await notificationCenter.AddNotificationRequestAsync(request);
 }
        /// <summary>
        ///     Show a local notification
        /// </summary>
        /// <param name="title">Title of the notification</param>
        /// <param name="body">Body or description of the notification</param>
        /// <param name="id">Id of the notification</param>
        /// <param name="notificationDateTime">Time to show notification</param>
        public void Notify(string title, string body, DateTime notificationDateTime, int id = 0)
        {
            if (!_hasNotificationPermissions)
            {
                return;
            }
            UNMutableNotificationContent content = new UNMutableNotificationContent
            {
                Title = title,
                Body  = body,
                Sound = UNNotificationSound.Default
            };
            NSDateComponents dateComponent = new NSDateComponents
            {
                Month  = notificationDateTime.Month,
                Day    = notificationDateTime.Day,
                Year   = notificationDateTime.Year,
                Hour   = notificationDateTime.Hour,
                Minute = notificationDateTime.Minute,
                Second = notificationDateTime.Second
            };
            UNCalendarNotificationTrigger trigger = UNCalendarNotificationTrigger.CreateTrigger(dateComponent, false);

            BaseNotify(id, content, trigger);
        }
Esempio n. 34
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            this.CalendarView = new TKCalendar (this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.CalendarView.Delegate = new CalendarDelegate (this);
            this.CalendarView.SelectionMode = TKCalendarSelectionMode.Range;
            this.View.AddSubview (this.CalendarView);

            NSDateComponents components = new NSDateComponents ();
            components.Day = 1;

            NSDate date = NSDate.Now;
            this.UnselectableDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);

            components.Day = 3;
            NSDate startDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);

            components.Day = 6;
            NSDate endDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);

            components.Year = -5;
            this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);

            components.Year = 5;
            this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, (NSCalendarOptions)0);

            this.CalendarView.SelectedDatesRange = new TKDateRange (startDate, endDate);
        }
Esempio n. 35
0
        private ObservableCollection <ScheduleAppointment> CreateAppointments()
        {
            NSDate     today    = new NSDate();
            NSCalendar calendar = NSCalendar.CurrentCalendar;

            // Get the year, month, day from the date
            NSDateComponents components = calendar.Components(
                NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components.Hour   = 10;
            components.Minute = 0;
            components.Second = 0;
            NSDate startDate = calendar.DateFromComponents(components);

            // Get the year, month, day from the date
            NSDateComponents endDateComponents = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents.Hour   = 12;
            endDateComponents.Minute = 0;
            endDateComponents.Second = 0;
            NSDate endDate = calendar.DateFromComponents(endDateComponents);
            ScheduleAppointment appointment = new ScheduleAppointment();

            appointment.StartTime             = startDate;
            appointment.EndTime               = endDate;
            appointment.Subject               = new NSString("Jeni's B'Day Celebration");
            appointment.AppointmentBackground = UIColor.FromRGB(0xA2, 0xC1, 0x39);
            NSDateComponents components1 = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            components1.Hour   = 11;
            components1.Minute = 0;
            components1.Second = 0;
            components1.Day    = components1.Day + 1;
            NSDate startDate1 = calendar.DateFromComponents(components1);

            // Get the year, month, day from the date
            NSDateComponents endDateComponents1 = calendar.Components(NSCalendarUnit.Year | NSCalendarUnit.Month | NSCalendarUnit.Day, today);

            // Set the hour, minute, second
            endDateComponents1.Hour   = 13;
            endDateComponents1.Minute = 30;
            endDateComponents1.Second = 0;
            endDateComponents1.Day    = endDateComponents1.Day + 1;
            NSDate endDate1 = calendar.DateFromComponents(endDateComponents1);
            ScheduleAppointment appointment1 = new ScheduleAppointment();

            appointment1.StartTime             = startDate1;
            appointment1.EndTime               = endDate1;
            appointment1.Subject               = new NSString("Checkup");
            appointment1.AppointmentBackground = UIColor.FromRGB(0xD8, 0x00, 0x73);
            ObservableCollection <ScheduleAppointment> appCollection = new ObservableCollection <ScheduleAppointment>();

            appCollection.Add(appointment);
            appCollection.Add(appointment1);
            return(appCollection);
        }
Esempio n. 36
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad();
// >> getting-started-calendar-cs
            TKCalendar calendarView = new TKCalendar(this.View.Bounds);

            calendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.View.AddSubview(calendarView);
// << getting-started-calendar-cs

            calendarDelegate = new CalendarDelegate();

// >> getting-started-assigndatasource-cs
            calendarView.DataSource = new CalendarDataSource(this);
// << getting-started-assigndatasource-cs

// >> getting-started-event-cs
            events = new List <TKCalendarEvent> ();
            NSCalendar calendar = new NSCalendar(NSCalendarType.Gregorian);
            NSDate     date     = NSDate.Now;

            Random r = new Random();

            for (int i = 0; i < 3; i++)
            {
                TKCalendarEvent ev = new TKCalendarEvent();
                ev.Title = "Sample event";
                NSDateComponents components = calendar.Components(NSCalendarUnit.Day | NSCalendarUnit.Month | NSCalendarUnit.Year, date);
                components.Day = r.Next() % 20;
                ev.StartDate   = calendar.DateFromComponents(components);
                ev.EndDate     = calendar.DateFromComponents(components);
                ev.EventColor  = UIColor.Red;
                events.Add(ev);
            }
// << getting-started-event-cs

// >> getting-started-minmaxdate-cs
            calendarView.MinDate = TKCalendar.DateWithYear(2010, 1, 1, calendar);
            calendarView.MaxDate = TKCalendar.DateWithYear(2016, 12, 31, calendar);
// << getting-started-minmaxdate-cs

//			calendarDelegate.events = this.events;
            calendarView.Delegate = calendarDelegate;

// >> getting-started-navigatetodate-cs
            NSDateComponents newComponents = new NSDateComponents();

            newComponents.Year  = 2015;
            newComponents.Month = 5;
            newComponents.Day   = 1;
            NSDate newDate = calendarView.Calendar.DateFromComponents(newComponents);

// >> navigation-navigate-cs
            calendarView.NavigateToDate(newDate, true);
// << navigation-navigate-cs
// << getting-started-navigatetodate-cs

            calendarView.ReloadData();
        }
Esempio n. 37
0
 public NSDate DateWithYear(int year, int month, int day)
 {
     NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
     NSDateComponents components = new NSDateComponents ();
     components.Year = year;
     components.Month = month;
     components.Day = day;
     return calendar.DateFromComponents (components);
 }
Esempio n. 38
0
		void AddDataPointsForChart (DateTime XValue, Double YValue)
		{
			NSCalendar cal 			= new NSCalendar (NSCalendarType.Gregorian);
			NSDateComponents comp 	= new NSDateComponents ();
			comp.Day 				= XValue.Day;
			comp.Month 				= XValue.Month;
			comp.Year 				= XValue.Year;
			comp.Hour 				= XValue.Hour;
			comp.Minute 			= XValue.Minute;
			comp.Second 			= XValue.Second;
			DataPoints.Add (new SFChartDataPoint ( cal.DateFromComponents(comp), NSObject.FromObject(YValue)));
		}
Esempio n. 39
0
 void AddItem(NSMutableArray array, string name, float value, string group, int day, UIImage image)
 {
     NSCalendar calendar = NSCalendar.CurrentCalendar;
     NSDateComponents components = new NSDateComponents ();
     components.Day = day;
     NSDate date = calendar.DateByAddingComponents (components, NSDate.Now, NSCalendarOptions.None);
     DSItem item = new DSItem () {
         Name = name,
         Value = value,
         Group = group,
         Date = date,
         Image = image
     };
     array.Add (item);
 }
Esempio n. 40
0
		public static NSDate DateTimeToNSDate(this DateTime dt) {
			if (dt == DateTime.MinValue) return null; // ?

			DateTime ldt = dt.ToLocalTime();
			NSDateComponents components = new NSDateComponents();
			components.Year = ldt.Year;
			components.Month = ldt.Month;
			components.Day = ldt.Day;
			components.Hour = ldt.Hour;
			components.Minute = ldt.Minute;
			components.Second = ldt.Second;
			components.Nanosecond = (ldt.Millisecond * 1000000);

			return NSCalendar.CurrentCalendar.DateFromComponents(components);
		}
Esempio n. 41
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			this.tableViewDataSource = new TableViewDataSource (this);

			this.TableView = new UITableView (new RectangleF ());
			this.TableView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin;
			this.TableView.RegisterClassForCellReuse (typeof(UITableViewCell), new NSString("cell"));
			this.TableView.DataSource = this.tableViewDataSource;
			this.View.AddSubview (this.TableView);

			NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
			calendar.FirstWeekDay = 2;

			NSDateComponents components = new NSDateComponents ();
			components.Year = -10;
			NSDate minDate = calendar.DateByAddingComponents (components, NSDate.Now, (NSCalendarOptions)0);
			components.Year = 10;
			NSDate maxDate = calendar.DateByAddingComponents (components, NSDate.Now, (NSCalendarOptions)0);

			this.calendarDelegate = new CalendarDelegate (this);
			this.calendarDataSource = new CalendarDataSource (this);

			this.CalendarView = new TKCalendar (new RectangleF());
			this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
			this.CalendarView.Calendar = calendar;
			this.CalendarView.Delegate = calendarDelegate;
			this.CalendarView.DataSource = calendarDataSource;
			this.CalendarView.MinDate = minDate;
			this.CalendarView.MaxDate = maxDate;
			this.CalendarView.AllowPinchZoom = true;

			TKCalendarMonthPresenter presenter = (TKCalendarMonthPresenter)this.CalendarView.Presenter;
			presenter.Style.TitleCellHeight = 40;
			presenter.HeaderIsSticky = true;

			if (UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Pad) {
				presenter.WeekNumbersHidden = true;
				this.CalendarView.Theme = new TKCalendarIPadTheme ();
				presenter.Update (true);
			} else {
				presenter.WeekNumbersHidden = false;
			}

			this.View.AddSubview (this.CalendarView);
		}
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            this.DataSource = new TKCalendarEventKitDataSource ();
            this.CalendarView = new TKCalendar (this.View.Bounds);
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.CalendarView.DataSource = this.DataSource;
            this.View.AddSubview (this.CalendarView);

            NSDate date = NSDate.Now;
            NSDateComponents components = new NSDateComponents ();
            components.Year = -1;
            this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);
            components.Year = 1;
            this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);
        }
        public LabelDetailController()
        {
            coloredLabel.SetTextColor (UIColor.Purple);

            var attrString = new NSAttributedString ("Ultralight Label", new UIStringAttributes {
                Font = UIFont.SystemFontOfSize (16f, UIFontWeight.UltraLight)
            });
            ultralightLabel.SetText (attrString);

            var components = new NSDateComponents {
                Day = 10,
                Month = 12,
                Year = 2015
            };
            timer.SetDate (NSCalendar.CurrentCalendar.DateFromComponents (components));
            timer.Start ();
        }
Esempio n. 44
0
        public static NSDate ToNSDate(this DateTime dt)
        {
            if (dt == DateTime.MinValue)
                return null;

            var ldt = dt.ToLocalTime();
            var components = new NSDateComponents
            {
                Year = ldt.Year,
                Month = ldt.Month,
                Day = ldt.Day,
                Hour = ldt.Hour,
                Minute = ldt.Minute,
                Second = ldt.Second,
                Nanosecond = (ldt.Millisecond * 1000000)
            };
            return NSCalendar.CurrentCalendar.DateFromComponents(components);
        }
Esempio n. 45
0
		public override void ViewDidLoad ()
		{
			this.AddOption ("Flip Effect", SelectFlipEffect);
			this.AddOption ("Float Effect", SelectedFloatEffect);
			this.AddOption ("Fold Effect", SelectedFoldEffect);
			this.AddOption ("Rotate Effect", SelectedRotateEffect);
			this.AddOption ("Card Effect", SelectedCardEffect);
			this.AddOption ("Scroll Effect", SelectedScrollEffect);

			base.ViewDidLoad ();

			this.calendarDelegate  = new CalendarDelegate (this); 
			this.presenterDelegate = new CalendarPresenterDelegate (this);

			UIToolbar toolbar = new UIToolbar (new CGRect (0, this.View.Frame.Size.Height - 44, this.View.Bounds.Size.Width, 44));
			toolbar.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleTopMargin;
			this.View.AddSubview (toolbar);

			UIBarButtonItem buttonPrev = new UIBarButtonItem("Prev month", UIBarButtonItemStyle.Plain, this, new Selector("PrevTouched"));
			UIBarButtonItem buttonNext = new UIBarButtonItem("Next month", UIBarButtonItemStyle.Plain, this, new Selector("NextTouched"));
			UIBarButtonItem space = new UIBarButtonItem (UIBarButtonSystemItem.FlexibleSpace, this, null);
			toolbar.Items = new UIBarButtonItem[] { buttonPrev, space, buttonNext };

			CGRect rect = new CGRect (0, 0, this.View.Bounds.Size.Width, this.View.Bounds.Size.Height - toolbar.Frame.Size.Height);
			this.CalendarView = new TKCalendar (rect);
			this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleHeight | UIViewAutoresizing.FlexibleWidth;
			this.CalendarView.Delegate = calendarDelegate;
			this.CalendarView.AllowPinchZoom = false;
			this.View.AddSubview (CalendarView);

			NSDate date = NSDate.Now;
			NSDateComponents components = new NSDateComponents ();
			components.Year = -1;
			this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);
			components.Year = 1;
			this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);

			TKCalendarMonthPresenter presenter = (TKCalendarMonthPresenter)this.CalendarView.Presenter;
			presenter.TransitionMode = TKCalendarTransitionMode.Flip;
			presenter.Delegate = new CalendarPresenterDelegate (this);
			presenter.ContentView.BackgroundColor = this.Colors [ColorIndex];
			this.TransitionMode = TKCalendarTransitionMode.Flip;
		}
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();
			calendar.MaxSelectionCount = 100;
			calendar.SelectionChanging += (object sender, Xuni.iOS.Calendar.SelectionChangingEventArgs e) => {
				NSDateComponents components = new NSDateComponents();
				components.Day = 1;

				for(NSDate date = e.SelectedDates.StartDate;
					date.Compare(e.SelectedDates.EndDate) == NSComparisonResult.Ascending || 
					date.Compare(e.SelectedDates.EndDate) == NSComparisonResult.Same;
					date = NSCalendar.CurrentCalendar.DateByAddingComponents(components, date, NSCalendarOptions.None))
				{
					nint weekday = NSCalendar.CurrentCalendar.Components(NSCalendarUnit.Weekday, date).Weekday;

					if (weekday == 1 || weekday == 7) {
						e.SelectedDates.AddExcludedDates(date);
					}
				}
			};
		}
        void TurnOnNotifications()
        {
            // create notification for every day at specified time
            var notification = new UILocalNotification ();

            notification.RepeatInterval = NSCalendarUnit.Day;

            //set time
            var time = new NSDateComponents ();
            time.Hour = (nint)slider.Value;
            time.Minute = 00;
            time.Second = 0;

            //choose calendar
            var calendar = new NSCalendar (NSCalendarType.Gregorian);

            //create fire date
            var date = calendar.DateFromComponents (time);

            // set the fire date (the date time in which it will fire)
            notification.FireDate = date;
            notification.TimeZone = NSTimeZone.DefaultTimeZone;

            // configure the alert stuff
            notification.AlertTitle = "The APOD is ready!";
            //			notification.AlertAction = "Open the app";
            notification.AlertBody = "Open the app and check it out!";

            notification.UserInfo = NSDictionary.FromObjectAndKey (new NSString ("UserInfo for notification"), new NSString ("Notification"));

            // modify the badge - has no effect on the Watch
            notification.ApplicationIconBadgeNumber = 1;

            // set the sound to be the default sound
            notification.SoundName = UILocalNotification.DefaultSoundName;

            // schedule it
            UIApplication.SharedApplication.ScheduleLocalNotification (notification);
        }
Esempio n. 48
0
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            this.CalendarView = new TKCalendar (new RectangleF ());
            this.CalendarView.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
            this.CalendarView.Delegate = calendarDelegate;
            this.View.AddSubview (this.CalendarView);

            NSDate date = NSDate.Now;
            NSDateComponents components = new NSDateComponents ();
            components.Year = -1;
            this.CalendarView.MinDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);
            components.Year = 1;
            this.CalendarView.MaxDate = this.CalendarView.Calendar.DateByAddingComponents (components, date, NSCalendarOptions.None);

            UIImage img = new UIImage ("calendar_header.png");

            TKCalendarMonthPresenter presenter = (TKCalendarMonthPresenter)this.CalendarView.Presenter;
            presenter.Style.TitleCellHeight = 20;
            presenter.HeaderView.ContentMode = UIViewContentMode.ScaleToFill;
            presenter.HeaderView.BackgroundColor = UIColor.FromPatternImage (img);
        }
Esempio n. 49
0
		public override void ViewDidLoad ()
		{
			base.ViewDidLoad ();

			TKChart chart = new TKChart (this.View.Bounds);
			chart.AutoresizingMask = UIViewAutoresizing.FlexibleWidth | UIViewAutoresizing.FlexibleHeight;
			this.View.AddSubview (chart);

			NSCalendar calendar = new NSCalendar (NSCalendarType.Gregorian);
			NSDateComponents dateTimeComponents = new NSDateComponents ();
			dateTimeComponents.Year = 2013;
			dateTimeComponents.Day = 1;

			Random r = new Random ();
			List<TKChartDataPoint> list = new List<TKChartDataPoint> ();
			for (int i = 1; i <= 6; i++) {
				dateTimeComponents.Month = i;
				list.Add(new TKChartDataPoint(calendar.DateFromComponents(dateTimeComponents), new NSNumber(r.Next() % 100)));
			}

			TKChartSplineAreaSeries series = new TKChartSplineAreaSeries (list.ToArray());
			series.SelectionMode = TKChartSeriesSelectionMode.Series;

			dateTimeComponents.Month = 1;
			NSDate minDate = new NSDate ();
			NSDate maxDate = new NSDate ();
			minDate = calendar.DateFromComponents (dateTimeComponents);
			dateTimeComponents.Month = 6;
			maxDate = calendar.DateFromComponents (dateTimeComponents);

			TKChartDateTimeAxis xAxis = new TKChartDateTimeAxis (minDate, maxDate);
			xAxis.MajorTickIntervalUnit = TKChartDateTimeAxisIntervalUnit.Months;
			xAxis.MajorTickInterval = 1;
			chart.XAxis = xAxis;

			chart.AddSeries (series);
		}
Esempio n. 50
0
		public void QueryForRecentActivityData (Action completionHandler)
		{
			var now = NSDate.Now;
			var dateComponents = new NSDateComponents ();
			dateComponents.SetValueForComponent (-7, NSCalendarUnit.Day);
			var startDay = NSCalendar.CurrentCalendar.DateByAddingComponents (dateComponents, now, NSCalendarOptions.None);

			activityManager.QueryActivity (startDay, now, MotionQueue, (activities, error) => {
				if (activities != null)
					CreateActivityDataWithActivities (activities, completionHandler);
				else if (error != null)
					HandleError (error);
			});
		}
Esempio n. 51
0
 public static NSPredicate CreatePredicateForEvaluatingTriggerOccurringBeforeSignificantEvent(HMSignificantEvent significantEvent, NSDateComponents offset)
 {
     return CreatePredicateForEvaluatingTriggerOccurringBeforeSignificantEvent (GetEnumConstant (significantEvent), offset);
 }
        public override void ViewDidLoad()
        {
            base.ViewDidLoad ();

            webView.ShouldStartLoad = delegate (UIWebView webViewParam, NSUrlRequest request, UIWebViewNavigationType navigationType)
            {	// Catch the link click, and process the add/remove favorites
                if (navigationType == UIWebViewNavigationType.LinkClicked)
                {
                    string path = request.Url.Path.Substring(1);
                    string host = request.Url.Host.ToLower ();
                    if (host == "tweet.mix10.app") {
                        var tweet = new TWTweetComposeViewController();
                        tweet.SetInitialText ("I'm in '" + DisplaySession.Title + "' at #monkeyspace" );
                        PresentModalViewController(tweet, true);
                    } else if (host == "social.mix10.app") {
                        var message = "I'm in '" + DisplaySession.Title + "' at #monkeyspace";
                        var social = new UIActivityViewController(new NSObject[] { new NSString(message) },
                                                                  new UIActivity[] { new UIActivity() });
                        PresentViewController(social, true, null);
                    } else if (host == "add.mix10.app") {
                        AppDelegate.UserData.AddFavoriteSession(path);
                        App.Current.EventStore.RequestAccess (EKEntityType.Reminder, (bool granted, NSError e) => {
                            if (granted) {

                                EKReminder reminder = EKReminder.Create (App.Current.EventStore);
                                reminder.Title = DisplaySession.Title;
                                reminder.Calendar = App.Current.EventStore.DefaultCalendarForNewReminders;
                                reminder.Notes = DisplaySession.Abstract;

                                var date = new NSDateComponents();
                                date.Day = DisplaySession.Start.Day;
                                date.Month = DisplaySession.Start.Month;
                                date.Year = DisplaySession.Start.Year;
                                date.Hour = DisplaySession.Start.Hour;
                                date.Minute = DisplaySession.Start.Minute;
                                date.Second = DisplaySession.Start.Second;

                                reminder.StartDateComponents = date;
                                reminder.DueDateComponents = date;

                                App.Current.EventStore.SaveReminder (reminder, true, out e);
                            } else
                                new UIAlertView ( "Access Denied", "User Denied Access to Calendar Data", null, "OK", null).Show ();
                        });
                        Update(DisplaySession);
                    }
                    else if (host == "remove.mix10.app")
                    {	// "remove.MIX10.app"
                        AppDelegate.UserData.RemoveFavoriteSession(path);
                        if (IsFromFavoritesView)
                        {	// once unfavorited, hide and go back to list view
                            NavigationController.PopViewControllerAnimated(true);
                        }
                        else
                        {
                            Update(DisplaySession);
                        }
                    }
                    else
                    {
                        NavigationController.PushViewController (new WebViewController (request), true);
                        return false;
                    }
                }
                return true;
            };
        }
Esempio n. 53
0
 public NSDate DateWithOffset(int days, int hours)
 {
     NSCalendar calendar = NSCalendar.CurrentCalendar;
     NSDateComponents components = new NSDateComponents ();
     components.Day = days;
     components.Hour = hours;
     return calendar.DateByAddingComponents (components, NSDate.Now, (NSCalendarOptions)0);
 }
Esempio n. 54
0
 // Sets the cell's text to represent an exact time condition.
 public void SetOrder(TimeConditionOrder order, NSDateComponents dateComponents)
 {
     var date = NSCalendar.CurrentCalendar.DateFromComponents (dateComponents);
     var timeString = DateFormatter.StringFor (date);
     SetOrder (order, timeString, "Relative to Time");
 }
		// Maps the possible calendar units associated with recurrence titles, so we can properly
		// set our recurrenceUnit when an index is selected.
		static int RecurrenceIndexFromDateComponents (NSDateComponents components)
		{
			if (components == null)
				return -1;

			var unit = (NSCalendarUnit)0;
			if (components.Day == 1)
				unit = NSCalendarUnit.Day;
			else if (components.WeekOfYear == 1)
				unit = NSCalendarUnit.WeekOfYear;
			else if (components.Hour == 1)
				unit = NSCalendarUnit.Hour;

			return (int)unit == 0 ? -1 : Math.Max (Array.IndexOf (Components, unit), -1);
		}
		void AddEarthquakesToList (List<Earthquake> earthquakes)
		{
			var entity = NSEntityDescription.EntityForName ("Earthquake", managedObjectContext);
			var fetchRequest = new NSFetchRequest ();
			fetchRequest.Entity = entity;

			var date = (NSPropertyDescription)entity.PropertiesByName.ValueForKey (new NSString ("date"));
			var location = (NSPropertyDescription)entity.PropertiesByName.ValueForKey (new NSString ("location"));

			fetchRequest.PropertiesToFetch = new NSPropertyDescription[] { date, location };
			fetchRequest.ResultType = NSFetchRequestResultType.DictionaryResultType;

			NSError error;

			foreach (var earthquake in earthquakes) {
				var arguments = new NSObject[] { earthquake.Location, earthquake.Date };
				fetchRequest.Predicate = NSPredicate.FromFormat ("location = %@ AND date = %@", arguments);
				var fetchedItems = NSArray.FromNSObjects (managedObjectContext.ExecuteFetchRequest (fetchRequest, out error));

				if (fetchedItems.Count == 0) {

					if (string.IsNullOrEmpty (entity.Description))
						continue;

					var managedEarthquake = new ManagedEarthquake (entity, managedObjectContext) {
						Magnitude = earthquake.Magnitude,
						Location = earthquake.Location,
						Date = earthquake.Date,
						USGSWebLink = earthquake.USGSWebLink,
						Latitude = earthquake.Latitude,
						Longitude = earthquake.Longitude
					};

					managedObjectContext.InsertObject (managedEarthquake);
				}

				var gregorian = new NSCalendar (NSCalendarType.Gregorian);
				var offsetComponents = new NSDateComponents ();
				offsetComponents.Day = -14;// 14 days back from today
				NSDate twoWeeksAgo = gregorian.DateByAddingComponents (offsetComponents, NSDate.Now, NSCalendarOptions.None);

				// use the same fetchrequest instance but switch back to NSManagedObjectResultType
				fetchRequest.ResultType = NSFetchRequestResultType.ManagedObject;
				fetchRequest.Predicate = NSPredicate.FromFormat ("date < %@", new NSObject[] { twoWeeksAgo });

				var olderEarthquakes = NSArray.FromObjects (managedObjectContext.ExecuteFetchRequest (fetchRequest, out error));

				for (nuint i = 0; i < olderEarthquakes.Count; i++)
					managedObjectContext.DeleteObject (olderEarthquakes.GetItem<ManagedEarthquake> (i));

				if (managedObjectContext.HasChanges) {
					if (!managedObjectContext.Save (out error))
						Console.WriteLine (string.Format ("Unresolved error {0}", error.LocalizedDescription));
				}
			}
		}