Академический Документы
Профессиональный Документы
Культура Документы
Wiley also publishes its books in a variety of electronic formats. Some content that appears in print
may not be available in electronic books.
ISBN: 978-1-118-73606-7
Printed and bound in the United States
10 9 8 7 6 5 4 3 2 1
Contents at a Glance
Introduction....................................................... 1
Part I: Introducing Tizen..................................... 5
Chapter 1: Getting an Inside Look at Tizen............................................. 7
Chapter 2: Exploring the Tizen Architecture........................................ 17
Acknowledgments.......................................... 199
Table of Contents
Introduction........................................................ 1
About This Book......................................................................... 1
Conventions Used in This Book ............................................... 1
Who Should Read This Book..................................................... 2
How This Book Is Organized..................................................... 2
Part I: Introducing Tizen.................................................. 3
Part II: Getting Practical................................................... 3
Part III: Tizen in Detail...................................................... 3
Part IV: The Part of Tens.................................................. 3
Icons Used in This Book............................................................. 4
Where to Go from Here.............................................................. 4
Acknowledgments........................................... 199
xii Tizen For Dummies, Developer Conference Edition
Introduction
W elcome to Tizen For Dummies. This book will be your
best friend to help you understand the technologies
and story behind the Tizen platform.
The Tizen SDK Help will always provide the most up-to-date
reference information. Check out https://developer.
tizen.org and the resources listed throughout this book to
ensure that you stay up to date.
The Tip icon points out important information that can save
you time or make a task easier.
Getting an Inside
Look at Tizen
In This Chapter
▶ Discovering what makes Tizen unique
▶ Becoming part of the Tizen community
Discovering Tizen
Tizen is an open source, standards-based, cross-architecture
device software platform designed to find a place in
everything from smartphones to smart TVs and beyond.
You can find out more about Tizen and the Tizen Association
at www.tizen.org and www.tizenassociation.org.
Focusing on HTML5
Tizen’s primary focus for application development is HTML5,
which is rapidly emerging as the preferred development envi-
ronment for mobile applications. Tizen support for HTML5
is extensive and powerful. It includes support for most of the
major W3C APIs included under the banner of HTML5, as well
as many supplementary web APIs.
The lowest layer is the kernel. For open source mobile plat-
forms, this layer will generally be a Linux kernel. The kernel
interacts with middleware components to talk to the hard-
ware. It’s the middleware layer that the platform developers,
who contribute to the components of the platform, will be
most interested in.
Not only does the Tizen web engine (based on WekKit2 since
Tizen 2.0) perform well, its web browser also scores highly in
web standards compliance tests, finishing first according to
the scores from http://html5test.com, which test how
well a browser supports HTML5 specifications.
Tizen is open
As an open source software platform, Tizen provides many
opportunities for both individuals and Original Equipment
Manufacturers (OEMs) – the people that make the phones.
Anyone can grab the source code and customize it to meet
their own needs. Any OEM can ship Tizen devices with a cus-
tomized user interface, app store, or set of services.
Defining open
At any gathering of open source code to the platform is freely
developers, the one subject available, anyone can download it,
guaranteed to cause an argument – and you can use it for any purpose in
aside from which pizza restaurant to any project. We accept that this may
order from – is ‘What is the definition not meet everyone’s definition of
of open source?’ open source software, but this is our
definition, and we’re sticking to it.
In this book, we describe Tizen as
open source because the source
12 Part I: Introducing Tizen
Tizen is innovative
Innovation can come from many sources. It may be an idea
from an individual or an organisation’s R&D projects, but
most innovation comes from collaboration.
Comparing Tizen to
Other Platforms
Tizen’s openness contrasts with closed, proprietary plat-
forms, such as iOS, Blackberry 10 and Windows Phone, for
which the source code is not available. The choice for users
of these platforms is also limited, with only Windows Phone
licensed to other manufacturers and the rest available only on
the vendor’s devices.
Chapter 1: Getting an Inside Look at Tizen 13
Of the open source alternatives, WebOS and Firefox OS are
both platforms with potential, but they don’t have the same
level of industry support as Tizen.
Android is the best known open source platform, but the gov-
ernance of the platform is arguably not as open, and its stan-
dards support isn’t as comprehensive as Tizen.
Getting Involved
You can participate and contribute to the Tizen Project at dif-
ferent levels. As described on the Tizen website (www.tizen.
org), you can be a platform contributor, an application devel-
oper, a user, or a Tizen product vendor.
At the platform level, the membership for the TSG (for exam-
ple, groups responsible for areas such as Release Engineering,
Quality Assurance, and Program Management) is invitation
14 Part I: Introducing Tizen
Submitting patches
If you think you can improve the existing code of the Tizen
platform, you can submit your changes to the Gerrit system
for code review. The maintainer, release engineers, and the
QA team will review your patches and decide whether they
will be accepted based on the quality of your code. Once the
changes are approved, you can submit them to the Gerrit
system and Gerrit will merge the changes into the Tizen code
base. You can find a guide to submitting changes at:
https://source.tizen.org/documentation/
developer-guide/submitting-patches
https://wiki.tizen.org/wiki/Main_Page
Details of these mailing lists and how to join them are pro-
vided on the Tizen community website:
www.tizen.org/community/mailing-lists
www.tizen.org/irclogs
Chapter 1: Getting an Inside Look at Tizen 15
Forums
Another source of help and information are the forums avail-
able on the Tizen developer site:
https://developer.tizen.org/forums
Bug tracker
Tizen uses JIRA to track bugs and gather requests for new
features:
https://bugs.tizen.org/jira
Going native
The 2.1 release of the Tizen SDK device functionality not supported
includes a set of C++ APIs which by the web APIs. However, web
you can use to create native apps. apps are more portable, support all
Depending on your requirements, the HTML5 standards and still have
you can choose whether to create a most of the features of native apps.
web app or take the native approach.
This book concentrates on web
Developing a native app is a good apps, but you can find full details of
choice if your app is performance the C++ APIs, as well as examples
intensive or you need access to and tutorials, in the SDK help.
Chapter 2: Exploring the Tizen Architecture 19
The web runtime
Each web app runs in its own process. In the task manager of
a Tizen device, you can see a Tizen web app just like a native
app. You can utilise process scheduling and management, and
platform security features also apply.
Installer
When an application is installed, the Tizen package manager
is called to install the web application. The package man-
ager invokes the web runtime’s app installer program, which
checks that the app is properly signed and then starts the
installation. Once installed, the app is registered with the web
runtime database using the information supplied in the app’s
configuration file, including the app ID, name of the app, and
icon. The app’s icon then appears in the menu screen.
Runtime core
The runtime core is responsible for managing the lifecycle of
an application, including startup, suspend and resume, and
terminate.
The idea behind these APIs isn’t to compete with the W3C
APIs. In fact, Samsung and Intel participate on various stan-
dards committees that define W3C APIs. The aim is that the
Tizen device APIs will one day be absorbed into W3C so that
they’ll become standards.
Tizen
The Tizen JavaScript object is used to access device APIs
such as Contact, Calendar and NFC.
For example, to access the default address book, you use the
following code:
Throughout this book and in the Tizen SDK, the web Interface
Definition Language (IDL) is used to describe APIs in a lan-
guage independent way. This allows the APIs to be described
using terms familiar to those of you with a background in
strongly typed object oriented languages, such as C++, even
though the APIs are accessed through JavaScript.
Apart from being the base object used to access the other
device APIs, the tizen object also provides access to a set
of generic functions, including error handling and filters.
Chapter 9 demonstrates how to use filters.
24 Part I: Introducing Tizen
Alarm
The Alarm API allows you to set an alarm to run an application
at a specified time and launch it if it’s not already running.
Application
The Application API allows you to retrieve a list of running
applications and launch other apps by using an application
control. So, you might launch the camera app to take a picture
or record video or use the media player to play music files.
You can also provide services to other apps. Chapter 9 covers
launching an application using an application control.
Bookmark
The Bookmark API provides access to the device’s book-
marks. You can use it to retrieve bookmarks, as well as add
and remove both bookmarks and bookmark folders.
Bluetooth
The Bluetooth API provides access to the Bluetooth protocol,
which can be used for transmitting files over short distances
between devices.
Calendar
The Calendar API allows you to manage events and tasks
so that it can handle your schedule or to-do list. Chapter 13
explains the Calendar API in detail.
CallHistory
The CallHistory API provides access to the call history func-
tionality, such as finding and removing call history entries.
Chapter 2: Exploring the Tizen Architecture 25
Contacts
You use the Contacts API to manage contacts and handle mul-
tiple address books. Chapter 12 explains the Contacts API in
detail.
Content
The Content API lets you search for content on the device,
either stored locally or on a memory card. Chapter 9 shows
you how to use these features.
DataControl
The DataControl API, introduced in Tizen 2.1, is used to
access data exported by other applications, for example
native applications. You can use the functionality provided
by the DataControl API to operate on both SQL and key-value
databases.
DataSynchronization
The DataSynchronization API, supported from Tizen 2.1,
allows you to synchronize device data with a server using the
OMA Data Synchronization 1.2 protocol.
Download
The Download API, introduced in Tizen 2.0, is used to down-
load files from the Internet and monitor the download status.
Filesystem
The Filesystem API provides access to the device’s file system.
The SDK includes more information, including tutorials.
26 Part I: Introducing Tizen
MessagePort
The MessagePort API allows you to exchange data with
another web application, or with a native application. Data is
sent using the RemoteMessagePort, and data is received from
the LocalMessagePort.
Messaging
The Messaging service allows you to send SMS, MMS, and
Email messages and search messages on the device. Chapter 11
explains this API in more detail and provides source code for
searching SMS messages on your device.
NetworkBearerSelection
The NetworkBearerSelection API, new to Tizen 2.1, allows you
to specify a particular network connection to be used from
your web applications to connect a given domain or host.
NFC
Near Field Communication (NFC) is used for short range wire-
less communication. NFC enabled devices can be used for
mobile payments and in a range of other applications. We
explain Near Field Communication (NFC) in detail in Chapter 10.
You discover the different applications of NFC technology and
how to use NFC in your Tizen web apps.
Notification
The Notification API, introduced in Tizen 2.0, provides a way
of alerting the user to events happening in your app. You can
find details of how to create and manage notifications in the
SDK help.
Chapter 2: Exploring the Tizen Architecture 27
Package
The Package API, new to Tizen 2.1, allows you to install and
uninstall packages, retrieve information about the packages
installed on the device, and monitor any changes to installed
packages.
Power
Another new API introduced in Tizen 2.0, this provides access
to a device’s power state and allows you to control display
dimming and brightness, for example. More information,
including a tutorial are included in the SDK.
Push
The Push API, new in Tizen 2.1, allows web applications to
receive push notifications from the push server.
SecureElement
The SecureElement API, introduced in Tizen 2.1, provides
access to secured elements on the device, such as a UICC/SIM,
embedded security element or secure SD card.
SystemInfo
Provides access to device specific information, such as local
storage, battery levels, cellular network, and so on. More
information and a tutorial are included in the SDK.
SystemSetting
The SystemSetting API, introduced in Tizen 2.0, lets you get
and set various device properties. At the time of writing you
can get and set the following device properties: the device
and lock screen wallpaper, the ringtone for incoming calls and
the email message notification sound.
28 Part I: Introducing Tizen
Time
Provides date and time functions, including working with the
current date and time and locale specific date and time han-
dling. Chapter 13 uses the Time APIs to set the date and time
of calendar tasks.
Part II
Getting Practical
In this part . . .
I n this part we start to get practical. You download and
install the Tizen SDK, start to find your way round the
tools, and build your first Tizen app. In Chapter 3 you
learn enough to get up and running, while Chapter 4 takes
you through each component of a Tizen app in detail.
You’ll explore some of the sample apps and discover how
there’s a world of third-party JavaScript libraries ready for
you to use in your apps. Chapter 5 tidies up the messy
business of testing and debugging.
You might have an existing web app that you want to port
to Tizen, in which case you will find some useful tips in
Chapter 6. We also explain how you can design your Tizen
web app to make it more portable.
Chapter 3
Getting Started
In This Chapter
▶ Installing the Tizen SDK
▶ Building your first web app
▶ Getting Help
Getting perspective
A perspective describes the layout Editor is covered in its own section
of views to help you achieve a later in this chapter.
particular task. In the case of the
You can also open up other useful
default Tizen Web Perspective, that
views not shown in the current
task is web development, so you’ll
perspective by choosing Window➪
see views including the Connection
Show View. There’s much more
Explorer, and HTML Web Page Editor.
detail about perspectives, views, and
Chapter 5 introduces the Connection
the workbench in the Tizen SDK help.
Explorer, while the HTML Web Page
This chapter refers to the 2.1 Magnolia version of the Tizen SDK.
After you install the SDK, the first time you launch the IDE
you’re asked to select a workspace. On the Welcome screen
that appears, choose the Workbench option. The Tizen Web
Perspective appears, as shown in Figure 3-1.
It’s well worth taking a look at all the templates and sample
code provided in the IDE, to give you a head start creating
your app.
To launch the New Project wizard and choose a template,
follow these steps:
Before you can use this option, you need to create your own
application project template. You can create a user template
based on any project, using the Export wizard. To use the
Export wizard, follow these steps:
3. Click Next.
The User Template Export wizard appears.
4. Enter the name and export location.
Chapter 3: Getting Started 37
5. Select the Import a Template check box so that your
template will appear in the New Project wizard.
6. Click Next.
The icon selection screen of the User Template Export
wizard appears.
7. Add any icons that you want to be shown in the new
wizard.
8. Click Next.
The images and descriptions screen appears.
9. Add any images or descriptions that you want
displayed in the new wizard.
10. Click Finish to complete the export of your user
template.
1. Choose File➪Import.
The Import dialog box, shown in Figure 3-4, appears.
2. From the Select an Import Source list, double-click
Tizen and then select Web Projects and Widget file.
3. Click Next.
The Import Widget screen appears.
4. Enter the root directory or click the Browse button
to select the projects you want to copy into the
workspace.
5. Click Finish.
Figure 3-4: The Import dialog box of the New Project Wizard.
1. Choose File➪New➪Project.
2. In the wizard’s drop-down list, double-click the
General folder and then click Project (see Figure 3-5).
3. Click Next.
4. Uncheck the use default location check box and
enter the name and location of your project.
5. Click Finish.
After you create the project, you need to edit two files:
.project and config.xml. You can find full instructions on
how to edit these files on the Tizen developer website:
https://developer.tizen.org/downloads/sample-
web-applications/load-web-app-tizen-sdk
Chapter 3: Getting Started 39
The IDE offers several options, shown in Table 3-1, for viewing
your HTML content.
40 Part II: Getting Practical
To view your HTML file in the HTML Preview tool, select the
Preview button from the IDE’s toolbar.
CSS Preview
You can instantly preview the look and feel of any CSS file
using the CSS Preview tool, shown in Figure 3-8. Google
Chrome is used to display the content in the Preview, and any
changes you make will be reflected immediately.
To view your CSS file in the CSS Preview tool, select the
Preview button from the IDE’s toolbar.
42 Part II: Getting Practical
CSS
The CSS tool removes comments, white space, extra semico-
lons, empty declarations, zero values, and so on from your
CSS code.
If you want to, you can select one of the sample applications
introduced in the ‘Using a sample app’ section, earlier in this
chapter, and try building and running the app for yourself.
44 Part II: Getting Practical
Help documentation
You can find the most up-to-date information about Tizen in
the SDK Help documentation. You can open the Help from
within the IDE, by choosing Help➪Help Contents. You can
also access Help on the Tizen website:
https://developer.tizen.org/documentation
Sample applications
In addition to the tutorials and the sample applications pro-
vided in the SDK, several sample web applications are avail-
able for download from the Tizen developer site:
https://developer.tizen.org/downloads/sample-
web-applications
See Chapter 1 for more details about the Tizen wiki, mailing
list, IRC channel, and forums.
46 Part II: Getting Practical
Chapter 4
If you want to follow along, then why not build one of the
sample apps as described in Chapter 3? This section isn’t
based around one app, but if you have one of the Tizen
samples loaded into the IDE, you’ll be able to find the main
components as they’re explained.
Localized content
The example shown in Figure 4-1 is missing one key ingredient
of a well-designed web app, and that’s localized content.
One of the ways to ensure that your web app displays content
appropriate to the current locale is to use folder-based local-
isation. With this approach, you create a folder for each locale
for which you’re creating localized content. For example, for
the French locale, put localized HTML files, images, and other
resources into the /locales/fr folder at the root level of
the application package. If the current locale is set to French,
then the platform will first look inside this folder for French
localized resources.
You can create all the necessary files and folders for localizing
your app using the Tizen Localization wizard. To launch the
wizard, right-click your project in the Project Explorer panel
and choose the Localization➪Localization Wizard menu item.
This wizard allows you to choose which files to localize, as
well as the locales you want to support.
You can find the folder naming standards as part of the widget
specification at www.w3.org/TR/widgets.
The configuration file
The configuration file is an XML file that contains informa-
tion about the features of the application. The Tizen platform
supports the configuration file as defined in the W3C widget
specification and adds some Tizen-specific extensions.
The next part of the config.xml file defines the widget ele-
ment and its attributes:
<widget xmlns=”http://www.w3.org/ns/widgets”
xmlns:tizen=”http://tizen.org/ns/widgets” id=”http://
yourdomain/SysteminfoSample” version=”0.1.7”
viewmodes=”maximized”>
</widget>
The namespace declaration will be the same for all Tizen web
apps. It just specifies that the app is a W3C format widget that
uses the Tizen-specific extensions.
<content src=”index.html”/>
<icon src=”icon.png”/>
<name>SysteminfoSample</name>
<tizen:privilege
name=”http://tizen.org/privilege/application.read”/>
<tizen:privilege
name=”http://tizen.org/privilege/systeminfo”/>
<tizen:application id=”LCj1zMvDil.SysteminfoSample”
package=”LCj1zMvDil” required_version=”2.1”/>
Overview
In the Overview tab, you can enter general information about
your application.
Chapter 4: Piecing Together the Application Jigsaw 53
The items shown in Table 4-1 are the attributes that you can
set through the Overview tab in the Configuration Editor.
Widget
In the Widget tab, you can enter specific information about
your application.
The items shown in Table 4-2 and Table 4-3 are the attributes
that you can set through the Widget tab in the Configuration
Editor.
54 Part II: Getting Practical
Features
In the Features tab, you can declare all the mandatory hard-
ware and software components that are required by your
application. This information will be used by the Tizen appli-
cation store to filter applications, ensuring that only those
applications which are compatible with a user’s device are
shown.
After you select the new privileges, click the Finish button.
After you finish making changes to the configuration file,
choose File➪Save or close the config.xml window and click
Yes when you’re prompted to save your changes.
Access
The Tizen platform supports WARP, the W3C Access Request
Policy. So by default, applications are restricted from access-
ing network resources. If your application needs to access any
network resources, you must add them in the config.xml file.
56 Part II: Getting Practical
Localization
The Tizen platform supports localization of selected elements
in the config.xml file, including the application name and
description.
Figure 4-5: Locales. Add any new locales you want to support.
Chapter 4: Piecing Together the Application Jigsaw 57
2. To do so, choose the required locales from the
Available locales list and click the Add button to add
them to the Selected locales list.
3. Click OK to return to the Localization window,
shown in Figure 4-6.
Preferences
A preference is a persistently stored name-value pair that is
associated with the application. You usually use a preference
58 Part II: Getting Practical
Tizen
In the Tizen tab, you can enter any Tizen-specific information
about your application. This information includes the applica-
tion’s id, the minimum version of the APIs that the application
supports, the location of the start file if hosted on an external
server, settings such as screen orientation, support for con-
text menus, background support, encryption and installation
location, and any app control information.
Table 4-4 shows the attributes that you can set in the Tizen
tab if your application provides an application control for
other applications to use.
Source
The Source tab shows the XML content of the config.xml
file. You can use this tab to view the values you’ve set up
using the other configuration tabs. You can also manually edit
the file.
<content src=”my-app.html”/>
JavaScript
If your application requires any interactive elements, you can
program them using JavaScript code. You can include this
code directly in your index.html file within a <script>
element, or you can load it from an external JavaScript file.
The New Project wizard provided in the IDE creates a default
external script file called main.js for you to add to your
JavaScript code.
<script src=”js/main.js”></script>
Style sheet
Generally, your index.html file should contain only the
basic content and structure of your application, with any style
and presentation information contained within style sheets.
The New Project wizard provided in the IDE creates a default
style sheet called style.css, which you can use to apply
styles and presentation information to the elements used in
your application.
You can preview the look and feel of any style elements using
the CSS Preview tool, as described in Chapter 3.
Application icon
The icon.png file is the application’s default icon file and
should contain a logo or some other graphical representation
of the application.
The use of this icon file depends on the Tizen device you’re
developing for, but it generally appears in the application
menu screen.
Author signature
An author can digitally sign any application to ensure its
integrity. This signature file, which cryptographically covers
all nonsignature files within the application package, is the
author signature.
Chapter 4: Piecing Together the Application Jigsaw 61
This file isn’t mandatory in the package, but if the application
is signed by the author, only one author-signature.xml
file can exist.
Check out the SDK Help for more details about creating an
author signature.
Distributor signature
A distributor can also sign an application to ensure its integ-
rity. This signature file, which cryptographically covers all
nonsignature files and the author signature, if it exists, is the
distributor signature.
This file isn’t mandatory in the package. The package can con-
tain more than one distributor signature, so the naming con-
vention is signature1.xml, signature2.xml, and so on.
Check out the SDK Help for more details about creating a dis-
tributor signature.
Third-party source
code or libraries
Sometimes you may want or need to use external libraries to
implement UI controls or functionality that isn’t a standard
part of the Tizen platform. Using third-party libraries is a
really simple way to reuse existing technology and implement
advanced features in your application.
After you add the libraries to the project and load them in the
start file, you can use them in your application code.
<script src=”js/jquery-1.7.min.js”></script>
<script src=”js/jquery-ui-1.8.12.custom.min.js”></script>
<script src=”js/wijmo/jquery.wijmo.wijutil.min.js” type=”text/
javascript”></script>
<script src=”js/wijmo/jquery.wijmo.wijtooltip.min.js”
type=”text/javascript”></script>
Chapter 4: Piecing Together the Application Jigsaw 63
<script src=”js/wijmo/jquery.wijmo.wijprogressbar.min.js”
type=”text/javascript”></script>
<script src=”js/wijmo/jquery.wijmo.wijexpander.min.js”
type=”text/javascript”></script>
<script src=”js/main.js”></script>
Make sure that you load your JavaScript files in the order
dictated by any dependencies. For example, in this code, the
main.js file is loaded last because it’s dependent on features
provided in the wijmo libraries.
Example 1: A 5-minute
application
A simple Tizen web application is a package that contains
only a start file and a configuration file. In this example, we
show you how to quickly create a simple web application to
run on your mobile device.
When you save your changes, the IDE will verify that the
config.xml file is valid. If any errors occur, the IDE displays
a warning dialog box.
<title></title>
<script type=”text/javascript”>
window.location=”http://m.foodnetwork.com”;
</script>
</head>
<body></body>
</html>
Example 2: Something a
bit more complicated
In this example, we introduce the use of JavaScript, CSS, and
Tizen APIs in a web application. Rather than showing you a
step-by-step guide to creating this more complicated app, we
look at the default Systeminfo sample application provided in
the SDK.
First, you need to build and run the Systeminfo app from the
Tizen SDK. You can find detailed instructions in the Chapter 3.
Chapter 4: Piecing Together the Application Jigsaw 67
If you already know your way around, just choose File➪New➪
Tizen Web Project from the menu. Then choose Systeminfo
from the list of samples and build and run the app in the
Simulator or Emulator. The opening screen is shown in
Figure 4-8.
<tizen:privilege
name=”http://tizen.org/privilege/application.read”/>
<tizen:privilege
name=”http://tizen.org/privilege/systeminfo”/>
tizen.systeminfo.getPropertyValue(“BATTERY”,
onBatterySucess, onError);
Looking at index.html
At the beginning of the index.html file is the head section of
the document. This section contains elements for defining the
character set and an application description. This section is
also where any JavaScript files and style sheets are loaded.
<head>
<meta charset=”utf-8”/>
<meta name=”description” content=”Systeminfo API Tutorial”/>
<title>Systeminfo</title>
<script src=”tizen-web-ui-fw/latest/js/jquery.js”></script>
<script src=”./js/config.js”></script>
Chapter 4: Piecing Together the Application Jigsaw 69
<script src=”tizen-web-ui-fw/latest/js/tizen-webui-fw-libs.
js”></script>
<script src=”tizen-web-ui-fw/latest/js/tizen-web-ui-fw.
js” data-framework-viewportscale=”false”></script>
<script type=”text/javascript” src=”./js/main.js”></script>
The first page, with the id main, contains text in the header
area, a list element in the content area, and control bar ele-
ment in the footer area:
<div data-role=”content”>
<ul data-role=”listview” id=”info-list”>
</ul>
</div>
<div data-role=”footer” data-position=”fixed”>
</div>
</div>
You can also bind any other actions to events during initiali-
sation in the same way. In this sample application, all the click
events for the items in the list elements are implemented in
this way:
$(“#display-info”).bind(“vclick”, function() {
getSystemProperty(“DISPLAY”, onDisplaySuccess);
return false;
});
li>label {
color:#646464;
}
You can modify style and layout attributes and preview them
immediately using the CSS Preview feature provided by the
IDE, as shown in Chapter 3.
The Tizen SDK includes a set of tools to help you with testing
and debugging throughout your development process. The
Simulator and Emulator let you test your application before
you run it on a device, while the Remote Web Inspector
helps you track down the bugs that creep into even the most
carefully written project.
This chapter refers to the tools included with the 2.1 Magnolia
release of the Tizen SDK.
74 Part II: Getting Practical
In the Simulator shipped with the Tizen 2.1 release, the imple-
mentation of some of the APIs may be incomplete, check the
Tizen 2.1 Release Notes for more information.
You can also control the screen size and pixel density of
the Emulator image, inject events into your application, and
create multiple Emulator images, all of which help ensure
your app is running smoothly before you run it on a real
device.
While your app is being installed on the Emulator, you can see
the status of the operation in the Progress panel.
In Version 2.1 of the Tizen SDK, the Event Injector can simu-
late device, location, NFC, sensor, and telephony events.
Figure 5-9 shows the Event Injector window.
Chapter 5: Testing and Debugging 81
You can use both the Remote Web Inspector and the Simulator
Web Inspector to debug JavaScript and inspect the Document
Object Model (DOM), CSS, and resources. It also provides profil-
ing based tools such as stack analysis and storage usage analysis.
The key bindings of the Web Inspector conflict with the key
bindings of Eclipse, with Eclipse taking precedence. So if you
want to use the Web Inspector shortcut keys, you need to
unmap the Eclipse key bindings. You can find more informa-
tion by searching for key bindings in the SDK Help.
86 Part II: Getting Practical
Debugging JavaScript
Note: This information is relevant for whichever debugging
environment you’re using.
You can use SDB with either the Emulator or a Tizen device.
To use SDB with a Tizen device, you must set the device to
SDB mode. You can set this mode from the device by choos-
ing Settings➪More System Settings➪Developer Options from
the menu and enabling the USB Debugging mode
In the Emulator, you can also open an SDB shell from the
Emulator configuration menu (refer to Figure 5-4).
sdb devices
Table 5-2 shows the options that you can use to direct the
commands to the required device or Emulator instance.
Standards
Another good thing about the web technology is that it’s
open and standards driven. The World Wide Web Consortium
(W3C) is the main body that drives these standards – for
example, the device APIs on mobile. But other organisations,
such as the GSM Association (GSMA), publish requirements
and APIs for web apps.
Distribution
The final part of web app landscape is the distribution chan-
nel, including the app stores in which you sell your web apps.
The distribution channel is the most important part of the
ecosystem because it’s how you’ll start making money from
your app. However, supporting multiple stores on multiple
platforms can also become complicated.
Some stores, such as the Chrome Web Store and the Mozilla
Marketplace, accept stand-alone web apps, but use different
packaging formats. The Chrome store requires web apps to
be packaged as .crx files, while Mozilla Marketplace requires
.xpi packages. Other stores, including the Apple iOS App
Store and Google Play, accept only native applications, so
you’ll have to wrap your web code in a native app in order to
gain entry to these stores.
.stage {
width: 1024px;
height: 600px;
position: relative;
overflow: hidden;
-webkit-transform: translateZ(0);
}
Our updated CSS code for a fluid layout of the Aura app looks
like this:
.stage {
width: 100%;
position: relative;
overflow: hidden;
-webkit-transform: translateZ(0);
}
100 Part II: Getting Practical
The media query in CSS3 allows you to detect the screen size
of device and adjust the style accordingly:
Chapter 6: Porting Your Web App to Tizen 101
@media screen and (max-width: 1024px){
.stage {
width: 1024px;
height: 600px;
position: relative;
overflow: hidden;
-webkit-transform: translateZ(0);
}
}
@media screen and (max-width: 1280px){
.stage {
width: 100%;
position: relative;
overflow: hidden;
-webkit-transform: translateZ(0);
}
}
//rope.js
...
var gravity = new Vector(0, 9.8);
var acc = new Vector(0, 0);
...
window.addEventListener(“devicemotion”, function(event) {
acc.x = event.accelerationIncludingGravity.x;
acc.y = -event.accelerationIncludingGravity.y;
}, true);
...
function draw(){
...
if(acc.x * acc.x + acc.y * acc.y > 9) {
var accAngle = Math.atan2(acc.y, acc.x);
gravity.x = Math.cos(accAngle) * 9.82;
gravity.y = Math.sin(accAngle) * 9.82;
} else {
gravity.x = 0;
gravity.y = 9.82;
}
...
}
Chapter 6: Porting Your Web App to Tizen 103
The variable accAngle represents the angle between the
rope and the x axis. To fix the cloud problem on a Tizen refer-
ence device that is implemented according to the W3C stan-
dards, you have to change one line of the JavaScript to this:
function getVibrationFunc() {
var vibrate = function() {};
if (navigator.vibrate) {
vibrate = function(p) {navigator.vibrate(p);};
} else if (navigator.mozVibrate) {
vibrate = function(p) {navigator.mozVibrate(p);};
} else if (navigator.webkitVibrate) {
vibrate = function(p) {navigator.webkitVibrate(p);};
}
return vibrate;
}
106 Part II: Getting Practical
Building Your UI
In This Chapter
▶ Introducing jQuery Mobile
▶ Using basic controls
▶ Taking advantage of UI building tools
▶ Creating advanced UIs
This chapter puts you well on the way to creating a great UI.
We leave the rest of your killer app to you.
110 Part III: Tizen in Detail
Page structure
To use jQuery Mobile, you just need to create an HTML5 page.
The page must start with an HTML5 doctype to take advan-
tage of jQuery Mobile library. In the head tag, you can specify
a meta data tag viewport for the initial scale and screen size
of your mobile web app. Under the body tag, you can create a
single or multiple jQuery Mobile page by using data-role=
”page” inside the div. This creates a view that uses up to
the full screen of your mobile device if the status bar area is
hidden.
Inside the page div, you can also add the header, content,
and footer sections, as shown in Figure 7-1.
Chapter 7: Building Your UI 111
Events
jQuery Mobile also provides various types of custom events
to create useful hooks between the UI and your JavaScript
code. These events cohabit nicely with the native events of
the platform. For example, touch-related events include tap,
taphold, swipe, swipeleft, swiperight, and pinch.
To assign the event to your UI, you just use the following
method:
Design: Select the Design tab while you’re building the UI.
✓
Preview: Select Preview to see the result as your design
✓
develops.
Chapter 7: Building Your UI 115
After you drag the UI widget to the page, you can adjust its
default properties from the Properties View. In the example
shown in the Figure 7-5, we change the text of the List Item
from ‘In The Gym’ to the more realistic ‘In The Kitchen’.
Implementing events in
the UI builder
The UI Builder can also generate code to handle the events
supported by Tizen’s predefined UI widgets. For example, a
list item supports the SwipeLeft event, and you can generate
the skeleton JavaScript code to handle this event from within
UI Builder.
Highlight the list item in the UI Builder and click the Event
Handler tab in the Property Panel. You see a drop-down
menu, which lists all the events the List Item widget sup-
ports. Choose SwipeLeft to assign this event to the List
Item and click the triangle that appears below the menu, as
shown in Figure 7-6.
Chapter 7: Building Your UI 117
/**
* @param {Object} event
* @base _page1_page
* @returns {Boolean}
*/
_page1_page.prototype.listitem3_onswipeleft = function(event) {
};
https://github.com/botelho/flipboard-layout
f-page is for the pages between the cover and back that
✓
you need to flip.
f-cover is the cover page.
✓
f-cover-back is the back of the cover.
✓
For the page layout, the box class presents the content of the
page – for example, the images and articles. These boxes each
need an additional “height” and “width” class to give the
element percentage-based dimensions.
Chapter 7: Building Your UI 119
A sample HTML page looks like this:
<div class=”f-page”>
<div class=”f-title”>
<!-- ... -->
</div>
<div class=”box w-50 h-100”>
<div class=”img-cont img-1”></div>
<h3>Headline <span>Published May 7, 2012</span></h3>
<p>Some text</p>
</div>
<div class=”box w-50 h-100”>
<!-- ... -->
</div>
</div>
<div class=”f-page”>
<!-- ... -->
</div>
Figures 7-7 and 7-8 show the final code running on the Tizen
development device. The cover page contains the image and
flip text.
Taking Advantage of
Location-Based Services
In This Chapter
▶ Displaying a map
▶ Converting between addresses and co-ordinates
▶ Dropping a pin on a map
Displaying a Map
While you can use any of the JavaScript mapping APIs for dis-
playing a map in your Tizen web app, we use the Google Maps
API for this example. Here’s how you display a map based on
your current location:
Figure 8-1: Displaying a map in the Tizen Emulator using the Google map
APIs.
https://developers.google.com/maps/documentation/
javascript/tutorial
You also need to include the Map API URL in your Tizen
project config.xml file because it’s an external resource
that is accessed from your Tizen app. See Chapter 4 for
more details about how to add a URL to the access section
of config.xml.
Chapter 8: Taking Advantage of Location-Based Services 125
Finding an Address
Displaying a map given a longitude and latitude is relatively
simple, but sometimes all you have is a human-readable address.
Converting this address into a longitude and latitude is known
as geocoding, while the process of translating coordinates to a
human-readable form is referred to as reverse geocoding.
An array of GeocoderAddressComponents
✓
A string containing the human-readable address of this
✓
location
A GeocoderGeometry object
✓
An array of strings denoting the type of the returned
✓
geocoded element.
Google also provides the Geocoding web service. You can use
an HTTP request to access the geocoder directly. This service
is designed for geocoding static addresses for placement of
app content on a map. It’s not designed to respond in real
time to user input.
https://developers.google.com/maps/documentation/
javascript/3.exp/reference#Geocoder
marker.setMap(map)
128 Part III: Tizen in Detail
Chapter 9
Discovering Content
The Tizen Content API provides functionality for searching
for content stored either locally on your device or an external
memory card.
Content
A content item is an object that contains the attributes of a
single piece of content, rather than the content itself. You use
the Content interface to access an item’s attributes.
Getting permission
Because content is private data, the Tizen platform restricts
access to this data using different permission levels.
Permissions are set in the config.xml file. (See Chapter 4 for
more on permissions.)
Adding http://tizen.org/privilege/content.
✓
read to your permissions gives you access to the
methods in the API for searching for content, and
watching for added, updated or removed content.
Adding http://tizen.org/privilege/content.
✓
write to your permissions gives you access to the
methods in the API for updating the attributes of items.
Before you start to use the Content APIs, you must set the
correct permission in your application’s config.xml file.
In this example, you need to set the http://tizen.org/
privilege/content.read permission level.
Then you can use the find() method to search for the first
ten items that match your search requirements:
function audioFoundCb(content) {
// List the audio files found
for (var i=0; i<content.length; i++) {
console.log(“Location: “ + content[i].contentURI
+ “ Track title: “+ content[i].title);
}
}
function errCb(err) {
console.log(“Error: “ + err.message);
}
134 Part III: Tizen in Detail
Launching an application
The application object provides a launchAppControl()
method, which your app calls to launch the service defined in
the Application Control object.
You don’t need to set a URI, category or any data for this
camera Application Control request.
The success callback tells your app that the camera applica-
tion has been launched successfully:
function successCb() {
console.log(“Camera application launched successfully”);
}
Chapter 9: Working with Multimedia 137
If problems occur with the launch request, if the app can’t be
found, or if it fails for some other reason, it will be reported to
the error callback:
function errCb(err) {
console.log(“Error: “ + err.message);
}
You can also create your own custom controls for an audio
player. In this case, you use the following code to add an
audio element to your app:
If you’re not using the default controls, you need to add the
buttons and other controls for your custom playback UI.
<audio id=”audioPlayer”></audio>
<div id=”playButton”>
<button onclick=”playAudio();”>Play</button>
</div>
function playAudio() {
var audioPlayer = document.querySelector(‘#audioPlayer’);
audioPlayer.src = “audio/test.mp3”;
audioPlayer.play();
}
When the user clicks the Play button, the audio file is loaded
into the audio element and starts playing.
140 Part III: Tizen in Detail
Another feature you can use is the poster attribute. You can
use this attribute to set an image to be displayed while no
video is available. You can create the video element, with the
poster attribute and a button, in your start file:
function playVideo() {
var videoPlayer = document.querySelector(‘#videoPlayer’);
videoPlayer.src = “/opt/media/Videos/Helicopter.mp4”
videoPlayer.play();
}
Chapter 9: Working with Multimedia 141
Until the user starts playing the video, the Helicopter.jpg
image appears in the video player.
Multimedia Streaming
In a Tizen web application, it’s possible to access multime-
dia streams from local devices, such as the video camera
and microphone. This functionality is based on the W3C
getUserMedia specification.
webkitGetUserMedia
The webkitGetUserMedia API is the WebKit implementation
of the getUserMedia specification. It’s used to create a local
media stream from either the device’s camera, microphone,
or both.
For more information about media streams and how you can
use them in your web application, see the W3C WebRTC spec-
ification at http://dev.w3.org/2011/webrtc/editor/
getusermedia-20111130.html.
navigator.webkitGetUserMedia({video:true, audio:true},
playStream, errCb);
function playStream(stream) {
var videoPlayer = document.querySelector(‘#videoPlayer’);
videoPlayer.src = window.webkitURL.createObjectURL(stream);
localMediaStream = stream;
}
If you store a reference to the local media stream, you can use
it to stop the stream from the camera:
localMediaStream.stop();
function errCb(err) {
console.log(‘Error: ‘ + err.message);
}
144 Part III: Tizen in Detail
Chapter 10
Introducing NFC
Near Field Communication (NFC) isn’t a new technology.
You can trace its roots back to 2004 when Nokia, Philips,
and Sony founded the NFC Forum. The technology is based
on the Radio-Frequency Identification (RFID) standards. The
difference is that RFID is a passive information tag and can’t
process the information sent from other devices, while NFC
enabled devices can do more, such as card simulation and
peer-to-peer communication. That’s why NFC needs the
processing power of a smart device.
Close proximity
✓
Low speed
✓
No setup required
✓
No battery required for a passive tag
✓
But NFC has uses far beyond mobile payments. For example,
the Android Beam feature, introduced in the Ice Cream
Sandwich (4.0) release, allows users to exchange small
amount of information, such as web URLs, between phones
just by touching them together. Several manufacturers have
introduced NFC-enabled speaker systems, which allow you to
start streaming audio from a device with a single touch.
Chapter 10: Using Hardware in Tizen 147
These examples are just the tip of the iceberg, NFC has many
other uses. According to the NFC Forum specifications, NFC
devices can be operated in three different modes, shown in
Figure 10-1:
To use NFC features in your app, the first thing you need to
do is add the required permissions to the config.xml file. For
example, if you use the tag feature, add
nfcAdapter.setPowered(
true,
function(){
//SuccessCallback
},
function(){
//ErrorCallback
//e.g. ServiceNotAvailableError: NFC service is busy
}
);
nfcAdapter.setTagListener(
function(){
//handle the onattach and ondetach events
}
);
nfcAdapter.setPeerListener(
function(){
//handle onattach or ondetach events
}
);
Reading a tag
When a tag is detected by the device, it calls the tag detected
callback function. At this point, you can carry out an operation
on the detected tag. For example, to read the tag, you use the
readNDEF method.
Writing a tag
The implementation of writing a tag is very similar to the code
required to read a tag. After the NFCTagDetectCallback is
triggered, you can use the writeNDEF() method of the tag
object to write information to the tag:
var onTagDetect = {
onattach: function(tag){
if(tag.isSupportedNDEF){
tag.writeNDEF(
ndefMessage,
function(){
//handle success case
},
function(){
//handle failure case
}
);
}
}
};
After you create the NDEF message, you can pass it to the
writeNDEF method.
Chapter 10: Using Hardware in Tizen 153
Using NFC in peer-to-peer mode
The last NFC use case you can implement on Tizen is the peer-
to-peer mode. Peer-to-peer mode always involves two or more
NFC devices (peers), and it’s a two-way communication. Tizen
provides both send and receive NDEF message functionality
for the peer-to-peer mode. One peer can send a NDEF message
proactively, but can only receive an incoming NDEF message if
the receive listener is set.
peer.setReceiveNDEFListener({
onsuccess: function(message){
for(var i = 0; i < message.recordCount;
i++){
switch(message.records[i].tnf ){
case tizen.nfc.NFC_RECORD_TNF_
EMPTY:
}
}
}
});
}
// read the record
else{
//peer not connected
}
},
ondetach:function(){
//peer lost
}
});
window.addEventListener(“deviceorientation”, function(data){
this.direction = data.alpha;
this.tiltFB = data.beta;
this.tiltLR = data.gamma;
}, true);
http://www.w3.org/TR/DOM-Level-2-Events/events.
html
After you have the orientation data, you can use it to control
the UI element – for example, an image rotating according to
the device orientation using CSS animation:
tizen.systeminfo.getPropertyValue
(“DEVICE_ORIENTATION”, onOrientationSuccess, onError);
function onOrientationSuccess(orientation) {
To get the motion data, you need to add the device motion
event listener to your window object:
window.addEventListener(“devicemotion”, function(data){
var acceleration = data.accelerationIncludingGravity;
function motionHandler(data){
var acceleration = data.acceleration;
}
navigator.vibrate(1000)
Messaging
In This Chapter
▶ Creating and sending messages
▶ Searching for messages
▶ Building a User Interface for message searching
I t’s often said that the smarter smartphones get, the less
they are used for actual voice calls. Walk around any town,
and you’re likely to see smartphone users deep in concentra-
tion, tapping at their screens as they send SMS, email, and
other forms of messages to friends and colleagues who may
actually be standing right next to them.
These days, people like to message more than talk, and the
Messaging API is a vital part of any smart device. The W3C
specifications don’t contain any Messaging APIs, and Tizen
fills that gap by providing its own Messaging API.
Message service
In order to use messaging functionality in your application,
you first have to retrieve the message service for the required
service type. A message service is the interface that gives you
access to the message creation, sending, and reading capabili-
ties of the platform. Email, SMS, and MMS messaging service
types share a common interface.
tizen.messaging.getMessageServices(“messaging.email”,
msgServiceCb, errCb);
Message structure
A message consists of a Message object, which contains the
attributes of the message, a MessageBody object, and option-
ally any MessageAttachment objects.
Chapter 11: Messaging 161
Message
The Message interface describes the properties of a message,
such as the message recipients, subject, sender, type, and so
on. (The message attributes and the service types they apply
to are described in the SDK Help documentation.)
Once created, this message can either be sent using the SMS
message service or stored as a draft in the filesystem using
the MessageStorage interface.
MessageBody
The MessageBody object describes the body of a message
with the following attributes: an id, the loaded status, a plain
text part, an html part, and inline attachments for email
messages.
MessageAttachment
The MessageAttachment object describes the content and
properties of a message attachment with the following
attributes: an attachment id, a message id, the MIME type, and
the file path of the downloaded content.
Message storage
Each message service object in the system has its own mes-
sage storage object. This provides an interface to query,
update, and delete messages and subscribe to any changes in
the message storage object. It also provides functionality to
find specific messages, conversations, or message folders.
Getting Permission
Because messages are private data, the Tizen platform
restricts access to this data using different permission levels.
Permissions are set in the config.xml file and are explained
in detail in Chapter 4. Here are the ones related to messaging
content:
Adding http://tizen.org/privilege/messaging.
✓
read to your permissions lets you find and watch
messages, conversations and folders from the message
storage.
Adding http://tizen.org/privilege/messaging.
✓
write to your permissions lets you add, remove and
update messages in the message storage, synchronize
content and folders with external mail servers, and send
messages.
<div data-role=”content”>
<ul id=”msgList” data-role=”listview”></ul>
</div><!-- /content -->
Initialisation
This example uses the Tizen UI Framework, which is based on
jQuery Mobile, and applications are developed using a page
structure. Any initialisation code that needs to be run when
the page is loaded should be executed when the pageinit
event is fired.
To search for all the SMS messages on the device, you need to
use the message storage object’s findMessages() method
with a tizen filter. In this example, you should create an attri-
bute filter to narrow down your search to SMS messages only,
as shown in Listing 11-3.
function errCb(err) {
console.log(“Error: “ + err.message);
}
function msgServiceCb(services) {
msgService = services[0];
msgStore = msgService.messageStorage;
var typeFilter = new tizen.AttributeFilter(“type”,
“EXACTLY”, “messaging.sms”);
msgStore.findMessages(typeFilter, msgFoundCb, errCb);
}
The first action is to clear any previous list data using the
remove() method, and then you can append the new list
data. To differentiate between the incoming and outgoing
messages, you can check the from message attribute, which
will be empty for outgoing messages.
To create each list item, you need to append a list item ele-
ment with the relevant bubble class type to the msgList list
element. In this example, the body text and timestamp of the
message is added to the list item. After the list has been popu-
lated, you tell the framework to update the list using the List
View’s refresh() method.
For this, you use the search input element, displayed in the
header section of the page, to accept user input and the mes-
sage storage object’s findMessages() method to find the
messages.
When the user enters a character in the search bar, the input
element’s input event is triggered.
In this example, both the input and change events are han-
dled by the updateList() method.
function findString(str) {
var typeFilter = new tizen.AttributeFilter(“type”,
“EXACTLY”, “messaging.sms”);
var strFilter = new tizen.AttributeFilter(“body”,
“CONTAINS”, str);
function updateList() {
var input = $(“#searchBox”).val();
if(input != prevString) {
findString(input);
prevString = input;
}
}
Chapter 12
Address books
It doesn’t matter how many address books you have or where
they are stored (for example, on your device or SIM card) –
you use the same ContactManager interface to retrieve
them.
For example, to retrieve the unified address book, you use the
following in your code:
Contacts
A contact is a set of information that contains all the data you
hold about a specific person or organisation, including name,
phone numbers, and email addresses.
Getting Permission
Because contacts and address books contain private and
sensitive data, the Tizen platform restricts access to this data
using different permission levels. Permissions are set in the
config.xml file and are explained in detail in Chapter 4. Here
are the ones related to contacts:
Adding http://tizen.org/privilege/contact.read
✓
to your permissions gives you access to the methods in the
API for retrieving address books, getting/finding/watching
persons or contacts, and retrieving contact groups.
Adding http://tizen.org/privilege/contact.
✓
write to your permissions gives you access to the
methods in the API for adding, modifying and deleting
persons, contacts or groups, and linking or unlinking a
contact to a person.
Adding a contact
In this example, we show you how to add a single contact to
an address book.
tizen.contact.getAddressBooks(addContactCB, errorCB);
After you create your contact, you can then add it to the
address book:
addressBook.add(contact);
Retrieving a contact
In this example, we show you how to get a specific contact
from the address book. You can get a contact in two ways:
using the contact reference or searching with filters.
console.log(“Name: “ + contact.name.displayName
+ “ Email: “ + contact.emails[0].email
+ “ Tel: “ + contact.phoneNumbers[0].number);
function successCB(contacts) {
console.log(‘Number of contacts found: ‘
+ contacts.length);
for (var i=0; i<contacts.length; i++){
console.log(“Name: “
+ contacts[i].name.firstName + “ “
+ contacts[i].name.lastName
+ “ Email: “
+ contacts[i].emails[0].email
+ “ Tel: “
+ contacts[i].phoneNumbers[0].number);
}
}
function errorCB(err) {
console.log(‘Error: ‘ + err.message);
}
Deleting contacts
The AddressBook object contains methods that allow you
to update or delete multiple contacts in a batch operation.
These operations are asynchronous, so success or failure of
the operation is indicated by the invocation of the appropri-
ate callback method.
To get all the contacts in the address book, you can use the
find() method:
addressBook.find(successCB, errorCB);
function successCB(contacts) {
if (contacts.length > 0) {
var contactIds = [];
for(var i=0; i<contacts.length; i++) {
contactIds[i]=contacts[i].id;
}
addressBook.removeBatch(contactIds,
deleteSuccessCB, errorCB);
}
}
Exporting a contact
In this example, we show you how to export a contact in the
vCard format. The Contact API supports vCard version 3.0.
console.log(vCard);
Getting Organized
with Calendars
In This Chapter
▶ Using the Calendar API
▶ Creating and retrieving tasks
▶ Adding reminders to a task
CalendarManager
This calendar object implements the CalendarManager
interface, which provides methods to access the calendars
stored in the system. The same interface is used to access
both event calendars and task calendars.
Calendar
The Calendar interface provides the methods to get, find,
add, update, delete, and watch items within the calendar.
Access to some of these methods is restricted depending on
which permission you’ve set for your application.
CalendarItem
CalendarItem is an interface from which both the
CalendarEvent and CalendarTask interfaces are derived.
The CalendarItem interface defines the functions and attri-
butes that are common to both events and tasks.
Chapter 13: Getting Organized with Calendars 183
Supported properties
The following properties are The calendar event type
supported for all calendar item supports the following additional
types: i d , c a l e n d a r I d , properties: i s D e t a c h e d ,
lastModificationDate, endDate, availability, and
description, summary, recurrenceRule.
isAllDay, startDate,
The calendar task type supports
duration, location,
the following additional properties:
geolocation, organizer,
dueDate, completedDate, and
visibility, status,
progress.
priority, alarms,
categories, and attendees.
Getting Permission
In order to use any of the Calendar API features, the relevant
privilege must be set in the application’s config.xml file.
(See Chapter 4 for more information about the config.xml
file.)
Adding http://tizen.org/privilege/calendar.
✓
read to your permissions gives you access to the meth-
ods in the API for retrieving calendars, getting/finding/
watching items, converting items to strings, cloning
items, and expanding recurrences.
Adding http://tizen.org/privilege/calendar.
✓
write to your permissions gives you access to the meth-
ods in the API for adding, modifying and deleting events
or tasks.
184 Part III: Tizen in Detail
Creating a Task
In this example, we add a single task to the default task calendar.
You can specify the initial values for a new task in two ways:
using a CalendarTaskInit object or from a string format-
ted in the iCalendar todo format VTODO. Look at the “Support
for iCalendar” sidebar in this chapter for more details about
Tizen’s support for this standard.
After you create your task, you can then add it to the calendar:
calendar.add(task);
Chapter 13: Getting Organized with Calendars 185
A new batch
In Chapter 12, we explain and removing events or tasks, into
that operations that involve batch operations.
making changes to the address
These functions are asynchronous,
book can be combined into
so you supply a callback function
batch operations to improve
that will be invoked when the
performance. You can also use
operation is complete. Your app
the addBatch, updateBatch,
continues processing and stays
and removeBatch functions to
responsive without having to wait
combine multiple changes to the
for the changes to the calendar to be
calendar, such as adding, updating,
completed.
Retrieving Tasks
You can get a task from the calendar in two ways:
The task id is the identifier that was assigned to the task when
it was added to the calendar.
If you know the task id, you can retrieve the task from the cal-
endar using the get() method:
var taskId;
taskId = ... // gets a valid Task ID from somewhere
var calendar = tizen.calendar.getDefaultCalendar(“TASK”);
// Retrieve task
var task = calendar.get(taskId);
If you don’t know the task id or you want to search for mul-
tiple tasks, you can use a filter with the find() method.
The tizen object provides several filter options that you can
use when searching for a task.
186 Part III: Tizen in Detail
function successCB(tasks) {
console.log(‘Number of tasks found: ‘
+ tasks.length);
for (var i=0; i<tasks.length; i++){
console.log(“Description: “
+ tasks[i].description
+ “ Summary: “
+ tasks[i].summary
+ “ Due Date: “
+ tasks[i].dueDate);
}
}
function errorCB(err) {
console.log(‘Error: ‘ + err.message);
}
Chapter 13: Getting Organized with Calendars 187
Setting an Alarm
In this example, we show you how to retrieve a task item from
the calendar, add a reminder alarm to it, and then update the
calendar.
To get a specific task item from the calendar, you can use the
get() method:
After you create your alarm, you can then add it to the task
and update the calendar:
task.alarms = [alarm];
calendar.update(task, false);
If you want to check whether the task has been updated, you
can retrieve the task from the calendar and check the last
ModificationDate attribute or the alarms attribute.
188 Part III: Tizen in Detail
Douglas Crockford’s
JavaScript Lectures
Douglas Crockford is involved in the ongoing development of
JavaScript, was responsible for the JSON (JavaScript Object
Notation) data format and for many popular JavaScript tools.
He’s considered the JavaScript expert; when he speaks, it’s
worth hearing what he has to say. In 2010/11 he presented
a series of lectures on the history of JavaScript, its features
and programming style. You can find these lectures here:
http://yuiblog.com/crockford/
JavaScript Patterns
Object oriented languages such as JavaScript, lend themselves
to the design and use of design patterns – reusable solutions that
can be applied to common coding problems. While JavaScript is
not strongly typed like C++ and Objective-C, it does provide many
object-oriented features such as constructors and inheritance.
JavaScript Libraries
There are thousands of JavaScript libraries out there which you
can use to add features to your app and to save you time. Chapter
4 explains how to use external JavaScript libraries in your code.
You’ll find that all these sites link to lots more information
sources, but that’s why it’s fun to explore.
Smashing Magazine
A special mention to Smashing Magazine (and not just
because we like the name). Their website at www.smashing
magazine.com/ contains hundreds of articles on web design
and development.
Type Tizen into the search bar and you’ll find videos of presen-
tations from various conferences (including some featuring the
authors of this book!) and up-to-date Tizen news and demos.
And . . . You
Of course the most important resource is you. The best way
to learn a new skill is by doing it. We hope this book encour-
ages you to write a web page, start tweaking some JavaScript
examples, create a Tizen web app based on the examples and
start developing the next great killer app.
Chapter 15
Tizen Is Consistent
These device APIs use patterns that will be familiar to you
if you’re used to libraries such as jQuery. If you’re already
a web developer, it won’t take you long to become a Tizen
expert.
More personally:
From Cheng: To Mom, Dad, Mary, Luke, and Tong with love.