Documentos de Académico
Documentos de Profesional
Documentos de Cultura
FOR
DUMmIES
01_9781118539538-ffirs.indd i
1/18/13 1:28 PM
01_9781118539538-ffirs.indd ii
1/18/13 1:28 PM
Table of Contents
Introduction....................................................... 1
About This Book ........................................................................ 1
Conventions Used in This Book ............................................... 1
Foolish Assumptions ................................................................. 2
How This Book Is Organized .................................................... 2
Part I: Introducing Tizen ................................................. 2
Part II: Getting Practical .................................................. 3
Part III: Tizen in Detail ..................................................... 3
Part IV: The Part of Tens................................................. 3
Icons Used in This Book ............................................................ 3
Where to Go from Here ............................................................. 4
02_9781118539538-ftoc.indd iii
1/18/13 1:28 PM
iv
02_9781118539538-ftoc.indd iv
1/18/13 1:28 PM
Table of Contents
02_9781118539538-ftoc.indd v
1/18/13 1:28 PM
vi
02_9781118539538-ftoc.indd vi
1/18/13 1:28 PM
Table of Contents
vii
02_9781118539538-ftoc.indd vii
1/18/13 1:28 PM
viii
02_9781118539538-ftoc.indd viii
1/18/13 1:28 PM
ix
Table of Contents
02_9781118539538-ftoc.indd ix
1/18/13 1:28 PM
02_9781118539538-ftoc.indd x
1/18/13 1:28 PM
Introduction
03_9781118539538-intro.indd 1
1/18/13 1:28 PM
03_9781118539538-intro.indd 2
1/18/13 1:28 PM
Introduction
We also give you a tour of the components of the Tizen plaform, explain how web applications fit in and provide you
with a quick summary of the Tizen Device APIs.
03_9781118539538-intro.indd 3
1/18/13 1:28 PM
03_9781118539538-intro.indd 4
1/18/13 1:28 PM
Part I
Introducing Tizen
04_9781118539538-pp01.indd 5
1/18/13 1:29 PM
In this part . . .
04_9781118539538-pp01.indd 6
1/18/13 1:29 PM
Chapter 1
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.
The Linux Foundation announced the Tizen project in September
2011 and the Tizen Association was formed in 2012 to drive
industry engagement and support for the project. Currently,
the main contributors to Tizen are Samsung and Intel, but
with increasing industry support, you can expect more organizations to become active contributors. Currently, the Tizen
Association board has 12 members from different industry
sectors, including many mobile operators.
Tizen has solid open source foundations, and it makes use
of established open source components, such as WebKit,
GStreamer, Xorg, and Connman. If you want to know how
Tizen compares to other open source mobile platforms, see
05_9781118539538-ch01.indd 7
1/18/13 1:30 PM
Focusing on HTML5
Tizens primary focus for application development is HTML5,
which is rapidly emerging as the preferred development environment 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.
At the time of writing, the Tizen 2.0 alpha release includes
APIs only for web app development. So, currently the only
way to create Tizen apps is to use HTML, JavaScript, and
related technologies. Luckily, thats the focus of this book.
The first prerelease version of Tizen emerged blinking into
the spotlight of the developer community in January 2012.
The final 1.0 version, code named Larkspur and including
Linux and Windows versions of the SDK and the Tizen Web
UI framework, was released in May, just before the first Tizen
Developers Conference in San Francisco. At this event, the
attendees were given a reference device, known as the software
development platform (SDP), or lunchbox, as it is nicknamed
due to its less than svelte appearance.
The version of Tizen we used to create this book is 2.0 alpha,
which was released in September 2012.
05_9781118539538-ch01.indd 8
1/18/13 1:30 PM
05_9781118539538-ch01.indd 9
1/18/13 1:30 PM
10
05_9781118539538-ch01.indd 10
1/18/13 1:30 PM
11
Defining open
At any gathering of open source
developers, the one subject guaranteed to cause an argument aside
from which pizza restaurant to order
from is what is the definition of
open source.
In this book, we describe Tizen as
open source because the source
code to the platform is freely available, anyone can download it, and
you can use it for any purpose in any
project. We accept that this may not
meet everyones definition of open
source software, but this is our definition, and were sticking to it.
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 customised user interface, app store, or set of services.
Open source projects also encourage collaboration. Software
engineering is changing, and its a challenge for an individual
or even an organization to build something without using open
source code. Collaborating with the open source community
is a more efficient and cost-effective way of development, and
it generally avoids re-inventing the wheel.
Tizen is innovative
Innovation can come from many sources. It may be an idea
from an individual or an organizations R&D projects, but
most innovation comes from collaboration.
05_9781118539538-ch01.indd 11
1/18/13 1:30 PM
12
Comparing Tizen to
Other Platforms
Tizens openness contrasts with closed, proprietary platforms, such as iOS, Blackberry OS 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 vendors devices.
Of the open source alternatives, WebOS and Firefox OS are
both platforms with potential, but they dont have the same
level of industry support as Tizen.
05_9781118539538-ch01.indd 12
1/18/13 1:30 PM
13
Android is the best known open source platform, but the governance of the platform is arguably not as open, and its standards support isnt as comprehensive as Tizen.
Getting Involved
You can participate and contribute to the Tizen Project at different levels. As described on the Tizen website (www.tizen.
org), you can be a platform contributor, an application developer, a user, or a Tizen product vendor.
At the platform level, the membership for the TSG (for example, groups responsible for areas such as Release Engineering,
Quality Assurance, and Program Management) is invitation
only and will mainly be open to the Tizen vendors. However,
the Community Office, Localization, and some Middleware
groups will be open to participation on a merit basis.
05_9781118539538-ch01.indd 13
1/18/13 1:30 PM
14
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
The Tizen wiki is available for collaborating on documentation
related to the Tizen project:
https://wiki.tizen.org/wiki/Main_Page
If you have any information or tutorials you want to share
with the community, youre free to add them to the wiki.
However, before contributing, you should check the User
Guide and style guides.
05_9781118539538-ch01.indd 14
1/18/13 1:30 PM
15
Forums
Another source of help and information are the forums available on the Tizen developer site:
https://developer.tizen.org/forums
The forums are available to any developer with an account to
ask questions, contribute to discussions, and share information.
Bug tracker
Tizen uses JIRA to track bugs and gather requests for new
features:
https://bugs.tizen.org/jira
Anyone with a tizen.org account can add a new bug, comment
on an existing bug, or even submit a patch to fix a bug.
05_9781118539538-ch01.indd 15
1/18/13 1:30 PM
16
05_9781118539538-ch01.indd 16
1/18/13 1:30 PM
Chapter 2
06_9781118539538-ch02.indd 17
1/18/13 1:30 PM
18
06_9781118539538-ch02.indd 18
1/18/13 1:30 PM
19
The web runtime is also responsible for access control checking. Whenever a web app calls a JavaScript API, the web runtime checks that the app is allowed to access that particular
feature, returning an error if access is denied. This process
provides a high level of runtime security.
Figure 2-1 shows the components of the web runtime. As you
can see from Figure 2-1, the web application talks to the web
runtime, which then communicates with the layer below to
access the features of the device. The web runtime consists
of an installer, runtime core, plugin core, and security components. The following sections look at these areas in more
detail.
Installer
When an application is installed, the Tizen package manager
is called to install the web application. The package manager invokes the web runtimes 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 apps
configuration file, including the app ID, name of the app, and
icon. The apps icon then appears in the menu screen.
When the user uninstalls an app, the app is unregistered from
the web runtime database, and all app resources are removed
from the client.
06_9781118539538-ch02.indd 19
1/18/13 1:30 PM
20
Runtime core
The runtime core is responsible for managing the lifecycle of
an application, including startup, suspend and resume, and
terminate.
When an app launches, the Tizen launchpad executes the
web app process. This creates a new process for the web app
and initialises some of the callbacks that will be invoked for
certain system events. When an app is initially launched, the
runtime will retrieve the web apps start file, usually called
index.html, initialise the web view and load this .html file.
If the app provides a service for example, getting an image from
a web service then this feature will be registered as a service,
using the Image MIME type. When another app requests the
image service, the app will receive the request and handle it.
The Tizen web runtime rendering engine is based on WebKit2.
This is the same WebKit used in the Tizen browser. As a
result, web apps can take advantage of the same HTML5 APIs
and the same 2D and 3D optimisations and CSS3 optimisations
that the built-in browser uses.
Plugin core
The plugin core is what enables the web app to talk to the
device/platform via JavaScript APIs. It communicates with
the JSCore module in the platform layer (refer to Figure 2-1)
and implements on-demand loading of plugins at runtime. The
06_9781118539538-ch02.indd 20
1/18/13 1:30 PM
21
06_9781118539538-ch02.indd 21
1/18/13 1:30 PM
22
Tizen
When a Tizen web app is launched, Tizen examines the apps
configuration file to determine which features are supported.
If the Tizen feature is specified, then a Tizen JavaScript object
is created which can then be used to access the rest of the
device APIs such as Contact, Calendar and NFC. You can find
more about features and the configuration file in Chapter 4.
06_9781118539538-ch02.indd 22
1/18/13 1:30 PM
23
For example, to access the default address book, you use the
following code:
var addressBook = tizen.contact.getDefaultAddressBook();
Alarm
The Alarm API allows you to set an alarm to run an application
at a specified time and launch it if its not already running.
Application
The Application API allows you to retrieve a list of running
applications and launch other apps by using an application
service. 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 service.
Bluetooth
The Bluetooth API provides access to the Bluetooth protocol,
which can be used for transmitting files over short distances
between devices.
06_9781118539538-ch02.indd 23
1/18/13 1:30 PM
24
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.
Call
The Call API provides access to the call history and allows
you to monitor the status of the current call.
Contacts
You use the Contacts API to manage contacts and handle
multiple address books. Chapter 12 explains the Contacts
API in detail.
Download
The Download API, introduced in Tizen 2.0, is used to download files from the Internet and monitor the download status.
Filesystem
The Filesystem API provides access to the devices file system.
The SDK includes more information, including tutorials.
Geocoder
The Geocoder API is responsible for converting geographic
co-ordinates (longitude and latitude) into user-readable
addresses and the other way around. Chapter 8 explains this
API in more detail.
Media Content
The Media Content API lets you search for multimedia content on the device, either stored locally or on a memory card.
Chapter 9 shows you how to use these features.
06_9781118539538-ch02.indd 24
1/18/13 1:30 PM
25
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.
NFC
Near Field Communication (NFC) is used for short range wireless 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. Limited
notification features were implemented in the version of Tizen
available at the time of writing- 2.0 alpha.
Power
Another new API introduced in Tizen API, this provides access
to a devices power state and allows you to control display
dimming and brightness, for example. More information,
including a tutorial are included in the SDK.
06_9781118539538-ch02.indd 25
1/18/13 1:30 PM
26
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.
Time
Provides date and time functions, including working with the
current date and time and locale specific date and time handling. Chapter 13 uses the Time APIs to set the date and time
of calendar tasks.
06_9781118539538-ch02.indd 26
1/18/13 1:30 PM
Part II
Getting Practical
07_9781118539538-pp02.indd 27
1/18/13 1:30 PM
In this part . . .
07_9781118539538-pp02.indd 28
1/18/13 1:30 PM
Chapter 3
Getting Started
In This Chapter
Installing the Tizen SDK
Building your first web app
Getting Help
08_9781118539538-ch03.indd 29
1/18/13 1:30 PM
30
Getting perspective
A perspective describes the layout
of views to help you achieve a
particular task. In the case of the
default Tizen Web Perspective, that
task is web development, so youll
see views including the Connection
Explorer, HTML Preview, and CSS
preview. Chapter 5 introduces the
Connection Explorer, while the HTML
08_9781118539538-ch03.indd 30
1/18/13 1:30 PM
31
This latter approach allows you to complete the SDK installation when youre not connected to the Internet.
After you install the SDK, the first time you launch the IDE
youre 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.
Now youre ready to start developing apps.
08_9781118539538-ch03.indd 31
1/18/13 1:30 PM
32
08_9781118539538-ch03.indd 32
1/18/13 1:30 PM
33
These templates include the basic structure for an application and all the relevant JavaScript libraries required for the
selected UI framework. All you need to do is add your application specific code.
08_9781118539538-ch03.indd 33
1/18/13 1:30 PM
34
3. Click Next.
The User Template Export wizard appears.
4. Enter the name and export location.
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.
08_9781118539538-ch03.indd 34
1/18/13 1:30 PM
35
Figure 3-4: The Import dialog box of the New Project Wizard.
08_9781118539538-ch03.indd 35
1/18/13 1:30 PM
36
After you create the project, you need to edit two files:
.project and config.xml. You can find full instructions
onhow to edit these files on the Tizen developer website:
https://developer.tizen.org/downloads/
sample-web-applications/
load-web-app-tizen-sdk
08_9781118539538-ch03.indd 36
1/18/13 1:30 PM
37
Table 3-1
HTML View Modes
08_9781118539538-ch03.indd 37
1/18/13 1:30 PM
38
08_9781118539538-ch03.indd 38
1/18/13 1:30 PM
39
CSS
The CSS tool removes comments, white space, extra semicolons,
empty declarations, zero values, and so on from your CSS code.
To minify your CSS file, right-click the file in the Project
Explorer, and the options in Figure 3-9 appear at the bottom of
the list. Choose the Minify CSS option, and the file is minified
with a new version of the file (.min.css) created.
08_9781118539538-ch03.indd 39
1/18/13 1:30 PM
40
JavaScript
The JavaScript tool removes comments and extra white
space, replaces identifiers, and performs micro-optimisations
in your JavaScript code.
To minify your JavaScript file, right-click the file in the Project
Explorer, and the options in Figure 3-10 appear at the bottom
of the list. Choose the Minify JS option, and the file is minified
with a new version of the file (.min.js) created.
08_9781118539538-ch03.indd 40
1/18/13 1:30 PM
41
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 HelpHelp Contents. You can
also access Help on the Tizen website:
https://developer.tizen.org/documentation
Here are some of the most useful Help sections to consult to
find out more about the platform and creating apps:
Getting Started with Tizen/Overview/Architecture
describes the platform architecture and introduces the
components that make the platform.
Getting Started with Tizen/Development Environment/
Tizen SDK describes the tools available in the SDK and
tips on how to use them.
Tizen Web App Programming/API References/Device
API Reference provides detailed information about the
Tizen device APIs and how to use them within your web
application. This specification uses Interface Definition
Language (IDL), which is used to describe APIs in a language independent way.
08_9781118539538-ch03.indd 41
1/18/13 1:30 PM
42
Sample applications
In addition to the tutorials and the sample applications provided
in the SDK, several sample web applications are available for
download from the Tizen developer site:
https://developer.tizen.org/downloads/
sample-web-applications
These applications use a variety of standard HTML5, JavaScript,
and CSS3 techniques and can be run either on the desktop or
a mobile device. Each application has a tutorial describing
the main features of the application and how they were
implemented.
You can use the instructions described in the Other web
applications section, earlier in this chapter, to import these
projects into the IDE.
See Chapter 1 for more details about the Tizen wiki, mailing
list, IRC channel, and forums.
08_9781118539538-ch03.indd 42
1/18/13 1:30 PM
Chapter 4
09_9781118539538-ch04.indd 43
1/18/13 1:31 PM
44
09_9781118539538-ch04.indd 44
1/18/13 1:31 PM
45
Localized content
The example shown in Figure 4-1 is missing one key ingredient
of a well-designed web app, and thats localized content.
One of the ways to ensure that your web app displays content
appropriate to the current locale is to use folder-based localization. With this approach, you create a folder for each locale
for which youre 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.
Figure 4-2 shows the package for an app using folder-based
localization.
Figure 4-2: Example application with localized contentpackage content and structure.
09_9781118539538-ch04.indd 45
1/18/13 1:31 PM
46
Listing 4-1
09_9781118539538-ch04.indd 46
1/18/13 1:31 PM
47
The first line of the config.xml file is the declaration identifying the XML version and encoding used:
<?xml version=1.0 encoding=UTF-8?>
The next part of the config.xml file defines the widget element and its attributes:
<widget xmlns=http://www.w3.org/ns/widgets
xmlns:tizen=http://tizen.org/ns/widgets id=http://
yourdomain/SysteminfoSample version=0.13
viewmodes=fullscreen>
</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.
The id attribute is mandatory and uniquely identifies your
widget in this case, the Systeminfo sample. If you have
your own domain name, then use it in place of yourdomain in
Listing 4-1. The id doesnt have to be a valid URL and is just
used for identification.
You can also set other optional attributes, including version,
height, width, viewmodes, and defaultlocale.
The widget element can also contain a number of optional
child elements, representing additional information about
your application. We explain what these elements are used
for in the next section.
<name>SysteminfoSample</name>
<icon src=icon.png/>
<content src=index.html/>
<feature name=http://tizen.org/api/tizen
required=true/>
<feature name=http://tizen.org/api/application.read
required=true/>
<feature name=http://tizen.org/api/systeminfo
required=true/>
09_9781118539538-ch04.indd 47
1/18/13 1:31 PM
48
Overview
In the Overview tab, you can enter general information about
your application.
09_9781118539538-ch04.indd 48
1/18/13 1:31 PM
49
Table 4-1
Type
Description
Identifier
Version
Name
Content
Icon
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.
Table 4-2
Type
Description
Author
Web Site
License
License URL
Description
09_9781118539538-ch04.indd 49
1/18/13 1:31 PM
50
Table 4-3
Type
Description
Width
Height
View Modes
Feature
A feature is a URI-identifiable runtime component for example, an API such as http://tizen.org/api/systeminfo.
In order to access a feature or API at runtime, your application
must register it in the config.xml file. To add a new feature
to your applications config.xml file, select the Feature tab
and click the Add button, as shown in Figure 4-4.
If you select the Internal radio button, youll be able to select
from a list of Tizens built-in features. Optionally, using the
other radio buttons and text boxes, you can enter a URL or
the name of a file that contains a feature definition.
09_9781118539538-ch04.indd 50
1/18/13 1:31 PM
51
Access
The Tizen platform supports WARP, the W3C Access Request
Policy. So by default, applications are restricted from accessing network resources. If your application needs to access any
network resources, you must add them in the config.xml file.
To allow access to a network URL, select the Access tab
and click the Add button. Enter the network URL and select
whether the application should be able to access the URLs
subdomains.
In the Example 1: A 5-Minute Application section, later in
this chapter, we show you how to create a simple app that
displays content from the Food Networks website, as shown
in Figure 4-8. Well leave it to you to decide if were partial to
cakes.
Youll notice that http://m.foodnetwork.com and other
related sites were added to the access origin section of the
config.xml file. The app needs to access these external
resources in order to retrieve the data to display.
09_9781118539538-ch04.indd 51
1/18/13 1:31 PM
52
09_9781118539538-ch04.indd 52
1/18/13 1:31 PM
53
Preferences
A preference is a persistently stored name-value pair that is
associated with the application. You usually use a preference
to store application settings, such as whether a calendar app
was last opened in month or day view, for example.
09_9781118539538-ch04.indd 53
1/18/13 1:31 PM
54
Tizen
In the Tizen tab, you can enter any Tizen-specific information about your application. This information includes the
applications id, the minimum version of the platform that the
application supports, settings such as screen orientation and
context menus, and any app service information.
Table 4-4 shows the attributes that you can set in the Tizen
tab if your application provides an application service for
other applications to use.
Table 4-4
Tizen Information
Type
Description
src
operation
scheme
mime
Source
The Source tab shows the XML content of the config.xml file.
You can use this tab to view the values youve set up using the
other configuration tabs. You can also manually edit the file.
The config.xml file must conform to the XML formatting
rules and the W3C specification requirements, so be careful
when manually editing this file.
09_9781118539538-ch04.indd 54
1/18/13 1:31 PM
55
Start file
The start file is the file that is loaded by the web runtime on
application startup. It is a mandatory part of the application
package. The New Project wizard provided in the IDE creates
a default application start-up file for you called index.html.
Your start file doesnt have to be named index.html. You
can give it any name you like, but you must define the name
of the start file in the content elements src attribute in the
config.xml file. For example:
<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.
In order to load your external JavaScript code, you must
include your script in the header section of the index.html
file using the following code:
<script src=js/main.js></script>
09_9781118539538-ch04.indd 55
1/18/13 1:31 PM
56
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.
To load a style sheet, include the following link in the header
section of the index.html file:
<link rel=stylesheet href=css/style.css />
You can preview the look and feel of any style elements using
the CSS Preview tool, as described in Chapter 3.
If youve minified your CSS files, dont forget to load this version
in the index.html file instead of the original for example:
<link rel=stylesheet href=css/style.css.min />
Application icon
The icon.png file is the applications 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 youre
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.
09_9781118539538-ch04.indd 56
1/18/13 1:31 PM
57
Distributor signature
A distributor can also sign an application to ensure its integrity. This signature file, which cryptographically covers all
nonsignature files and the author signature, if it exists, is the
distributor signature.
This file isnt mandatory in the package. The package can
contain more than one distributor signature, so the naming
convention is signature1.xml, signature2.xml, and so on.
Check out the SDK Help for more details about creating a
distributor signature.
You can find additional information about author and distributor signatures in the XML Digital Signatures for Widgets
specification at www.w3.org/TR/widgets-digsig.
Third-party source
code or libraries
Sometimes you may want or need to use external libraries to
implement UI controls or functionality that isnt 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.
Before making use of any third-party source code or libraries
in your application, please ensure that you check the license
thoroughly and comply with the terms and conditions of use.
09_9781118539538-ch04.indd 57
1/18/13 1:31 PM
58
09_9781118539538-ch04.indd 58
1/18/13 1:31 PM
59
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 its dependent on features
provided in the wijmo libraries.
Example 1: A 5-minute
application
The minimum requirement for a Tizen web application is
a package that contains a start file and a configuration file.
These are the only mandatory parts of an application. In this
example, we show you how to quickly create a simple webapplication to run on your mobile device.
The most simple web application you can create is a hostedweb application. Basically, its an application that launches a
mobile web-page into your web-runtime.
09_9781118539538-ch04.indd 59
1/18/13 1:31 PM
60
09_9781118539538-ch04.indd 60
1/18/13 1:31 PM
61
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.
09_9781118539538-ch04.indd 61
1/18/13 1:31 PM
62
09_9781118539538-ch04.indd 62
1/18/13 1:31 PM
63
First, you need to build and run the Systeminfo app from
the Tizen SDK. You can find detailed instructions in the
Chapter 3.
If you already know your way around, just choose FileNew
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-9.
This sample application uses the Tizen Web UI Framework
and demonstrates how to use the System Info Tizen APIs. Its
a good starting point to understand how to include JavaScript
and CSS functionality in a web application and also to see how
to use the Tizen APIs.
09_9781118539538-ch04.indd 63
1/18/13 1:31 PM
64
When these features are registered, the application can immediately access the functionality provided by the Tizen and
SystemInfo objects. So for example, to retrieve the current
battery level on the device, the following code is used:
tizen.systeminfo.getPropertyValue(Power, onPowerSucess,
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.
In this index.html, we load a single style sheet and JavaScript
files for jQuery, the Web UI Framework, and our app:
<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>
<script src=tizen-web-ui-fw/latest/js/tizen-webui-fw-libs.
js></script>
09_9781118539538-ch04.indd 64
1/18/13 1:31 PM
65
<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>
<link rel=stylesheet type=text/css href=./css/style.
css/>
</head>
09_9781118539538-ch04.indd 65
1/18/13 1:31 PM
66
09_9781118539538-ch04.indd 66
1/18/13 1:31 PM
67
09_9781118539538-ch04.indd 67
1/18/13 1:31 PM
68
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.
Multiple style sheets can be used in your application to style
your elements, but due to the way that cascading style sheets
are merged, you must be careful about the order they are
linked to in the index.html document head.
09_9781118539538-ch04.indd 68
1/18/13 1:31 PM
69
09_9781118539538-ch04.indd 69
1/18/13 1:31 PM
70
09_9781118539538-ch04.indd 70
1/18/13 1:31 PM
Chapter 5
10_9781118539538-ch05.indd 71
1/18/13 1:31 PM
72
10_9781118539538-ch05.indd 72
1/18/13 1:31 PM
73
10_9781118539538-ch05.indd 73
1/18/13 1:31 PM
74
10_9781118539538-ch05.indd 74
1/18/13 1:31 PM
75
You can also launch the Emulator Manager from the command line or from the application menu.
10_9781118539538-ch05.indd 75
1/18/13 1:31 PM
76
10_9781118539538-ch05.indd 76
1/18/13 1:31 PM
77
10_9781118539538-ch05.indd 77
1/18/13 1:31 PM
78
10_9781118539538-ch05.indd 78
1/18/13 1:31 PM
79
10_9781118539538-ch05.indd 79
1/18/13 1:31 PM
80
10_9781118539538-ch05.indd 80
1/18/13 1:31 PM
81
10_9781118539538-ch05.indd 81
1/18/13 1:31 PM
82
10_9781118539538-ch05.indd 82
1/18/13 1:31 PM
83
10_9781118539538-ch05.indd 83
1/18/13 1:31 PM
84
10_9781118539538-ch05.indd 84
1/18/13 1:31 PM
85
Debugging JavaScript
Note: This information is relevant for whichever debugging
environment youre using.
To debug your JavaScript, choose the Sources option from
the menu to view the JavaScript files in the Remote Inspector
window, as shown in Figure 5-14. You can select the required
JavaScript file to debug by clicking the arrow next to the
filename.
10_9781118539538-ch05.indd 85
1/18/13 1:31 PM
86
You can also debug your JavaScript by adding debug statements into your code using the console.log() function.
Any log messages will be displayed in the IDEs console panel
at the bottom of the Web Perspective.
10_9781118539538-ch05.indd 86
1/18/13 1:31 PM
87
Table 5-1
SDB Commands
Command
Description
sdb shell
sdb help
sdb version
sdb start-server
sdb kill-server
10_9781118539538-ch05.indd 87
1/18/13 1:31 PM
88
Description
sdb get-state
sdb get-serialno
Print <serial-number>
sdb status-window
In the Emulator, you can also open an SDB shell from the
Emulator configuration menu (refer to Figure 5-4).
Table 5-2 shows the options that you can use to direct the
commands to the required device or Emulator instance.
Table 5-2
SDB Options
Option
Description
-d
-e
10_9781118539538-ch05.indd 88
1/18/13 1:31 PM
Chapter 6
s any mobile developer knows, the write-once, runanywhere promise of HTML5 is still a long way from
being realized. Web developers face a lot of challenges, including
designing CSS style sheets to cope with different screen sizes,
fine-tuning JavaScript code to handle subtle differences in
device APIs, and even deciding which app store to sell their
wares in. But those same developers also know a good opportunity when they see one and wont let a few problems get in
their way.
In this chapter, we examine different aspects of the web app
landscape, including platforms, JavaScript frameworks, web
API standards, and app stores. We focus on some of the most
common web porting problems and provide some solutions.
If youve built a web page or developed a web app for another
platform, this chapter acts as your guide to porting your web
app to Tizen. If you want to make your Tizen web apps more
portable, were here to help with that, too.
11_9781118539538-ch06.indd 89
1/18/13 1:31 PM
90
11_9781118539538-ch06.indd 90
1/18/13 1:31 PM
91
11_9781118539538-ch06.indd 91
1/18/13 1:31 PM
92
Standards
Another good thing about the web technology is that its
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 Wholesale Application Community (WAC), which
is now integrated into the GSM Association (GSMA), publish
requirements and APIs for web apps.
WAC defines operator APIs and includes device APIs from the
Open Mobile Terminal Platform (OMTP) BONDI project and
Joint Innovation Lab (JIL). The goal of WAC is to allow developers to create platform independent apps that include features such as the WAC Payment API with billing features that
work for all network operators.
Some platforms extend the W3C device APIs by defining their
own proprietary device APIs. However, using these APIs makes
your web app less portable, so you gain features at the expense
of compatibility. Its the web app developers dilemma.
Distribution
The final part of web app landscape is the distribution channel, including the app stores in which you sell your web apps.
The distribution channel is the most important part of the
ecosystem because its how youll start making money from
your app. However, supporting multiple stores on multiple
platforms can also become complicated.
11_9781118539538-ch06.indd 92
1/18/13 1:31 PM
93
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
youll have to wrap your web code in a native app in order to
gain entry to these stores.
Note: The Tizen store is in the preparation stage at the time of
writing.
Handling different
package formats
Table 6-1 shows the packaging formats used by different platforms. To port your web app from one of these platforms to
Tizen, you need to package your files as in the standard W3C
web widget format, a .wgt file.
11_9781118539538-ch06.indd 93
1/18/13 1:31 PM
11_9781118539538-ch06.indd 94
(installable bundle)
myscript.js *
.crx
.xpi
options.xul*
main.html
Format
install.rdf*
icon.png
/img folder *
manifest.webapp
manifest.json
Content
.zip
splash
screen.png
/img folder*
/css folder
/js folder
default.html
package.appx
manifest
Chrome Store
icon.png*
icon.png
.ipk
sources.json
/img folder
/css folder
/js folder
.wgt
/img folder*
/css folder*
/js folder*
index.html
config.xml
appinfo.json
index.html
Tizen
webOS
Stores
Table 6-1
94
Part II: Getting Practical
1/18/13 1:31 PM
95
11_9781118539538-ch06.indd 95
1/18/13 1:31 PM
96
11_9781118539538-ch06.indd 96
1/18/13 1:31 PM
97
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);
}
11_9781118539538-ch06.indd 97
1/18/13 1:31 PM
98
This code ensures that your app is optimized to take advantage of the full device width of a mobile device.
The media query in CSS3 allows you to detect the screen size
of device and adjust the style accordingly:
@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);
}
}
11_9781118539538-ch06.indd 98
1/18/13 1:31 PM
99
11_9781118539538-ch06.indd 99
1/18/13 1:31 PM
100
11_9781118539538-ch06.indd 100
1/18/13 1:31 PM
101
11_9781118539538-ch06.indd 101
1/18/13 1:31 PM
102
This will ensure that you always use the latest version of the
libraries, but of course you will need an Internet connection.
11_9781118539538-ch06.indd 102
1/23/13 8:32 AM
Part III
Tizen in Detail
12_9781118539538-pp03.indd 103
1/18/13 1:31 PM
In this part . . .
12_9781118539538-pp03.indd 104
1/18/13 1:31 PM
Chapter 7
Building Your UI
In This Chapter
Introducing jQuery Mobile
Using basic controls
Taking advantage of UI building tools
Creating advanced UIs
13_9781118539538-ch07.indd 105
1/18/13 1:32 PM
106
Page structure
To use jQuery Mobile, you just need to create an HTML5 page.
The page must start with an HTML5 doctype to take advantage 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. We explain the
page elements in more detail in the upcoming Example:
Building a Contacts UI section.
13_9781118539538-ch07.indd 106
1/18/13 1:32 PM
107
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,
tabhold, swipe, swipeleft, and swiperight.
To assign the event to your UI, you just use the bind method:
$(document).bind(swipeleft, function(event, data){
//your implementation of swipe event
});
13_9781118539538-ch07.indd 107
1/18/13 1:32 PM
108
Table 7-1
Name
From
Description
Checkbox
JQM
Radio Button
JQM
Radio button
Button
JQM
Basic buttons
Searchbar
JQM
Segment Control
JQM
Selection Info
JQM
Slider
JQM
Progressbar
jQuery UI
Lists
JQM
List of items
Virtual List
New
Extendable List
New
Swipe List
New
Popup
New
Pop-up window
Context Popup
New
Toggle Switch
New
13_9781118539538-ch07.indd 108
1/18/13 1:32 PM
109
Name
From
Description
Notification
New
Image Slider
New
Page Control
New
Control Bar
New
Day Selector
New
New
Color
New
No Contents
New
Handler
New
New
Multimedia View
New
Virtual Grid
New
13_9781118539538-ch07.indd 109
1/18/13 1:32 PM
110
You can use the Tizen Web UI Framework to create the same
UI in your web app. Figure 7-3 shows a web version of the
native contacts app.
Implementing the Tizen web user experience is simple. The
top level view widget is a page in jQuery Mobile, consisting of
header, content, and footer. Our Contacts web app uses the
controlbar, searchbar, and swipelist widgets to implement the application functionality.
13_9781118539538-ch07.indd 110
1/18/13 1:32 PM
111
13_9781118539538-ch07.indd 111
1/18/13 1:32 PM
112
13_9781118539538-ch07.indd 112
1/23/13 8:35 AM
113
If you have both the control bar and search bar in the header,
as shown in Figure 7-6, you have to add the following code to
your CSS file because the height of the control bar (114px)
isnt automatically calculated by the Tizen web UI Framework:
.input-search-bar {
top: 114px;
}
If you dont make this change to your CSS file, then the search
bar wont appear in the right place. You need to apply the
same CSS styling to the page content as well.
13_9781118539538-ch07.indd 113
1/23/13 8:35 AM
114
Because the Swipe List is derived from the List View, all
options for the List View are also applicable to the Swipe List.
This includes list items with multi-lines of text, large icons,
toggle buttons, text buttons, circle buttons, thumbnails, or
even more complex ones with fixed with icons and buttons.
13_9781118539538-ch07.indd 114
1/23/13 8:35 AM
115
13_9781118539538-ch07.indd 115
1/18/13 1:32 PM
116
13_9781118539538-ch07.indd 116
1/18/13 1:32 PM
117
13_9781118539538-ch07.indd 117
1/18/13 1:32 PM
118
Implementing events
in the UI builder
The UI Builder can also generate code to handle the events
supported by Tizens predefined UI widgets. For example, the
Swipe List item supports the Animationend event, and you
can generate the skeleton JavaScript code to handle this event
from within UI Builder.
13_9781118539538-ch07.indd 118
1/18/13 1:32 PM
119
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 swipelist widget supports. Choose Animationend to assign this event to the
swipelist item and click the triangle that appears below
the menu, as shown in Figure 7-13.
13_9781118539538-ch07.indd 119
1/18/13 1:32 PM
120
13_9781118539538-ch07.indd 120
1/18/13 1:32 PM
121
Figures 7-14 and 7-15 show the final code running on the Tizen
development device. The cover page contains the image and
flip text.
13_9781118539538-ch07.indd 121
1/18/13 1:32 PM
122
13_9781118539538-ch07.indd 122
1/18/13 1:32 PM
Chapter 8
Taking Advantage of
Location-Based Services
In This Chapter
Displaying a map
Converting between addresses and co-ordinates
Dropping a pin on a map
14_9781118539538-ch08.indd 123
1/18/13 1:32 PM
124
14_9781118539538-ch08.indd 124
1/18/13 1:32 PM
125
Displaying a Map
While you can use any of the JavaScript mapping APIs for
displaying a map in your Tizen web app, we use the Google
Maps API for this example. Heres how you display a map
based on your current location:
1. Get your current location.
You need to use the W3C geolocation API to retrieve
the longitude and latitude of the devices current
location:
navigator.geolocation.getCurrentPosition(
function(position) {
var mapCentre = position;
console.log('Latitude: + position.coords.
latitude+ Longitude: +
position.coords.longitude);
},
function(error) {
console.err(Failed to get current position);
}
);
14_9781118539538-ch08.indd 125
1/18/13 1:32 PM
126
Figure 8-1: Displaying a map in the Tizen Emulator using the Google map
APIs.
You also need to include the Map API URL in your Tizen
project config.xml file because its 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.
Finding an Address
Displaying a map given a longitude and latitude is relatively
simple, but sometimes all you have is a human-readable
14_9781118539538-ch08.indd 126
1/18/13 1:32 PM
127
and select the one you want to use from the list.
The Tizen Geocoder APIs provide two methods: geocode()
and reverseGeocode().
The geocode() method takes up to four parameters: a
DOMString or address that you want to geocode, callback
functions for success and error handling, and a Geocode
Options object that you use to specify the sorting order and
maximum number of results returned. The last two parameters
are optional.
14_9781118539538-ch08.indd 127
1/18/13 1:32 PM
128
14_9781118539538-ch08.indd 128
1/18/13 1:32 PM
129
function(results, status) {
if (status == google.maps.GeocoderStatus.OK) {
map.setCenter(results[0].geometry.location);
var marker = new google.maps.Marker({
map: map,
position: results[0].geometry.location});
}
else {
alert(Geocode was not successful for the
following reason: + status);
}
}
);
}
14_9781118539538-ch08.indd 129
1/18/13 1:32 PM
130
14_9781118539538-ch08.indd 130
1/18/13 1:32 PM
131
14_9781118539538-ch08.indd 131
1/18/13 1:32 PM
132
14_9781118539538-ch08.indd 132
1/18/13 1:32 PM
Chapter 9
15_9781118539538-ch09.indd 133
1/18/13 1:32 PM
134
Table 9-1
Multimedia Features
Feature
Recommended API
Capturing audio
Capturing images
Capturing video
Discovering Content
The Tizen MediaContent API provides functionality for
searching for multimedia content stored either locally on your
device or an external memory card.
15_9781118539538-ch09.indd 134
1/18/13 1:32 PM
135
Media source
To use the functionality provided by the MediaContent API,
you must retrieve the media source of the platform using the
following in your code:
var mediaSource = tizen.mediacontent.getLocalMediaSource();
Media item
A media item is an object that contains all the attributes of
a single piece of multimedia content; it doesnt contain the
multimedia content itself. The MediaItem interface is used to
provide an application access to an items attributes.
In the Tizen platform, the MediaItem interface is extended by
the MediaAudio, MediaImage, and MediaVideo interfaces
with attributes specific to the content type. Table 9-2 lists
these attributes.
15_9781118539538-ch09.indd 135
1/18/13 1:32 PM
136
Table 9-2
Attributes Supported by
Multimedia Content
Content Type
Attributes
MediaItem
MediaAudio
MediaImage
MediaVideo
Getting permission
Because multimedia 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.)
Here are the permissions related to multimedia content:
Adding http://tizen.org/api/mediacontent.
read to your permissions gives you access to the
methods in the API for retrieving folders and searching
for content.
Adding http://tizen.org/api/mediacontent.write
to your permissions gives you access to the methods in
the API for updating the attributes of media items.
Adding http://tizen.org/api/mediacontent
allows you access to all the features of the API.
15_9781118539538-ch09.indd 136
1/18/13 1:32 PM
137
Before you can use any of the MediaContent APIs, you need
to get the mediasource object from the platform:
var mediaSource = tizen.mediacontent.getLocalMediaSource();
15_9781118539538-ch09.indd 137
1/18/13 1:32 PM
138
15_9781118539538-ch09.indd 138
1/18/13 1:32 PM
139
ApplicationService object
To launch an Application Service, you first need to create an
Application Service object that describes the type of service
you require.
An Application Service object consists of an operation, URI,
MIME type, and data array:
The operation is a string that defines the action to be
performed by the Application Service.
The URI defines the data on which the operation will be
performed for example, the location of a picture to be
viewed.
The MIME type defines the specific type of the URI for
example, the type of image.
15_9781118539538-ch09.indd 139
1/18/13 1:32 PM
140
Launching a service
The application object provides a launchService()
method, which your app calls to launch the service defined in
the Application Service object.
When the system receives the launch request, it processes
the parameters of the Application Service object to select
the application that provides the appropriate service. If the
system finds a suitable application, it launches it, passing the
information contained in the Application Service object.
The launchService() method is asynchronous, so you
can define optional success and error callbacks to get status
information. The success callback is triggered when the
application is launched successfully; to get the status of the
requested operation and any data passed back to your app,
you need to define a reply callback. This is how you get the
image chosen by the user in the gallery app, for example.
The reply callback uses the ApplicationServiceData
ArrayReplyCallback interface, which specifies two methods: onsuccess() and onfail(). The onsuccess()
method will contain an array with any data passed back from
the Application Service, such as the URIs of the selected
images.
15_9781118539538-ch09.indd 140
1/18/13 1:32 PM
141
You dont need to set a URI or any data for this camera
Application Service request.
After you create the Application Service object, your app
requests that this service is launched using the launch
Service() method:
tizen.application.launchService(service, null, successCb, errCb,
serviceReplyCb);
15_9781118539538-ch09.indd 141
1/18/13 1:32 PM
142
15_9781118539538-ch09.indd 142
1/18/13 1:32 PM
143
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:
<audio id=audioPlayer src=audio/test.mp3></audio>
If youre not using the default controls, you need to add the
buttons and other controls for your custom playback UI.
If you want to display any visual elements (such as subtitles),
you can also play your audio file through the HTML5 video
element.
15_9781118539538-ch09.indd 143
1/18/13 1:32 PM
144
When the user clicks the Play button, the audio file is loaded
into the audio element and starts playing.
15_9781118539538-ch09.indd 144
1/18/13 1:32 PM
145
Multimedia Streaming
In a Tizen web application, its possible to access multimedia
streams from local devices, such as the video camera
and microphone. This functionality is based on the W3C
getUserMedia specification.
The getUserMedia specification is a work in progress
and not fully standardized. Many browser projects have
implemented their own versions of the specification. The
Tizen platform uses WebKit and provides access to local
multimedia streams through the webkitGetUserMedia API.
The implementation of getUserMedia is very much bleedingedge technology. Any APIs or functionality discussed in this
section are liable to change in future versions of the specification and may work differently in later versions of Tizen.
15_9781118539538-ch09.indd 145
1/18/13 1:32 PM
146
webkitGetUserMedia
The webkitGetUserMedia API is the WebKit implementation
of the getUserMedia specification. Its used to create a local
media stream from either the devices camera, microphone,
or both.
The webkitGetUserMedia API is an access method,
prompting the user for permission to use the audio/video
input. If the user gives permission, the APIs success callback is
triggered with a local media stream object. If the user refuses
permission, the optional error callback is triggered.
Note: The user interface for granting user permission to
access the video and audio streams is still being refined at the
time of writing (the 2.0 alpha version of the Tizen SDK).
The local media stream object generated by the webkit
GetUserMedia API can be saved to a file, displayed in a video
element, or transmitted to a remote peer. In this section, we
focus on how to display the local media stream in a video
element.
For more information about media streams and how you can
use them in your web application, see the W3C WebRTC
specification at www.w3.org/TR/webrtc.
In order to display the local media stream in a video element
the stream needs to be converted into a format that is
compatible with the video element. The video element
requires the input media resource for display to be in the
format of a URL.
The WebRTC specification defines a URL interface which
provides a createObjectURL() method that you can use
to create a Blob URL from a media stream object. As with the
getUserMedia API, the WebKit project has implemented its
own version of this specification and provides a webkitURL
interface containing a createObjectURL() method.
This createObjectURL() method takes the media stream
object generated by the webkitGetUserMedia API and
creates a URL that is suitable as an input for the video
elements source attribute.
15_9781118539538-ch09.indd 146
1/18/13 1:32 PM
147
15_9781118539538-ch09.indd 147
1/18/13 1:32 PM
148
15_9781118539538-ch09.indd 148
1/18/13 1:32 PM
Chapter 10
16_9781118539538-ch10.indd 149
1/18/13 1:32 PM
150
Introducing NFC
Near Field Communication (NFC) isnt 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 cant
process the information sent from other devices, while NFC
enabled devices can do more, such as card simulation and
peer-to-peer communication. Thats why NFC needs the
processing power of a smart device.
NFC provides a wireless communication method with some
unique characteristics:
Close proximity
Low speed
No setup required
No battery required for a passive tag
At the moment, it seems that NFC is everywhere. Google is
encouraging adoption of Google Wallet, which allows consumers
to make small transactions via NFC-enabled devices, such as
the Nexus S and Samsung Galaxy SIII. The S III was also the
device used by Visa and Samsung to provide mobile payment
services during the London 2012 Olympics.
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.
16_9781118539538-ch10.indd 150
1/18/13 1:32 PM
151
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:
Read/write mode: NFC devices are able to read or write
small amounts of information to NFC-compatible tags.
Possible uses include getting information from an NFC
tag on a smart poster or creating your own personal NFC
sticker.
Peer-to-peer mode: Two NFC devices exchange data.
This data could include Bluetooth or Wi-Fi link setup
parameters, virtual business cards, or digital photos.
Card Emulation mode: The NFC devices appear to an
external reader much the same as a traditional contactless
card. This enables contactless payment and ticketing.
16_9781118539538-ch10.indd 151
1/18/13 1:32 PM
152
and
<feature name=http://tizen.org/api/nfc.tag" required="true"/>
to config.xml.
16_9781118539538-ch10.indd 152
1/18/13 1:32 PM
153
Setting up NFC
To use NFC, you have to create the NFCAdapter object. It is
fairly simple to create the adapter by just calling
var nfcAdapter = tizen.nfc.getDefaultAdapter();
16_9781118539538-ch10.indd 153
1/18/13 1:32 PM
154
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.
16_9781118539538-ch10.indd 154
1/18/13 1:32 PM
155
}
}
}
},
function(){
//error callback of readNDEF()
}
);
}
}
};
16_9781118539538-ch10.indd 155
1/18/13 1:32 PM
156
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.
16_9781118539538-ch10.indd 156
1/18/13 1:32 PM
157
16_9781118539538-ch10.indd 157
1/18/13 1:32 PM
158
16_9781118539538-ch10.indd 158
1/18/13 1:32 PM
159
16_9781118539538-ch10.indd 159
1/18/13 1:32 PM
160
16_9781118539538-ch10.indd 160
1/18/13 1:32 PM
161
Table 10-1
Accelerating Accelerating
Up
Forward
acceleration
{0, 0, 0}
{0, 0, 5}
{0, 2, 0}
acceleration
IncludingGravity
{0, 0, 9.81}
{0, 0, 15}
{0, 2, 9.81}
Accelerating
Left
Accelerating up
& to the Right
acceleration
{3, 0, 0}
{5, 0, 9}
acceleration
IncludingGravity
{3, 0, 9.81}
{5, 0, 11}
16_9781118539538-ch10.indd 161
1/18/13 1:32 PM
162
16_9781118539538-ch10.indd 162
1/18/13 1:32 PM
Chapter 11
Messaging
In This Chapter
Creating and sending messages
Searching for messages
Building a User Interface for message searching
17_9781118539538-ch11.indd 163
1/18/13 1:33 PM
164
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
capabilities of the platform. Email, SMS, and MMS messaging
service types share a common interface.
For example, to access email functionality, you retrieve the
email service with the following code:
tizen.messaging.getMessageServices(messaging.email,
msgServiceCb, errCb);
This service request API is asynchronous, so any available email messaging services are returned in an array of
MessageService objects by the success callback.
Once the required message service is retrieved, you can send
messages and load message content and attachments. For
email, you can synchronise content with an external server.
Message structure
A message consists of a Message object, which contains
the attributes of the message, a MessageBody object, and
optionally any MessageAttachment objects.
17_9781118539538-ch11.indd 164
1/18/13 1:33 PM
165
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.)
The Message interface constructor is used to create a
Message object. For example, heres how to create an SMS
object:
msg = new tizen.Message(messaging.sms, {
plainBody: Hi Sarah, how are you?,
to: [1234]
});
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.
When reading a message, if the loaded status attribute of the
message body is set to false, it indicates that the body hasnt
been downloaded from the server. If this is the case, the body
must be downloaded using the MessageService objects
loadMessageBody() method.
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.
If a message contains one or more attachments, the messages
hasAttachment attribute will be set to true. Because
attachments arent always automatically downloaded from
the server, you may need to download them using the load
MessageAttachment() method.
17_9781118539538-ch11.indd 165
1/18/13 1:33 PM
166
Message storage
Each message service object in the system has its own
message 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/api/messaging.send to
your permissions gives you access to the message sending
functionality.
Adding http://tizen.org/api/messaging.read to
your permissions lets you read from the message storage
Adding http://tizen.org/api/messaging.write
to your permissions lets you write to the message storage
Adding http://tizen.org/api/messaging allows
you access to all the features of the API.
17_9781118539538-ch11.indd 166
1/18/13 1:33 PM
167
17_9781118539538-ch11.indd 167
1/18/13 1:33 PM
168
17_9781118539538-ch11.indd 168
1/18/13 1:33 PM
169
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.
In this example, the initialisation code includes functionality to retrieve the SMS message service, and event bindings
for the page and the search box. This is implemented in the
main.js file, as shown in Listing 11-2.
17_9781118539538-ch11.indd 169
1/18/13 1:33 PM
170
17_9781118539538-ch11.indd 170
1/18/13 1:33 PM
171
17_9781118539538-ch11.indd 171
1/18/13 1:33 PM
172
When the user enters a character in the search bar, the input
elements input event is triggered.
To update the list to display only the messages containing
the search string, you need to handle this event. In the
initialisation code in the main.js file, you already defined a
method to handle this input event. The code in Listing 11-5
shows how to implement this updateList() method.
updateList() checks whether the search string has
changed; if it has, the findString() method is called.
17_9781118539538-ch11.indd 172
1/18/13 1:33 PM
173
17_9781118539538-ch11.indd 173
1/18/13 1:33 PM
174
17_9781118539538-ch11.indd 174
1/18/13 1:33 PM
Chapter 12
18_9781118539538-ch12.indd 175
1/18/13 1:33 PM
176
Address books
It doesnt 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 default address book, you use the
following in your code:
var addressBook = tizen.contact.getDefaultAddressBook();
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.
18_9781118539538-ch12.indd 176
1/18/13 1:33 PM
177
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/api/contact.read to
your permissions gives you access to all the methods in
the API, but you cant add, modify, or delete contacts.
18_9781118539538-ch12.indd 177
1/18/13 1:33 PM
178
Adding a contact
In this example, we show you how to add a single contact to
the default address book.
Before you can perform any operations on an address book,
you must first retrieve it from the system. Heres how to get
the default address book:
var addressBook = tizen.contact.getDefaultAddressBook();
18_9781118539538-ch12.indd 178
1/18/13 1:33 PM
179
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.
If you know the ContactRef of the contact youre looking for,
you can directly retrieve the contact from the address book
using the get() method.
The ContactRef is a unique reference to the contact, as it
contains both the id of the address book the contact is
contained within and the id of the contact.
You can create this reference using the ContactRef
constructor with the AddressBookId and ContactId of
the contact youre trying to retrieve. The address books
id and the contacts id are both attributes of the Contact
object, which are set after the contact has been added to the
AddressBook.
var contactRef; // Value initialised with known data
18_9781118539538-ch12.indd 179
1/18/13 1:33 PM
180
18_9781118539538-ch12.indd 180
1/18/13 1:33 PM
181
}
}
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 appropriate
callback method.
In this example, we show you how to delete all the contacts in
a specific address book.
To get all the contacts in the address book, you can use the
find() method:
addressBook.find(successCB, errorCB);
18_9781118539538-ch12.indd 181
1/18/13 1:33 PM
182
Exporting a contact
In this example, we show you how to export a contact in the
vCard format. The Contact API supports vCard versions 2.1
and 3.0.
The Contact object provides a convertToString()
method to convert all the parameters contained within the
contact object into a string that complies with the vCard
format.
You can get a contact from the address book using either of
the examples shown in the Retrieving a contact section,
earlier in this chapter. Then you just call the convert
ToString() method:
var contactRef; // Value initialised with known data
var addressBook = tizen.contact.getAddressBook(contactRef.
addressBookId);
var contact = addressBook.get(contactRef.contactId);
var vCard = contact.convertToString(VCARD_30);
console.log(vCard);
18_9781118539538-ch12.indd 182
1/18/13 1:33 PM
Chapter 13
Getting Organized
with Calendars
In This Chapter
Using the Calendar API
Creating and retrieving tasks
Adding reminders to a task
19_9781118539538-ch13.indd 183
1/18/13 1:33 PM
184
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.
So, for example, to retrieve the default event calendar, you
use the following code:
var calendar = tizen.calendar.getDefaultCalendar(EVENT);
You should always use the default calendar for new items.
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 youve set for your application.
You can perform single add, update, and delete operations
on the calendar synchronously, or you can perform multiple
add, update, and delete operations using asynchronous batch
methods. See the A New Batch sidebar in this chapter for
more details about batch functions.
CalendarItem
CalendarItem is an interface from which both the
CalendarEvent and CalendarTask interfaces are derived.
The CalendarItem interface defines the functions and
attributes that are common to both events and tasks.
19_9781118539538-ch13.indd 184
1/18/13 1:33 PM
185
Supported properties
The following properties are
supported for all calendar item types:
id, lastModificationDate,
description, summary,
isAllDay, startDate,
duration, location,
geolocation, organizer,
visibility, status,
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 applications config.xml file.
(See Chapter 4 for more information about the config.xml
file.)
Adding http://tizen.org/api/calendar.read
gives you access to all the methods in the API, except for
any methods that add, modify, or delete events or tasks.
Adding http://tizen.org/api/calendar.write
gives you access to all the methods in the API, except for
any methods used to find events or tasks or watch the
calendar.
Adding http://tizen.org/api/calendar gives you
access to all the features in the API.
To use any of the Tizen Time objects, such as for setting the
date and time of calendar events and tasks, you need to set
one of the http://tizen.org/api/time permissions. See
the SDK Help for more details.
19_9781118539538-ch13.indd 185
1/18/13 1:33 PM
186
Creating a Task
In this example, we add a single task to the default task calendar.
Before you can perform any operations on the task calendar,
you first need to retrieve it from the system:
var calendar = tizen.calendar.getDefaultCalendar(TASK);
After you create your task, you can then add it to the calendar:
calendar.add(task);
19_9781118539538-ch13.indd 186
1/18/13 1:33 PM
187
A new batch
In Chapter 12, we explain
that operations that involve
making changes to the address
book can be combined into
batch operations to improve
performance. You can also use
the addBatch, updateBatch,
and removeBatch functions to
combine multiple changes to the
calendar, such as adding, updating,
Retrieving Tasks
You can get a task from the calendar in two ways:
By using the task id
By searching for specific task parameters in the calendar
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
calendar using the get() method:
var taskId; // Value initialised with known data
var calendar = tizen.calendar.getDefaultCalendar(TASK);
// Retrieve task
var task = calendar.get(taskId);
19_9781118539538-ch13.indd 187
1/18/13 1:33 PM
188
19_9781118539538-ch13.indd 188
1/18/13 1:33 PM
189
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:
var task = calendar.get(taskId);
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
lastModificationDate attribute or the alarms attribute.
19_9781118539538-ch13.indd 189
1/18/13 1:33 PM
190
19_9781118539538-ch13.indd 190
1/18/13 1:33 PM
Part IV
20_9781118539538-pp04.indd 191
1/18/13 1:33 PM
In this part . . .
20_9781118539538-pp04.indd 192
1/18/13 1:33 PM
Chapter 14
21_9781118539538-ch14.indd 193
1/18/13 1:34 PM
194
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.
This book, written by Stoyan Stefanov and published by
OReilly (ISBN: 978-0-596-80675-0) provides code templates
and explains the best approach to creating reusable code in
JavaScript. Its another essential volume on our bookshelves.
21_9781118539538-ch14.indd 194
1/18/13 1:34 PM
195
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.
jQuery (http://jquery.com/) is the most popular and
powerful JavaScript framework and is actually included with
Tizen. It allows you to write code thats portable. Weve found
it particularly useful for AJAX (www.adaptivepath.com/
ideas/ajax-new-approach-web-applications) features
and grabbing data from external websites. It also makes it
easy to traverse DOM (Document Object Model) trees.
We mention Modernizr (http://modernizr.com/) in
Chapter 6. Its handy for detecting the features of a browser
and writing portable code which works well across browsers.
Also worth checking out is Wijmo (http://wijmo.com/) a
set of UI widgets based on jQuery.
21_9781118539538-ch14.indd 195
1/18/13 1:34 PM
196
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.
Its particularly useful for those with a web design background.
Smashing Magazine also publish books, including Smashing
jQuery by Jake Rutter (Wiley, ISBN: 978-0-470-97723-1) which
is well worth checking out.
21_9781118539538-ch14.indd 196
1/18/13 1:34 PM
197
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
encourages 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.
21_9781118539538-ch14.indd 197
1/18/13 1:34 PM
198
21_9781118539538-ch14.indd 198
1/18/13 1:34 PM
Chapter 15
22_9781118539538-ch15.indd 199
1/18/13 1:34 PM
200
22_9781118539538-ch15.indd 200
1/18/13 1:34 PM
201
Tizen Is Consistent
These device APIs use patterns that will be familiar to you
if youre used to libraries such as jQuery. If youre already
a web developer, it wont take you long to become a Tizen
expert.
22_9781118539538-ch15.indd 201
1/18/13 1:34 PM
202
22_9781118539538-ch15.indd 202
1/18/13 1:34 PM
Acknowledgments
The authors would like to thank:
Dr. Yong-Suk Moon, Justin Hong, Ray HS Yun, Hokyung Kim,
and Philip Northam for their help in making this project
possible.
We would also like to thank our colleagues in HQ, SCRC, SPRC,
and SISO, especially Hyeyoung Jung, DaeHo Han, TaeHee Lee,
JunHo Lee, and Yuqiang Du.
Finally, we would like to thank our colleagues in our team at
SERI for their support, encouragement, and a never-ending
supply of biscuits.
More personally:
From Cheng: To Mom, Dad, Mary, Luke, and Tong with love.
From Jon: Love to Julia and Iliya, for keeping me crazy.
23_9781118539538-bother01.indd 203
1/18/13 1:34 PM
23_9781118539538-bother01.indd 204
1/18/13 1:34 PM
24_9781118539538-badvert01.indd 205
1/18/13 1:34 PM
SAMSUNG DEVELOPERS
JOIN US AND START CREATING GREAT APPS TODAY
SAMSUNG DEVELOPERS
Samsung Developers (http://developer.samsung.com)
provides a wealth of technical information and tools to
help you create apps for Samsung smart devices. Get up to
speed with the latest information on our mobile and Smart
TV platforms. Register as a Samsung Developer to get
regular updates on our various offline events, app
contests and software releases.
SAMSUNG APPS
Choose Samsung Apps to publish your app and reach
a global audience of millions. Accessible from every
Samsung smart device around the world, Samsung Apps
provides its customers with reliable high quality content
and its developers with localized support services. Make
the most of our in-app revenue generators to increase
your development ROI.
SELLER OFFICE
Seller Office is the administration system required to
distribute apps, from app registration and certification, to
deployment of your app through Samsung Apps. Seller
Office will guide you through the whole process and once
your app is live, buyer comments, sales/profit reports and
other vital statistical information can be easily viewed.
SAMSUNG DEVELOPERS
Realize your Imagination with
Samsung Developers
http://developer.samsung.com
24_9781118539538-badvert01.indd 206
1/18/13 1:34 PM