The Android.Calendar module provides proxies and methods for accessing the native Android calendar functionality.
deprecated since 3.2.0
Use <Titanium.Calendar> instead.
This module supports retrieving information about existing events and creating new events.
However, modifying or deleting existing events is not yet supported.
Additionally, recurring events are not yet supported.
Currently, calendar permissions must be explicitly configured in tiapp.xml
in order to access the
calendar. See "Common Requirements" in
tiapp.xml and timodule.xml Reference.
Print the names of all calendars known to Android, and the names of calendars that have been selected in the native Android calendar application.
function showCalendars(calendars) {
for (var i = 0; i < calendars.length; i++) {
Ti.API.info(calendars[i].name);
}
}
Ti.API.info('ALL CALENDARS:');
showCalendars(Ti.Android.Calendar.allCalendars);
Ti.API.info('SELECTABLE CALENDARS:');
showCalendars(Ti.Android.Calendar.selectableCalendars);
Create a picker to allow an existing calendar to be selected and, when a button is clicked, generate details of all events in that calendar for the current year .
var calendars = [];
var selectedCalendarName;
var selectedCalendarId;
var pickerData = [];
var win = Ti.UI.createWindow({
backgroundColor: 'white',
exitOnClose: true,
fullscreen: false,
layout: 'vertical',
title: 'Calendar Demo'
});
var scrollView = Ti.UI.createScrollView({
backgroundColor: '#eee',
height: 500,
top: 20
});
var label = Ti.UI.createLabel({
backgroundColor: 'white',
text: 'Click on the button to display the events for the selected calendar',
textAlign: Ti.UI.TEXT_ALIGNMENT_CENTER,
top: 20
});
scrollView.add(label);
var selectableCalendars = Ti.Android.Calendar.selectableCalendars;
for (var i = 0, ilen = selectableCalendars.length; i < ilen; i++) {
calendars.push({ name: selectableCalendars[i].name, id: selectableCalendars[i].id });
pickerData.push( Ti.UI.createPickerRow({ title: calendars[i].name }) );
if(i === 0){
selectedCalendarName = selectableCalendars[i].name;
selectedCalendarId = selectableCalendars[i].id;
}
}
var selectableCalendars = null;
if(!calendars.length){
label.text = 'No calendars available. Select at least one in the native calendar before using this app';
} else {
label.text = 'Click button to view calendar events';
var picker = Ti.UI.createPicker({
top:20
});
picker.add(pickerData);
win.add(picker);
picker.addEventListener('change', function(e){
for (var i = 0, ilen = calendars.length; i < ilen; i++) {
if(calendars[i].name === e.row.title){
selectedCalendarName = calendars[i].name;
selectedCalendarId = calendars[i].id;
}
}
});
var button = Ti.UI.createButton({
title: 'View events',
top: 20
});
win.add(button);
button.addEventListener('click', function(e){
label.text = 'Generating...';
var currentYear = new Date().getFullYear();
var consoleString = '';
function print(s) {
if (consoleString.length) {
consoleString = consoleString + '\n';
}
consoleString = consoleString + s;
}
var calendar = Ti.Android.Calendar.getCalendarById(selectedCalendarId);
function printReminder(r) {
var typetext = '[method unknown]';
if (r.method == Ti.Android.Calendar.METHOD_EMAIL) {
typetext = 'Email';
} else if (r.method == Ti.Android.Calendar.METHOD_SMS) {
typetext = 'SMS';
} else if (r.method == Ti.Android.Calendar.METHOD_ALERT) {
typetext = 'Alert';
} else if (r.method == Ti.Android.Calendar.METHOD_DEFAULT) {
typetext = '[default reminder method]';
}
print(typetext + ' reminder to be sent ' + r.minutes + ' minutes before the event');
}
function printAlert(a) {
print('Alert id ' + a.id + ' begin ' + a.begin + '; end ' + a.end + '; alarmTime ' + a.alarmTime + '; minutes ' + a.minutes);
}
function printEvent(event) {
if (event.allDay) {
print('Event: ' + event.title + '; ' + event.begin.toLocaleDateString() + ' (all day)');
} else {
print('Event: ' + event.title + '; ' + event.begin.toLocaleDateString() + ' ' + event.begin.toLocaleTimeString()+ '-' + event.end.toLocaleTimeString());
}
var reminders = event.reminders;
if (reminders && reminders.length) {
print('There is/are ' + reminders.length + ' reminder(s)');
for (var i = 0; i < reminders.length; i++) {
printReminder(reminders[i]);
}
}
print('hasAlarm? ' + event.hasAlarm);
var alerts = event.alerts;
if (alerts && alerts.length) {
for (var i = 0; i < alerts.length; i++) {
printAlert(alerts[i]);
}
}
var status = event.status;
if (status == Ti.Android.Calendar.STATUS_TENTATIVE) {
print('This event is tentative');
}
if (status == Ti.Android.Calendar.STATUS_CONFIRMED) {
print('This event is confirmed');
}
if (status == Ti.Android.Calendar.STATUS_CANCELED) {
print('This event was canceled');
}
}
var events = calendar.getEventsInYear(currentYear);
if (events && events.length) {
print(events.length + ' event(s) in ' + currentYear);
print('');
for (var i = 0; i < events.length; i++) {
printEvent(events[i]);
print('');
}
} else {
print('No events');
}
label.text = consoleString;
});
}
win.add(scrollView);
win.open();
Creates an event and adds an e-mail reminder for 10 minutes before the event.
var CALENDAR_TO_USE = 3;
var calendar = Ti.Android.Calendar.getCalendarById(CALENDAR_TO_USE);
// Create the event
var eventBegins = new Date(2010, 11, 26, 12, 0, 0);
var eventEnds = new Date(2010, 11, 26, 14, 0, 0);
var details = {
title: 'Do some stuff',
description: "I'm going to do some stuff at this time.",
begin: eventBegins,
end: eventEnds
};
var event = calendar.createEvent(details);
// Now add a reminder via e-mail for 10 minutes before the event.
var reminderDetails = {
minutes: 10,
method: Ti.Android.Calendar.METHOD_EMAIL
};
event.createReminder(reminderDetails);
Reminder alert delivery method.
Reminder alert delivery method.
Used with Titanium.Android.Calendar.Reminder.
One of the group of reminder method constants, METHOD_ALERT, METHOD_DEFAULT, METHOD_EMAIL, and METHOD_SMS.
Reminder default delivery method.
Reminder default delivery method.
Used with Titanium.Android.Calendar.Reminder.
One of the group of reminder method constants, METHOD_ALERT, METHOD_DEFAULT, METHOD_EMAIL, and METHOD_SMS.
Reminder email delivery method.
Reminder email delivery method.
Used with Titanium.Android.Calendar.Reminder.
One of the group of reminder method constants, METHOD_ALERT, METHOD_DEFAULT, METHOD_EMAIL, and METHOD_SMS.
Reminder SMS delivery method.
Reminder SMS delivery method.
Used with Titanium.Android.Calendar.Reminder.
One of the group of reminder method constants, METHOD_ALERT, METHOD_DEFAULT, METHOD_EMAIL, and METHOD_SMS.
Alert dismissed state.
Alert dismissed state.
Used with Titanium.Android.Calendar.Alert.
One of the group of reminder method constants, STATE_DISMISSED, STATE_FIRED, and STATE_SCHEDULED.
Alert fired state.
Alert fired state.
Used with Titanium.Android.Calendar.Alert.
One of the group of reminder method constants, STATE_DISMISSED, STATE_FIRED, and STATE_SCHEDULED.
Alert scheduled status.
Alert scheduled status.
Used with Titanium.Android.Calendar.Alert.
One of the group of reminder method constants, STATE_DISMISSED, STATE_FIRED, and STATE_SCHEDULED.
Event canceled status.
Event canceled status.
Used with Titanium.Android.Calendar.Event.
One of the group of reminder method constants, STATUS_CANCELED, STATUS_CONFIRMED, and STATUS_TENTATIVE.
Event confirmed status.
Event confirmed status.
Used with Titanium.Android.Calendar.Event.
One of the group of reminder method constants, STATUS_CANCELED, STATUS_CONFIRMED, and STATUS_TENTATIVE.
Event tentative status.
Event tentative status.
Used with Titanium.Android.Calendar.Event.
One of the group of reminder method constants, STATUS_CANCELED, STATUS_CONFIRMED, and STATUS_TENTATIVE.
Event confidential visibility.
Event confidential visibility.
Used with Titanium.Android.Calendar.Event.
One of the group of reminder method constants, VISIBILITY_CONFIDENTIAL, VISIBILITY_DEFAULT, VISIBILITY_PRIVATE, and VISIBILITY_PUBLIC.
Event default visibility.
Event default visibility.
Used with Titanium.Android.Calendar.Event.
One of the group of reminder method constants, VISIBILITY_CONFIDENTIAL, VISIBILITY_DEFAULT, VISIBILITY_PRIVATE, and VISIBILITY_PUBLIC.
Event private visibility.
Event private visibility.
Used with Titanium.Android.Calendar.Event.
One of the group of reminder method constants, VISIBILITY_CONFIDENTIAL, VISIBILITY_DEFAULT, VISIBILITY_PRIVATE, and VISIBILITY_PUBLIC.
Event public visibility.
Event public visibility.
Used with Titanium.Android.Calendar.Event.
One of the group of reminder method constants, VISIBILITY_CONFIDENTIAL, VISIBILITY_DEFAULT, VISIBILITY_PRIVATE, and VISIBILITY_PUBLIC.
All alerts in selected calendars.
All alerts in selected calendars.
All calendars known to the native calendar app.
All calendars known to the native calendar app.
The name of the API that this proxy corresponds to.
The name of the API that this proxy corresponds to.
The value of this property is the fully qualified name of the API. For example, Button
returns Ti.UI.Button
.
Indicates if the proxy will bubble an event to its parent.
Some proxies (most commonly views) have a relationship to other proxies, often established by the add() method. For example, for a button added to a window, a click event on the button would bubble up to the window. Other common parents are table sections to their rows, table views to their sections, and scrollable views to their views. Set this property to false to disable the bubbling to the proxy's parent.
Default: true
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
The Window or TabGroup whose Activity lifecycle should be triggered on the proxy.
If this property is set to a Window or TabGroup, then the corresponding Activity lifecycle event callbacks will also be called on the proxy. Proxies that require the activity lifecycle will need this property set to the appropriate containing Window or TabGroup.
All calendars selected within the native calendar app, which may be a subset of allCalendars
.
All calendars selected within the native calendar app, which may be a subset of allCalendars
.
The native calendar application may know via the registered webservices, such as Gooogle or Facebook accounts about calendars that it has access to but have not been selected to be displayed in the native calendar app.
Adds the specified callback as an event listener for the named event.
Name of the event.
Callback function to invoke when the event is fired.
Applies the properties to the proxy.
Properties are supplied as a dictionary. Each key-value pair in the object is applied to the proxy such that myproxy[key] = value.
A dictionary of properties to apply.
Fires a synthesized event to any registered listeners.
Name of the event.
A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.
Gets the calendar with the specified identifier.
Integer identifier of the calendar.
Removes the specified callback as an event listener for the named event.
Multiple listeners can be registered for the same event, so the
callback
parameter is used to determine which listener to remove.
When adding a listener, you must save a reference to the callback function in order to remove the listener later:
var listener = function() { Ti.API.info("Event listener called."); }
window.addEventListener('click', listener);
To remove the listener, pass in a reference to the callback function:
window.removeEventListener('click', listener);
Name of the event.
Callback function to remove. Must be the same function passed to addEventListener
.
Sets the value of the bubbleParent property.
New value for the property.
Sets the value of the lifecycleContainer property.
New value for the property.