public void CreateCalendarEntry(LocalCalendarEvent localCalendarEvent)
        {
            eventStore.RequestAccess(EKEntityType.Event,
                                     (bool granted, NSError e) => {
                if (granted)
                {
                    UIApplication.SharedApplication.InvokeOnMainThread(() => {
                        EventKitUI.EKEventEditViewController eventController = new EventKitUI.EKEventEditViewController();

                        eventController.EventStore = eventStore;

                        // wire up a delegate to handle events from the controller
                        var eventControllerDelegate      = new CreateEventEditViewDelegate(eventController, eventStore);
                        eventController.EditViewDelegate = eventControllerDelegate;

                        EKEvent newEvent = EKEvent.FromStore(eventStore);

                        newEvent.StartDate = (NSDate)(DateTime.SpecifyKind(localCalendarEvent.StartDate, DateTimeKind.Local));
                        if (localCalendarEvent.EndDate.HasValue)
                        {
                            newEvent.EndDate = (NSDate)(DateTime.SpecifyKind(localCalendarEvent.EndDate.Value, DateTimeKind.Local));
                        }

                        newEvent.Title    = localCalendarEvent.Subject;
                        newEvent.Notes    = localCalendarEvent.Description;
                        newEvent.Location = localCalendarEvent.Location;

                        if (localCalendarEvent.ReminderDate.HasValue)
                        {
                            newEvent.AddAlarm(EKAlarm.FromDate((NSDate)(DateTime.SpecifyKind(localCalendarEvent.ReminderDate.Value, DateTimeKind.Local))));
                        }

                        eventController.Event = newEvent;

                        // show the event controller
                        UIApplication.SharedApplication.Windows[0].RootViewController.PresentViewController(eventController, true, null);
                    });
                }
                else
                {
                    new UIAlertView("Access Denied", "User Denied Access to Calendar Data", null, "ok", null).Show();
                }
            });
        }
예제 #2
0
        public void CreateCalendarEntry(LocalCalendarEvent localCalendarEvent)
        {
//			ContentValues eventValues = new ContentValues ();
//
//			//eventValues.Put (CalendarContract.Events.InterfaceConsts.CalendarId, _calId);
//			eventValues.Put (CalendarContract.Events.InterfaceConsts.Title, localCalendarEvent.Subject);
//			eventValues.Put (CalendarContract.Events.InterfaceConsts.Description, localCalendarEvent.Description);
//			eventValues.Put("beginTime", GetDateTimeMS(localCalendarEvent.StartDate));
//			if (localCalendarEvent.EndDate.HasValue)
//				eventValues.Put("endTime", GetDateTimeMS (localCalendarEvent.EndDate.Value));
//			eventValues.Put (CalendarContract.Events.InterfaceConsts.EventLocation, localCalendarEvent.Location);
//
//			//eventValues.Put(CalendarContract.Events.InterfaceConsts.EventTimezone, "UTC");
//			//eventValues.Put(CalendarContract.Events.InterfaceConsts.EventEndTimezone, "UTC");
//
//			var uri = ContentResolver.Insert (CalendarContract.Events.ContentUri, eventValues);

            Intent intent = new Intent(Intent.ActionInsert, ContentUris.WithAppendedId(Android.Provider.CalendarContract.Events.ContentUri, 765));

            intent.SetData(Android.Provider.CalendarContract.Events.ContentUri);

            // Add Event Details
            intent.PutExtra(Android.Provider.CalendarContract.ExtraEventBeginTime, GetDateTimeMS(localCalendarEvent.StartDate));

            if (localCalendarEvent.EndDate.HasValue)
            {
                intent.PutExtra(Android.Provider.CalendarContract.ExtraEventEndTime, GetDateTimeMS(localCalendarEvent.EndDate.Value));
            }

            intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.AllDay, false);
            intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.EventLocation, localCalendarEvent.Location);
            intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.Description, localCalendarEvent.Description);
            intent.PutExtra(Android.Provider.CalendarContract.EventsColumns.Title, localCalendarEvent.Subject);

            // Add Alarm reminder
            //intent.PutExtra (Android.Provider.CalendarContract.EventsColumns.Availability, (int) Android.Provider.EventsAvailability.Busy);
            //intent.PutExtra (Android.Provider.CalendarContract.RemindersColumns.EventId, 123);
            //intent.PutExtra (Android.Provider.CalendarContract.RemindersColumns.Minutes, AlertTimeSettingsToMinutes (settings.AlertTimeBefore));

            Forms.Context.StartActivity(intent);
        }
예제 #3
0
        private void UpdateEvents(LocalCalendar calendarToUpdate)
        {
            CalendarListEntry calendarSelected = new CalendarListEntry();

            if (calendarToUpdate != null && calendarToUpdate is CalendarListEntry)
            {

                currentEventList.Clear();  // remove any existing events
                EventsResource.ListRequest listRequest = service.Events.List(calendarToUpdate.Id);
                listRequest.TimeMin = new DateTime(StartDate.Year, StartDate.Month, StartDate.Day, StartDate.Hour, StartDate.Minute, StartDate.Second);
                DateTime StopDate = StartDate.AddMonths(4);
                listRequest.TimeMax = new DateTime(StopDate.Year, StopDate.Month, StopDate.Day, StopDate.Hour, StopDate.Minute, StopDate.Second);
                listRequest.SingleEvents = true;
                listRequest.MaxResults = 500;
                IList<Event> calEvents = listRequest.Execute().Items;
                foreach (Event calEvent in calEvents)
                {
                    LocalCalendarEvent newEvent = new LocalCalendarEvent();
                    newEvent.AddGoogleEvent(calEvent);
                    currentEventList.Add(newEvent);  // add to collection
                }
            }
        }