Titanium.Android.Calendar
> Titanium.Android.Calendar

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.

Examples

All Calendars vs Selectable Calendars

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);

Events in a year

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();

Create an Event and Reminder

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);
  • 1.5
Defined By

Properties

Titanium.Android.Calendar
METHOD_ALERT : Numberreadonly

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.

Titanium.Android.Calendar
METHOD_DEFAULT : Numberreadonly

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.

Titanium.Android.Calendar
METHOD_EMAIL : Numberreadonly

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.

Titanium.Android.Calendar
METHOD_SMS : Numberreadonly

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.

Titanium.Android.Calendar
STATE_DISMISSED : Numberreadonly

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.

Titanium.Android.Calendar
STATE_FIRED : Numberreadonly

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.

Titanium.Android.Calendar
STATE_SCHEDULED : Numberreadonly

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.

Titanium.Android.Calendar
STATUS_CANCELED : Numberreadonly

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.

Titanium.Android.Calendar
STATUS_CONFIRMED : Numberreadonly

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.

Titanium.Android.Calendar
STATUS_TENTATIVE : Numberreadonly

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.

Titanium.Android.Calendar
VISIBILITY_CONFIDENTIAL : Numberreadonly

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.

Titanium.Android.Calendar
VISIBILITY_DEFAULT : Numberreadonly

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.

Titanium.Android.Calendar
VISIBILITY_PRIVATE : Numberreadonly

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.

Titanium.Android.Calendar
VISIBILITY_PUBLIC : Numberreadonly

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.

Titanium.Android.Calendar
allAlerts : Titanium.Android.Calendar.Alert[]readonly

All alerts in selected calendars.

All alerts in selected calendars.

Titanium.Android.Calendar
allCalendars : Titanium.Android.Calendar.Calendar[]readonly

All calendars known to the native calendar app.

All calendars known to the native calendar app.

apiName : Stringreadonly

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.

  • 3.2.0
  • 3.2.0
  • 3.2.0
Indicates if the proxy will bubble an event to its parent. ...

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

  • 3.0.0
  • 3.0.0
  • 3.0.0

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.

  • 3.6.0
Titanium.Android.Calendar
selectableCalendars : Titanium.Android.Calendar.Calendar[]readonly

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.

Defined By

Methods

Adds the specified callback as an event listener for the named event. ...

Adds the specified callback as an event listener for the named event.

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to invoke when the event is fired.

Returns

  • void
Applies the properties to the proxy. ...

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.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • props : Dictionary

    A dictionary of properties to apply.

Returns

  • void
Fires a synthesized event to any registered listeners. ...

Fires a synthesized event to any registered listeners.

Parameters

  • name : String

    Name of the event.

  • event : Dictionary

    A dictionary of keys and values to add to the Titanium.Event object sent to the listeners.

Returns

  • void
Titanium.Android.Calendar
( ) : Titanium.Android.Calendar.Alert[]
Gets the value of the allAlerts property. ...

Gets the value of the allAlerts property.

Returns

Titanium.Android.Calendar
( ) : Titanium.Android.Calendar.Calendar[]
Gets the value of the allCalendars property. ...

Gets the value of the allCalendars property.

Returns

Gets the value of the apiName property. ...

Gets the value of the apiName property.

  • 3.2.0
  • 3.2.0
  • 3.2.0

Returns

  • String
Gets the value of the bubbleParent property. ...

Gets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Returns

  • Boolean
Titanium.Android.Calendar
( id ) : Titanium.Android.Calendar.Calendar
Gets the calendar with the specified identifier. ...

Gets the calendar with the specified identifier.

Parameters

  • id : Number

    Integer identifier of the calendar.

Returns

Gets the value of the lifecycleContainer property. ...

Gets the value of the lifecycleContainer property.

  • 3.6.0

Returns

Gets the value of the selectableCalendars property. ...

Gets the value of the selectableCalendars property.

Returns

Removes the specified callback as an event listener for the named event. ...

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);

Parameters

  • name : String

    Name of the event.

  • callback : Callback<Object>

    Callback function to remove. Must be the same function passed to addEventListener.

Returns

  • void
Sets the value of the bubbleParent property. ...

Sets the value of the bubbleParent property.

  • 3.0.0
  • 3.0.0
  • 3.0.0

Parameters

  • bubbleParent : Boolean

    New value for the property.

Returns

  • void
Sets the value of the lifecycleContainer property. ...

Sets the value of the lifecycleContainer property.

  • 3.6.0

Parameters

Returns

  • void