PageRenderTime 11ms CodeModel.GetById 3ms app.highlight 3ms RepoModel.GetById 2ms app.codeStats 0ms

/lib/titanium/mobile/android/GeneralCalendar.hx

http://github.com/visup/haxe-titanium-api
Haxe | 248 lines | 28 code | 6 blank | 214 comment | 0 complexity | 3c0ababd132b65e77e2157ac3842093b MD5 | raw file
  1package titanium.mobile.android;
  2
  3import titanium.mobile.core.Dispatcher;
  4import titanium.mobile.android.calendar.Alert;
  5import titanium.mobile.android.calendar.Calendar;
  6
  7/**
  8GeneralCalendar class
  9
 10Documentation available at:
 11http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Android.Calendar-module
 12
 13- namespace
 14
 15Titanium.Android.Calendar
 16
 17- type
 18
 19module
 20
 21- returns
 22
 23object
 24
 25- description
 26
 27The Android.Calendar module provides proxies and methods for accessing the native Android calendar functionality.
 28
 29- since
 30
 311.5
 32
 33- platforms
 34
 35android
 36
 37- properties
 38
 39METHOD_ALERT[int]: constant for the `Titanium.Android.Calendar.Reminder` method property.
 40METHOD_DEFAULT[int]: constant for the `Titanium.Android.Calendar.Reminder` method property.
 41METHOD_EMAIL[int]: constant for the `Titanium.Android.Calendar.Reminder` method property.
 42METHOD_SMS[int]: constant for the `Titanium.Android.Calendar.Reminder` method property.
 43STATE_DISMISSED[int]: constant for the `Titanium.Android.Calendar.Alert` state property.
 44STATE_FIRED[int]: constant for the `Titanium.Android.Calendar.Alert` state property.
 45STATE_SCHEDULED[int]: constant for the `Titanium.Android.Calendar.Alert` state property.
 46STATUS_TENTATIVE[int]: constant for the `Titanium.Android.Calendar.Event` status property.
 47STATUS_CONFIRMED[int]: constant for the `Titanium.Android.Calendar.Event` status property.
 48STATUS_CANCELED[int]: constant for the `Titanium.Android.Calendar.Event` status property.
 49VISIBILITY_DEFAULT[int]: constant for the `Titanium.Android.Calendar.Event` visibility property.
 50VISIBILITY_CONFIDENTIAL[int]: constant for the `Titanium.Android.Calendar.Event` visibility property.
 51VISIBILITY_PRIVATE[int]: constant for the `Titanium.Android.Calendar.Event` visibility property.
 52VISIBILITY_PUBLIC[int]: constant for the `Titanium.Android.Calendar.Event` visibility property.
 53
 54allAlerts[array]: Array of `Titanium.Android.Calendar.Alert` objects representing all alerts.
 55
 56allCalendars[array]: Array of `Titanium.Android.Calendar.Calendar` objects representing all the calendars known to the native calendar app.
 57
 58selectableCalendars[array]: Array of `Titanium.Android.Calendar.Calendar` objects representing calendars selected within the native calendar app. This may be a subset of allCalendars; for example, the native calendar application may know -- via your Gooogle account -- about calendars that you have access to but have not selected to be displayed in the native calendar app.
 59
 60- methods
 61
 62getCalendarById: Returns the `Titanium.Android.Calendar.Calendar` object specified by the given integer id.
 63
 64- method : getCalendarById, object
 65
 66id[int]: The system id of the calendar to be retrieved. 
 67
 68- notes
 69
 70The API 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.
 71
 72- example : All Calendars vs Selectable Calendars
 73
 74Prints the names of all of your calendars known to Android, then prints the names of calendars that you have selected in the native Android calendar application.  The latter could be a subset, because (for example) Android -- via your Google account -- may know about more calendars that you have access to but that you have not selected inside the calendar app.
 75
 76~~~
 77function showCalendars(calendars) {
 78	for (var i = 0; i < calendars.length; i++) {
 79		Ti.API.info(calendars[i].name);
 80	}
 81}
 82
 83Ti.API.info('ALL CALENDARS:');
 84showCalendars(Ti.Android.Calendar.allCalendars);
 85Ti.API.info('SELECTABLE CALENDARS:');
 86showCalendars(Ti.Android.Calendar.selectableCalendars);
 87~~~
 88
 89- example : Events in a year
 90
 91This example will look at each event in a year for a given calendar.  Just set the desired calendar's id and the desired year to see it in action.  You can see calendar ids by running the example above.
 92
 93~~~
 94var win = Ti.UI.currentWindow;
 95var sv = Ti.UI.createScrollView();
 96win.add(sv);
 97
 98var console = Ti.UI.createLabel({
 99	backgroundColor: 'white', color: 'black', text: 'generating info...'
100});
101sv.add(console);
102
103var consoleString = '';
104
105function print(s) {
106	Ti.API.info(s);
107	if (consoleString.length > 0) {
108		consoleString = consoleString + '\n';
109	}
110	consoleString = consoleString + s;
111}
112
113
114// SHOW ALL EVENTS FOR 2010 FOR ONE CALENDAR
115var YEAR = 2010;
116var TEST_WITH_THIS_CAL_ID = 3;
117var calendar = Ti.Android.Calendar.getCalendarById(TEST_WITH_THIS_CAL_ID);
118
119function printReminder(r) {
120	var typetext = '[method unknown]';
121	if (r.method == Ti.Android.Calendar.METHOD_EMAIL) {
122		typetext = 'Email';
123	} else if (r.method == Ti.Android.Calendar.METHOD_SMS) {
124		typetext = 'SMS';
125	} else if (r.method == Ti.Android.Calendar.METHOD_ALERT) {
126		typetext = 'Alert';
127	} else if (r.method == Ti.Android.Calendar.METHOD_DEFAULT) {
128		typetext = '[default reminder method]';
129	}
130	print(typetext + ' reminder to be sent ' + r.minutes + ' minutes before the event');
131}
132
133function printAlert(a) {
134	print('Alert id ' + a.id + ' begin ' + a.begin + '; end ' + a.end + '; alarmTime ' + a.alarmTime + '; minutes ' + a.minutes);
135}
136
137function printEvent(event) {
138	if (event.allDay) {
139		print('Event: ' + event.title + '; ' + event.begin.toLocaleDateString() + ' (all day)');
140	} else {
141		print('Event: ' + event.title + '; ' + event.begin.toLocaleDateString() + ' ' + event.begin.toLocaleTimeString()+ '-' + event.end.toLocaleTimeString());
142	}
143
144	var reminders = event.reminders;
145	if (reminders && reminders.length) {
146		print('There is/are ' + reminders.length + ' reminder(s)');
147		for (var i = 0; i < reminders.length; i++) {
148			printReminder(reminders[i]);
149		}
150	}
151
152	print('hasAlarm? ' + event.hasAlarm);
153	var alerts = event.alerts;
154	if (alerts && alerts.length) {
155		for (i = 0; i < alerts.length; i++) {
156			printAlert(alerts[i]);
157		}
158	}
159
160	var status = event.status;
161	if (status == Ti.Android.Calendar.STATUS_TENTATIVE) {
162		print('This event is tentative');
163	}
164	if (status == Ti.Android.Calendar.STATUS_CONFIRMED) {
165		print('This event is confirmed');
166	}
167	if (status == Ti.Android.Calendar.STATUS_CANCELED) {
168		print('This event was canceled');
169	}
170}
171
172var events = calendar.getEventsInYear(YEAR);
173if (events && events.length) {
174	print(events.length + ' event(s) in ' + YEAR);
175	print('');
176	for (var i = 0; i < events.length; i++) {
177		printEvent(events[i]);
178		print('');
179	}
180} else {
181	print('No events on 2010-12-6');
182}
183
184console.text = consoleString;
185~~~
186
187- example : Create an Event and Reminder
188
189This example creates an event and adds an e-mail reminder for 10 minutes before the event.
190
191~~~
192var CALENDAR_TO_USE = 3;
193var calendar = Ti.Android.Calendar.getCalendarById(CALENDAR_TO_USE);
194
195// Create the event
196var eventBegins = new Date(2010, 11, 26, 12, 0, 0);
197var eventEnds = new Date(2010, 11, 26, 14, 0, 0);
198var details = {
199	title: 'Do some stuff',
200	description: "I'm going to do some stuff at this time.",
201	begin: eventBegins,
202	end: eventEnds
203};
204
205var event = calendar.createEvent(details);
206
207// Now add a reminder via e-mail for 10 minutes before the event.
208var reminderDetails = {
209	minutes: 10,
210	method: Ti.Android.Calendar.METHOD_EMAIL
211};
212event.createReminder(reminderDetails);
213~~~
214
215
216
217**/
218
219
220#if androidos
221@:native("Titanium.Android.Calendar")
222extern class GeneralCalendar extends Dispatcher
223{
224	// constants
225	public static var METHOD_ALERT:Int;
226	public static var METHOD_DEFAULT:Int;
227	public static var METHOD_EMAIL:Int;
228	public static var METHOD_SMS:Int;
229	public static var STATE_DISMISSED:Int;
230	public static var STATE_FIRED:Int;
231	public static var STATE_SCHEDULED:Int;
232	public static var STATUS_TENTATIVE:Int;
233	public static var STATUS_CONFIRMED:Int;
234	public static var STATUS_CANCELED:Int;
235	public static var VISIBILITY_DEFAULT:Int;
236	public static var VISIBILITY_CONFIDENTIAL:Int;
237	public static var VISIBILITY_PRIVATE:Int;
238	public static var VISIBILITY_PUBLIC:Int;
239		
240	// static properties
241	public static var allAlerts:Array<Alert>;
242	public static var allCalendars:Array<Calendar>;
243	public static var selectableCalendars:Array<Calendar>; 
244
245	// static methods
246	public static function getCalendarById(id:Int):Calendar;
247}
248#end