tizen ver2.2 calendar api 例 api • 形式符合icalendar(internet calendaring and scheduling core...

26
Tizen Ver2.2 - Calendar API 2014. 11. 09

Upload: nguyenduong

Post on 08-May-2018

236 views

Category:

Documents


10 download

TRANSCRIPT

Page 1: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Tizen Ver2.2 - Calendar API ⽰示例2014. 11. 09

Page 2: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

内容• Calendar API

• 组件• 函数

• ⽰示例

Page 3: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Calendar APIComponenets, Functions

Page 4: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

…Ajou Univrsity

Calendar API• 能够管理⽇日程并把相关活动和任务分组• calendar 是⼀一个活动(events)和任务(tasks)的集合• 每个活动或任务有⼀一系列的属性,例如⺫⽬目标,起始时间,持续时间

Schedule

[Attributes]

purpose

starting time

duration

[Type]

event

task

Page 5: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Calendar API

• 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使⽤用和⽀支持包括Google Calendar, Apple Calendar, IBM Lotuse Notes, Yahoo! Calendar等。[引⾃自wikipedia]• 定义了Calendar接⼝口中的⽅方法:

• • • •

addupdateremovesearch

• 为了在web应⽤用中创建⼀一个新的calendar, 你需要创建⼀一个hybrid application. 你可以使⽤用Tizen::Social::Calendarbook 类.

Ajou Univrsity

Page 6: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Calendar API

• CalendarManager 接⼝口 • 提供了获得calendar和calendar属性的⽅方法 • ⼀一旦获得了calendar对象,就可以通过接⼝口⽅方法来add,remove,update它所包含的信息

CalendarManager

+void getCalendars (CalendarType type, CalendarArraySuccessCallback successCallback, optional ErrorCallback? errorCallback) +Calendar getUnifiedCalendar (CalendarType type) +Calendar getDefaultCalendar (CalendarType type) +Calendar getCalendar (CalendarType type, CalendarId id)

Gets an array of Calendar objects.Gets the aggregation of allcalendars that are obtainedfrom getCalendars and containsall events or tasks. It does nothave the calendar id nor namewhich are set to null.

Gets the default calendar, which isused for new items.Gets the calendar with thespecified identifier and type.

Page 7: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

+void add (CalendarItem item)+void update (CalendarItem item, optionalboolean? updateAllInstances)+void remove (CalendarItemId id)+void find(CalendarItemArraySuccessCallbacksuccessCallback, optional ErrorCallback?errorCallback, optional AbstractFilter? filter,optional SortMode? sortMode)+long addChangeListener(CalendarChangeCallback successCallback)+void removeChangeListener (long watchId)+void addBatch //omit+void updateBatch //omit+void removeBatch//omit

readonly attribute CalendarId idreadonly attribute DOMString name+CalendarItem get (CalendarItemId id)

Calendar API

• Calendar 接⼝口 • 包含管理⼀一个calendar中活动(events)和任务(tasks)的⽅方法 • 根据calendar的类型,⼀一个calendar对象包含了⼀一个任务集合 An attribute to uniquely identify a Calendar

An attribute to assign a readable(descriptive) name for a calendar,such as work, personal, etc.

Gets the calendar item with thespecified identifier.Adds an item to the calendarsynchronously.Updates an existing item in thecalendar synchronously with the onespecified in the argument.Removes an item from the calendarthat corresponds to the specifiedidentifier. This method will throw anexception if it fails to remove thespecified calendar item.

Page 8: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Calendar API

• Calendar Interface • 包含管理⼀一个calendar中活动(events)和任务(tasks)的⽅方法 • 根据calendar的类型,⼀一个calendar对象包含了⼀一个任务集合 Calendar

+void addBatch //omit+void updateBatch //omit+void removeBatch//omit Ajou Univrsity

readonly attribute CalendarId idreadonly attribute DOMString name+CalendarItem get (CalendarItemId id)+void add (CalendarItem item)+void update (CalendarItem item, optionalboolean? updateAllInstances)+void remove (CalendarItemId id)+void find(CalendarItemArraySuccessCallbacksuccessCallback, optional ErrorCallback?errorCallback, optional AbstractFilter? filter,optional SortMode? sortMode)+long addChangeListener(CalendarChangeCallback successCallback)+void removeChangeListener (long watchId)

Finds and fetches an arrayof CalendarItem objects for itemsstored in the calendar according tothe supplied filter if it is valid else itwill return all the items stored.Adds a listener to receivenotifications about calendar changes.Unsubscribes from receivingnotification for a calendar itemchanges.add, update, remove an array ofitems to the calendar aynchronously

Page 9: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Calendar API

• CalendarItems接⼝口 • 包含events和tasks共有的属性

CalendarItem

+DOMString convertToString (CalendarTextFormat format) CalendarItem clone ()

CalendarTask CalendarEvent

+void expandRecurrence (TZDate startDate, TZDate endDate, CalendarEventArraySuccessCallb ack successCallback, optional ErrorCallback? errorCallback)

Ajou Univrsity

Page 10: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Calendar API

• CalendarTask: 与 RFC5545标准⼀一致. 增加的属性如下

• (TZDate) dueDate: 存储完成任务的截⽌止⽇日期和时间

• code example

• (TZDate) completedDate: 记录任务完成的⽇日期和时间

• code example

• (unsigned short) progress: 记录任务的完成百分⽐比,值为0到100的正整数

• code example

task.dueDate = new tizen.TZDate(2011, 2, 11);

task.completedDate = new tizen.TZDate(2011, 2, 11);

task.progress = 50; // 50% done

Page 11: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Calendar API

• CalendarEvent:与 RFC5545标准⼀一致. 增加的属性如下

• readonly (Boolean) isDetached:类似于⼀一个flag,表明⼀一个循环事件是否被派遣(detached)以及它是否被改变并保存到calendar中

• (TZDate) endDate: to 记录event的结束⽇日期和时间• code example

• (EventAvailability) availability: 表明对⼀一个event⽽而⾔言person的可得性(BUSY, FREE)

• (CalendarRecurrenceRule) recurrenceRule:记录event的循环规则

• code example

event.endDate = new tizen.TZDate(2010, 3, 30, 9, 0);

var rule = new tizen.CalendarRecurrenceRule("DAILY", {occurrenceCount: 7}); event.recurrenceRule = rule;

Page 12: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Exampleadd task/event, find, remove, set recurrence, set alarm增加 task/event,find,remove,设置recurrence,设置alarm

Page 13: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

需要的权限Required Privileges

• 在config.xml ⽂文件中<!--Configuration file content--><widget ...>

<!--Other configuration details--><tizen:privilege name="http://tizen.org/privilege/application.launch"/><tizen:privilege name="http://tizen.org/privilege/calendar.read"/><tizen:privilege name="http://tizen.org/privilege/calendar.write"/><tizen:privilege name="http://tizen.org/privilege/time"/>

</widget>

Page 14: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

获取 Calendar

• 获取默认的calendar

你可以通过四种⽅方式获取⼀一个calendar:通过id和type具体化的calendar,calendars数组,被新的item使⽤用默认的calendar,包含所有events和tasks的所有calendars的聚合

Page 15: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

默认Calendar

• 获取默认的calendar

默认 calendar 被返回

Page 16: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Retrieve Calendar

• 获取统⼀一的alendar

统⼀一的calendar没有id和name

Page 17: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

增加Task

• 获取默认Calendar

新的task可以通过Tizen.CalendarTask()定义通过calendar.add() 函数它可以被很简单地加上.

call getCalendar() fucntion

Page 18: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

call getTask() fucntion

Even if you add same task severaltimes, it keeps making tasks

获取Task

• 获取默认Calendar 通过 Calendar.find() 函数获取上张幻灯⽚片中增加的 如果它返回success,回调函数会获得⼀一个tasks集合

确保调⽤用了⼀一个calendar, 否则,tasks获取不到内容

Page 19: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

call default fucntion

增加Event

• 获取默认calendar

增加event和增加task相似 确保你写的event属性是否正确

‘PRIVATE’ is right. ‘Private’ makes error.

及时你写了错误的属性,也可以向calendar中增加event

Page 20: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

删除Event(Task)

如何使⽤用batch函数

如果你想删除events或者tasks,你可以使⽤用Calendar.remove(id) 函数.

Page 21: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

使⽤用addBatch() 函数• 如何使⽤用batch函数 addBatch() 函数使你增加多个calendar

的item(task和event),但是不可以同时加两个)

Ajou Univrsity

Page 22: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Filter/SortMode

call getHighPriorityEvents() fucntion

使⽤用’Filter’属性,你可以获取你需要的具体的calendar的item

‘SortMode’属性使得找到的calendar item按照升序或降序排列

Page 23: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Recurrent Event

call setrecurrenceEvent() fucntion

设置⼀一个recurrence规则,你可以制定recurrence事件

Page 24: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Checking Recurrence

通过按照recurrence规则过滤的calendar item,检查上张幻灯⽚片中的recurrence规则是否与event相适应

Page 25: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

设置Alarm

call setAlarm() fucntion

你可以通过Tizen在事件中设置alarm

Tizen.CalendarAlarm 函数的第⼆二个参数是

‘AlarmMethod’ ,它可以选择为“SOUND”或“DISPLAY”.

Page 26: Tizen Ver2.2 Calendar API 例 API • 形式符合iCalendar(Internet Calendaring and Scheduling Core Object Specification)标准 • 它由很多产品使和持包括 Google Calendar,

Ajou Univrsity

Reference

Hojun Jaygarl at al. Professional Tizen Application Development, wrox, 2014.Tizen Dev Guide 2.2.1https://developer.tizen.org/ko/documentation/dev-guide/2.2.1