Triggers: Difference between revisions

951 bytes removed ,  6 October 2016
m
no edit summary
mNo edit summary
mNo edit summary
Line 446: Line 446:
</source>
</source>


====Скрипт открывающий форму создания события в Гугл-Календаре.====
==== Script to insert an appointment into Google Calendar ====
Время события и название события будут определяться полями записи.
Suppose a library contains time and name of an appointment.
<source lang="javascript" line>
 
i = intent("android.intent.action.INSERT")
<source lang="javascript">
i.data("content://com.android.calendar/events")
i = intent("android.intent.action.INSERT")                 // Create Intent object with action Create Appointment
i.extra("title", entry().field("Title"))
i.data("content://com.android.calendar/events")             // For INSERT event, data contains Google Calendar URI
i.extra("description" , entry().field("Description"))
i.extra("title", entry().field("Title"))                   // Get name of event from the field Title
i.extraLong("beginTime" , entry().field("Begin").getTime())
i.extra("description" , entry().field("Description"))       // Get description of event from the field Description
i.extraLong("endTime" , entry().field("End").getTime())
i.extraLong("beginTime" , entry().field("Begin").getTime()) // Get start time from the field Begin. Begin is of type DateTime.
i.send()
                                                            // Additional parameter is of type Long, so extraLong() is used for conversion.
i.extraLong("endTime" , entry().field("End").getTime())     // Get end time from the field End. Requires same conversion as above.
i.send()                                                   // Send the message
</source>
</source>
# Создаем объект обмена сообщениями Intent и указываем действие которое требуется выполнить, а именно создание объекта - android.intent.action.INSERT.
# Для события android.intent.action.INSERT в data требуется передать базовый Uri создаваемого объекта. Событие в Google-календаре имеет базовый Uri - content://com.android.calendar/events.
# Устанавливаем название события, которое берем из поля Title.
# Устанавливаем описание события, которое берем из поля Description.
# Устанавливаем время начала события, которое берем из поля Begin. Поле Begin должно иметь тип Date/Time. Дополнительный параметр beginTime должен иметь тип Long, поэтому используется метод extraLong.
# Устанавливаем время окончания события, которое берем из поля End. Поле End должно иметь тип Date/Time. Дополнительный параметр endTime должен иметь тип Long, поэтому используется метод extraLong.
# Отправляем сообщение.


== JavaScript links ==
== JavaScript links ==
{{Template:JavaScriptLinks}}
{{Template:JavaScriptLinks}}