
Calendar methods are only supported by BrightForms version 8.1.0 and higher.
For the Android, version 4.0 or higher of the operating system is required.
// Fragment #1
local.vId = 0;
Calendar.QueryCalendars();
WHILE(Calendar.NextCalendar())
{
local.vId = local.vId + 1;
local.vCalendarId = Calendar.GetCalendarId();
local.vCalendarName = Calendar.GetCalendarName();
local.vDisplayName = Calendar.GetCalendarDisplayName();
Database.Reset();
Database.AddColumn("ID", local.vId);
Database.AddColumn("CALENDAR_ID", local.vCalendarId);
Database.AddColumn("CALENDAR_NAME", local.vCalendarName);
Database.AddColumn("DISPLAY_NAME", local.vDisplayName);
Database.AddRecord("CALENDARS");
}
// Fragment #2
Map.CreateMap("Calendars");
Calendar.QueryCalendars();
WHILE(Calendar.NextCalendar())
{
local.vCalId = Calendar.GetCalendarId();
local.vCalName = Calendar.GetCalendarName();
Map.Put("Calendars", local.vCalName, local.vCalId);
cmbCalendar.AddString(local.vCalName);
}
// Fragment #3
local.vCalId = Map.Get("Calendars", cmbCalendar);
Note:
Fragment #1 - Retrieves all the devices on a device, storing their ID, names and display names in a table CALENDARS. This is useful for displaying calendars for selection, for example, in a combobox.
Fragment #2, 3 - An alternative to storing the calendar information in a table - Fragment #2 uses a map to look up IDs which have been stored in a combo box, which is retrieved by the code in Fragment #3.
local.vId = 0;
Calendar.QueryEvents(local.vStartTime, local.vEndTime);
WHILE(Calendar.NextEvent())
{
local.vId = local.vId + 1;
local.vEventId = Calendar.GetEventId();
local.vEventTitle = Calendar.GetEventTitle();
local.vEventDesc = Calendar.GetEventDescription();
local.vStart = Calendar.GetEventStart();
local.vEnd = Calendar.GetEventEnd();
local.vIsAllDay = Calendar.IsEventAllDay();
local.vAvailable = Calendar.GetEventAvailability();
local.vEventCalendar = Calendar.GetCalendarId();
local.vAvailableStr = "UNKNOWN";
IF(local.vAvailable == AVAILABILITY_FREE)
{
local.vAvailableStr = "FREE";
}
IF(local.vAvailable == AVAILABILITY_TENTATIVE)
{
local.vAvailableStr = "TENTATIVE";
}
IF(local.vAvailable == AVAILABILITY_BUSY)
{
local.vAvailableStr = "BUSY";
}
local.vOrganiser = Calendar.GetEventOrganiser();
local.vLocation = Calendar.GetEventLocation();
Database.Reset();
Database.AddColumn("ID", local.vId);
Database.AddColumn("EVENT_ID", local.vEventId);
Database.AddColumn("EVENT_TITLE", local.vEventTitle);
Database.AddColumn("EVENT_DESC", local.vEventDesc);
Database.AddColumn("EVENT_START", local.vStart);
Database.AddColumn("EVENT_END", local.vEnd);
Database.AddColumn("IS_ALL_DAY", local.vIsAllDay);
Database.AddColumn("AVAILABLITY", local.vAvailable);
Database.AddColumn("AVAILABLITY_STR", local.vAvailableStr);
Database.AddColumn("ORGANISER", local.vOrganiser);
Database.AddColumn("LOCATION", local.vLocation);
Database.AddColumn("CALENDAR_ID", local.vEventCalendar);
Database.AddRecord("EVENTS");
}
Note:
The above code will retrieve all events in the range specified by local.vStartTime and local.vEndTime for all calendars, and write results in an EVENTS table.
To retrieve events in a specific calendar, the Calendar.QueryEventsInCalendar() method may be used with Calendar ID.
In addition to the availability code, an availability string is also calculated using system constants.
local.vStartTimeInMs = DateTime.GetMillisecondsAsString(local.vEventStart);
local.vEndTimeInMs = DateTime.GetMillisecondsAsString(local.vEventEnd);
System.ResetObjectState();
System.SetObjectStateAsLong("beginTime", local.vStartTimeInMs);
System.SetObjectStateAsLong("endTime", local.vEndTimeInMs);
local.vIntentUri = "content://com.android.calendar/events/" & local.vEventId;
System.RunProgram(local.vIntentUri, "android.intent.action.VIEW");
Note:
The above expression will use the RunProgram method to open the calendar app on an Android device, with event specified opened for editing.
local.vEventId, local.vEventStart and local.vEventEnd are values previously retrieved from the Calendar.Get... methods.
"content://com.android.calendar/events/" is the URI to launch the Google Calendar via Android Calendar Provider API.
DateTime values must be converted into milliseconds and set for the Google Calendar Provider Longs with the SetObjectStateAsLong() method.
"beginTime" and "endTime" are Calendar Provider Intent Extra constants. This is in order for Start and End time values to be interpreted correctly in the Calendar's dialog.
Calendar.ResetEventValues();
Calendar.SetEventValue(EVENT_TITLE, edtTitle);
Calendar.SetEventValue(EVENT_DESCRIPTION, edtDescription);
Calendar.SetEventValue(EVENT_ORGANIZER, edtOrganiser);
Calendar.SetEventValue(EVENT_LOCATION, edtLocation);
Calendar.SetEventValue(EVENT_START, dtStart);
Calendar.SetEventValue(EVENT_END, dtEnd);
Calendar.SetEventValue(EVENT_ALLDAY, chkAllDay);
local.vAvail = AVAILABILITY_BUSY;
IF(cmbAvail == "Free")
{
local.vAvail = AVAILABILITY_FREE;
}
IF(cmbAvail == "Tentative")
{
local.vAvail = AVAILABILITY_TENTATIVE;
}
IF(cmbAvail == "Unknown")
{
local.vAvail = AVAILABILITY_UNKNOWN;
}
Calendar.SetEventValue(EVENT_AVAILABILITY, local.vAvail);
local.vResult = Calendar.CreateEvent(local.vCalendarId);
IF(local.vResult <> NULL)
{
Form.MessageBox("Update", "Event created successfully.", 0);
}
ELSE
{
Form.MessageBox("Delete", "Could not create calendar event.", 0);
}
Note:
Clears event recording cache via ResetEventValues(), then uses the SetEventValue() methods with field constants to set the event details. The CreateEvent() method will then commit the values to a calendar event for the specified calendar.
Values are from edit controls, checkbox and combo box controls on the form.
local.vCalendarId is the ID of the calendar to write the event to. This is to be determined prior to the fragment call.
The result of the operation is checked at the end; and unsuccessful event write will return NULL, while a successful write will return the newly created Event ID. A messagebox will appear for either scenario.
Calendar.ResetEventValues();
Calendar.SetEventValue(EVENT_START, dtStart);
Calendar.SetEventValue(EVENT_END, dtEnd);
Calendar.SetEventValue(EVENT_ALLDAY, chkAllDay);
local.vResult = Calendar.UpdateEvent(local.vCalendarId, local.vEventId);
IF(local.vResult == 0)
{
Form.MessageBox("Update", "Event updated successfully.", 0);
}
ELSE
{
Form.MessageBox("Delete", "Could not update calendar event.", 0);
}
Note:
The above fragment will allocate the start time, end time and all day fields of an event to be updated via the SetEventValue() after clearing the cache with ResetEventValues(). It will then commit the changes via the UpdateEvent() method.
local.vCalendarId, local.vEventId are the calendar ID and event ID fields respectively. They are to be determined prior to the fragment call.
Result is checked, with 0 returned on success, or a different value on error. Both these instances will produce a messagebox indicating success/failure.
local.vResult = Calendar.DeleteEvent(local.vCalendarId, local.vEventId);
IF(local.vResult == 0)
{
Form.MessageBox("Delete", "Event deleted successfully.", 0);
}
ELSE
{
Form.MessageBox("Delete", "Could not delete calendar event.", 0);
}
Note:
Deletes the event for a calendar on the device, given a calendar ID and event ID.
local.vCalendarId, local.vEventId are the calendar ID and event ID fields respectively. They are to be determined prior to the fragment call.
Result is checked, with 0 returned on success, or a different value on error. Both these instances will produce a messagebox indicating success/failure.