2 Tizen Web App Dev Tizen Studio
2 Tizen Web App Dev Tizen Studio
2 Tizen Web App Dev Tizen Studio
Structure
Style and
layout
Interaction
and functionalities
4
Introduction
Web applications offer a range of benefits. It is a perfect way to start
developing Tizen applications.
Easy to learn
Compatible across multiple mobile and wearable platforms
Easy to maintain
However, there are still some limitations of Web applications over native
applications. Creation of native applications is discussed later in this tutorial.
5
Creating Tizen Web Project
In the Tizen IDE, click File > New > Tizen Project.
6
Creating Tizen Web Project
In the project wizard pop-up window, select the Template, then
select profile and versions: WEARABLE v2.3.2 application.
7
Creating Tizen Web Project
Select Web Application and click Next. Then select the application template.
Running the
Creating the Generating the Creating the
Application on the
Application Project Author Certificate Emulator Instance
Emulator
8
Creating Tizen Web Project
Change the project name, if you want.
Click More properties, if you want to change more properties.
Leave all other fields in the Project Wizard to their default values, and click
Finish.
Running the
Creating the Generating the Creating the
Application on the
Application Project Author Certificate Emulator Instance
Emulator
9
Files in Tizen Web Project
The following figure illustrates the basic structure of a Tizen Web application.
CSS3
HTML5
10
Files in Tizen Web Project
The config.xml file is a Web-standard deployment descriptor for the Web
application. It defines everything about the application that is required when
the application is installed and launched.
11
Files in Tizen Web Project
The Tizen SDK automatically fills in the general information with default
values, and you can change the values using the configuration editor if
necessary.
Custom icon
(It can be any .png file)
12
Files in Tizen Web Project
You can set the application configuration with various options in each tab.
Overview: Define and edit general information, such as the application name
and icon.
Features: Declare the required software and hardware features.
Privileges: Specify the APIs or API groups accessed and used.
Policy: Request network resource permissions when required to access
external network resources.
Localization: Provide localization support for name, description, and license
elements of the config.xml file.
Preferences: Declare the name-value pairs which can be set or retrieved.
Tizen: Edit the Tizen schema extension properties.
Source: View and edit the code of the config.xml file.
13
Files in Tizen Web Project
The index.html file contains source codes for the structure of the
application view.
14
Files in Tizen Web Project
HTML stands for Hyper Text Markup Language, and the HTML documents are
made up of HTML elements, which are written with a start tag, an end tag,
and contents in between.
<tagname>contents</tagname>
Everything from the start tag to the end tag is called an HTML element.
<tagname attributename=value>contents</tagname>
The list of standard HTML elements is provided by the W3C Working Group:
https://www.w3.org/TR/html-markup/elements-by-function.html
15
Files in Tizen Web Project
The following example explains the elements in a Web applications
index.html file:
index.html
<!DOCTYPE html> The DOCTYPE declaration
<html>
defines the document type
<head>
<meta charset="utf-8" /> to be HTML.
<meta name="viewport"
content="width=device-width, initial-
scale=1.0, maximum-scale=1.0">
The text between <html>
<meta name="description" and </html> describes
content="Tizen Wearable Web Basic Template" />
the entire HTML document
<title>Tizen Wearable Web Basic Application</title>
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-
scale=1.0, maximum-scale=1.0">
<meta name="description"
content="Tizen Wearable Web Basic Template" />
<body>
<div id="main" class="page">
<div class="contents">
<span id="content-text">Basic</span>
</div>
</div>
</body>
</html>
17
Files in Tizen Web Project
The css/style.css file contains the source code for specifying the layout
and the styling of the application views.
18
Files in Tizen Web Project
The CSS file is connected to the HTML file using a <link> tag in the <head>
element.
css/style.css
html,
body {
width: 100%;
height: 100%;
index.html margin: 0 auto;
<!DOCTYPE html> padding: 0;
<html> background-color: #222222;
color: #ffffff;
<head> }
... .page {
width: 100%;
<link rel="stylesheet" type="text/css" height: 100%;
href="css/style.css" /> display: table;
<script src="js/main.js"></script> }
</head> .contents {
display: table-cell;
<body> vertical-align: middle;
... text-align: center;
</body> -webkit-tap-highlight-color: transparent;
}
</html> #content-text {
font-weight: bold;
font-size: 5em;
}
19
Files in Tizen Web Project
CSS stands for Cascading Style Sheets, and it describes how HTML elements
are displayed on the screen.
selector {
property: value; /* declaration */
}
CSS selectors are used to select HTML elements based on the elements
name, ID, class, attribute, and more:
The element selectors are written written as element_name {}.
The ID selectors are written as #id_name {} .
The class selectors are written as .class_name {}.
The list of the standard HTML elements is provided in the W3C Wiki page:
https://www.w3.org/community/webed/wiki/CSS/Properties
20
Files in Tizen Web Project
The styling of the HTML elements in the index.html file is described in the
style.css file correspondingly.
css/style.css
index.html html,
<!DOCTYPE html> body {
<html> width: 100%;
height: 100%;
<head> margin: 0 auto;
... padding: 0;
background-color: #222222;
<link rel="stylesheet" type="text/css" color: #ffffff;
href="css/style.css" /> }
<script src="js/main.js"></script> .page {
</head> width: 100%;
height: 100%;
<body> display: table;
<div id="main" class="page"> }
<div class="contents"> .contents {
<span id="content- display: table-cell;
text">Basic</span> vertical-align: middle;
</div> text-align: center;
</div> -webkit-tap-highlight-color:
</body> transparent;
}
</html> #content-text {
font-weight: bold;
font-size: 5em;
}
21
Files in Tizen Web Project
The js/main.js file contains the code for handling the application
functionalities.
22
Files in Tizen Web Project
The JavaScript file is connected to the HTML file using a <script> tag in
the <head> element.
js/main.js
window.onload = function() {
// TODO:: Do your initialization job
23
Files in Tizen Web Project
JavaScript is a programming language, and consists of statements to be
executed by the program.
// Sample code
var mainPage = document.querySelector('#main');
mainPage.addEventListener("click", function() {
var contentText = document.querySelector('#content-text');
24
Files in Tizen Web Project
With JavaScript, you can:
Add behavior and user interactions
Load and change contents dynamically
Get access to device-specific features using standard Web APIs or
Tizen Web Device APIs.
For example, the following JavaScript code changes the contents of the
<span> element using the standard Web API method element.innerHTM.
index.html js/main.js
<body> // Sample code
<div id="main" class="page"> var mainPage = document.querySelector('#main');
<div class="contents"> mainPage.addEventListener("click", function()
<span id="content- {
text">Basic</span> var contentText =
</div> document.querySelector('#content-text');
</div> contentText.innerHTML =
</body> (contentText.innerHTML === "Basic") ?
"Tizen" : "Basic";
});
25
Files in Tizen Web Project
The following figure summarizes the interactions between the components:
ADDS STYLE
CALLS CALLS
CALLS
ADDS FUNCTIONALITIES
26
Implementing Tizen Web Applications
Implementing Tizen Web Applications Digital Watch
With the understanding of the basic components of Tizen Web applications,
you can create a simple digital watch application.
28
Implementation Plan
The digital watch application is implemented in 4 stages.
In Stage 1-2, the styling to the HTML elements is added using CSS
properties, including font-size and margin-top.
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="Tizen Wearable Web Basic Template" />
<body>
<div id="main" class="page">
<div class="contents">
<span id="content-text">Basic</span> Delete the unnecessary code
</div>
</div>
</body>
</html>
31
Stage 1-0: Digital Watch UI Layout Pre-setting
Delete the unnecessary code in the style.css file of the myFirstApp
application.
style.css
html,
body {
width: 100%;
height: 100%;
margin: 0 auto;
padding: 0;
background-color: #222222;
color: #ffffff;
}
.page {
width: 100%;
height: 100%;
display: table;
}
.contents {
display: table-cell;
vertical-align: middle;
text-align: center;
-webkit-tap-highlight-color: transparent;
}
#content-text {
font-weight: bold; Delete the unnecessary code
font-size: 5em;
}
32
Stage 1-0: Digital Watch UI Layout Pre-setting
Delete the unnecessary code in the main.js file of the myFirstApp
application.
main.js
window.onload = function() {
// TODO:: Do your initialization job
// Sample code
var mainPage = document.querySelector('#main');
mainPage.addEventListener("click", function() {
var contentText = document.querySelector('#content-text');
33
Stage 1-1: Digital Watch UI Layout index.html
Plan how to put each element in the index.html file.
You need an area for the time contents and another area for the date
contents. Use <div> elements to create the areas.
Then, you need texts for the hours, the colon, the minutes, the seconds, and
the date. Use <span> elements to create the texts.
Text for hour
Text for colon
Text for minute
34
Stage 1-1: Digital Watch UI Layout index.html
Put all elements in the index.html file and fill in the contents with pseudo
data.
index.html
...
<body>
<div id="main" class="page">
<div id="time-area" class="contents"> #time- #date-
<span id="hour-text">00</span> area area
<span id="colon-text">:</span>
<span id="minute-text">00</span>
<span id="second-text">00</span>
</div>
<div id="date-area" class="contents">
<span id="date-text">Mon 00 Jan</span>
</div>
</div>
</body> Add new <div> and <span> elements
...
To check how the elements are displayed right away, you can test the
application in the Web Inspector, which is a debugging tool provided for Web
applications.
36
Stage 1-2: Digital Watch UI Layout Debugging
In the Web Inspector, select an element and its placement is shown in the
emulator correspondingly.
37
Stage 1-2: Digital Watch UI Layout Debugging
Try adjusting the font size of <span id=hour-text">00</span>.
38
Stage 1-2: Digital Watch UI Layout Debugging
2. Add font-size: 100px; to element.style on the right column.
39
Stage 1-2: Digital Watch UI Layout Debugging
The next step is to actually apply the change in the style.css file.
style.css
...
.contents {
...
}
#hour-text {
font-size: 100px; Apply the change.
}
You can see that the <div> elements are aligned horizontally.
This is because the CSS display property of the <div> elements is set to
table-cell.
Next, change the code in the style.css file to align the elements vertically.
The texts are no longer aligned vertically in the middle, because the
vertical-align property does not work with the block display.
style.css
...
#hour-text {
...
}
#time-area { Add styling to the texts
margin-top: 25%;
}
#second-text, #date-text {
font-size: 40px;
}
#colon-text, #minute-text {
font-size: 100px;
}
43
Stage 1-3: Digital Watch UI Layout Summary
Your index.html file should appear as in the following example:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport"
content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="Tizen Wearable Web Basic Template" />
<title>Tizen Wearable Web Basic Application</title>
<body>
<div id="main" class="page">
<div id="time-area" class="contents">
<span id="hour-text">00</span>
<span id="colon-text">:</span>
<span id="minute-text">00</span>
<span id="second-text">00</span>
</div>
<div id="date-area" class="contents">
<span id="date-text">Mon 00 Jan</span>
</div>
</div>
</body>
</html>
44
Stage 1-3: Digital Watch UI Layout Summary
Your style.css file should appear as in the following example:
style.css
html, .contents {
body { display: block;
width: 100%; vertical-align: middle;
height: 100%; text-align: center;
margin: 0 auto; -webkit-tap-highlight-color:
padding: 0; transparent;
background-color: #222222; }
color: #ffffff; #hour-text {
} font-size: 100px;
.page { }
width: 100%; #time-area {
height: 100%; margin-top: 25%;
display: table; }
} #second-text, #date-text {
font-size: 40px;
}
The code continues on the right #colon-text, #minute-text {
font-size: 100px;
}
45
Stage 1-3: Digital Watch UI Layout Summary
Lastly, your main.js file should appear as in the following example:
main.js
window.onload = function() {
// TODO:: Do your initialization job
46
Stage 2: Digital Watch Functionality Goal
The goal of Stage 2 is to implement the functionality of the digital watch
using JavaScript and W3C standard Web API.
In Stage 2-2, create a changeTime() method using the W3C Date() API.
In Stage 2-3, create a changeDate() method using the W3C Date() API.
main.js
window.onload = function() {
// TODO:: Do your initialization job
The file contains a code block which closes the application when the back key
is pressed, but do not worry about the code details for now.
Implement a simple method which grabs an HTML element and changes its
content. The new method is named changeHTML().
The method is added above the window.onload method.
window.onload = function() {
Changes the content of
... the htmlElem element with
};
newContent
window.onload = function() {
...
};
Moreover, call the method inside the setInterval() method so that the
method gets executed every 1 second as the time changes.
main.js
...
window.onload = function() {
// TODO:: Do your initialization job
setInterval(function() {
changeTime();
}, 1000);
...
};
main.js
...
window.onload = function() {
// TODO:: Do your initialization job
setInterval(function() {
changeTime();
}, 1000);
The text for the date does not appear as we expected because the W3C
Date() API returns data for the month and day as an integer value.
Therefore, additional code is required for converting the integer values to the
corresponding string values, such as for month data, converting 0 to Jan.
54
Stage 2-3: Digital Watch Functionality changeDate()
Modify the changeDate() method so that the integer values for month and
day are converted to the corresponding string values.
main.js
function changeDate() {
var date = new Date(), Add arrays for string values
currentMonth = date.getMonth(), of month and day
currentDate = date.getDate(),
currentDay = date.getDay(),
strDate ="",
arrayMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"],
arrayDay = ["Sun", "Mon", "Tue", "Wed",
"Thu", "Fri", "Sat"];
changeHTML("date-text", strDate);
}
56
Stage 2-4: Digital Watch Functionality Summary
Your index.html file should appear as in the following example:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0">
<meta name="description" content="Tizen Wearable Web Basic Template" />
<title>Tizen Wearable Web Basic Application</title>
<body>
<div id="main" class="page">
<div id="time-area" class="contents">
<span id="hour-text">00</span>
<span id="colon-text">:</span>
<span id="minute-text">00</span>
<span id="second-text">00</span>
</div>
<div id="date-area" class="contents">
<span id="date-text">Mon 00 Jan</span>
</div>
</div>
</body>
</html>
57
Stage 2-4: Digital Watch Functionality Summary
Your style.css file should appear as in the following example:
style.css
html, .contents {
body { display: block;
width: 100%; vertical-align: middle;
height: 100%; text-align: center;
margin: 0 auto; -webkit-tap-highlight-color:
padding: 0; transparent;
background-color: #222222; }
color: #ffffff; #hour-text {
} font-size: 100px;
.page { }
width: 100%; #time-area {
height: 100%; margin-top: 25%;
display: table; }
} #second-text, #date-text {
font-size: 40px;
}
The code continues on the right. #colon-text, #minute-text {
font-size: 100px;
}
58
Stage 2-4: Digital Watch Functionality Summary
Lastly, your main.js file should appear as in the following example:
main.js
function changeHTML(elemId, newContent) {
var htmlElem = document.getElementById(elemId);
htmlElem.innerHTML = newContent;
}
59
Stage 2-4: Digital Watch Functionality Summary
main.js
function changeTime() {
var date = new Date(),
currentHour = date.getHours(),
currentMinute = date.getMinutes(),
currentSecond = date.getSeconds();
// Make the hour, minute, and second texts show as double-digit numbers
if (currentHour < 10) {
changeHTML("hour-text", "0" + currentHour);
} else {
changeHTML("hour-text", currentHour);
}
main.js
function changeDate() {
var date = new Date(),
currentMonth = date.getMonth(),
currentDate = date.getDate(),
currentDay = date.getDay(),
strDate ="",
arrayMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
arrayDay = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
currentMonth = arrayMonth[currentMonth];
currentDay = arrayDay[currentDay];
changeHTML("date-text", strDate);
}
61
Stage 2-4: Digital Watch Functionality Summary
main.js
window.onload = function() {
// TODO:: Do your initialization job
setInterval(function() {
changeTime();
}, 1000);
changeDate();
62
Stage 3: Battery UI Layout Goal
The goal of Stage 3 is to implement the user interface layout for the battery,
and add a background image to the digital watch application using HTML and
CSS.
In Stage 3-1, define the layout of the digital watch application using
the HTML <div> elements.
In Stage 3-2, add styling to the HTML elements using CSS properties,
including a border and a background.
63
Stage 3-1: Battery UI Layout index.html
Plan how to place each element in the index.html file .
You need to create an area using <div> elements for the container of the
battery element.
You need to create another area using <div> elements inside the container
area for the actual battery element, which is filled accordingly with the battery
level.
64
Stage 3-1: Battery UI Layout index.html
Add a new <div> element with a battery-container ID on top of the
<div> element with a time-area ID, and add another <div> element
with a battery-fill ID inside the new <div> element.
index.html
...
<div id="main" class="page">
<div id="battery-container">
<div id="battery-fill"></div>
</div>
<div id="time-area" class="contents">
<span id="hour-text">00</span>
<span id="colon-text">:</span>
<span id="minute-text">00</span>
<span id="second-text">00</span>
</div>
<div id="date-area" class="contents">
<span id="date-text">Mon 00 Jan</span>
</div>
</div>
...
At the moment, you cannot see any change on the screen because the
<div> elements are empty. Next, add some styling to the <div> elements
so that it appears properly as a battery element.
65
Stage 3-2: Battery UI Layout style.css
Add styling for the <div> element with the battery-container ID.
style.css
...
#colon-text, #minute-text {
font-size: 100px;
}
#battery-container {
Add styling for the #battery-
position: absolute;
width: 10%; container.
height: 5%;
top: 20%;
left: 63%;
border: solid 2px white;
}
#battery-container {
position: absolute;
width: 10%;
height: 5%;
top: 20%;
left: 63%;
border: solid 2px white;
}
#battery-fill {
width: 50%; Add styling for the
height: 100%;
background-color: white; #battery-fill.
}
68
Stage 3-2: Battery UI Layout Adding Files
When the New Folder pop-up appears, fill in the folder name as image, and
click Finish.
69
Stage 3-2: Battery UI Layout Adding Files
Copy the image file from a local directory to the project folder by dragging
and dropping the file to the image folder in Project Explorer.
You can use any image file from your local directory. Just rename the file as
bg.jpg
70
Stage 3-2: Battery UI Layout Adding Files
When the File Operation pop-up appears, select Copy files, and click OK.
The image file (bg.jpg) has been added in the Project Explorer.
71
Stage 3-2: Battery UI Layout style.css
In the style.css file, add the background image for the html, body
element.
style.css
html,
body {
... Add the background image.
background-color: #222222;
background-image: url('../image/bg.jpg');
background-size: 100%;
color: #ffffff;
}
...
The Stage 3 is now completed, and the battery element
and background image are implemented.
style.css
Stage 3-3: Battery UI Layout Summary
By the end of Stage 3, your application should appear as in the following
figure:
73
Stage 3-3: Battery UI Layout Summary
Your index.html file should appear as in the following example:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<meta name="description" content="Tizen Wearable Web Basic Template" />
74
Stage 3-3: Battery UI Layout Summary
index.html
<body>
<div id="main" class="page">
<div id="battery-container">
<div id="battery-fill"></div>
</div>
<div id="time-area" class="contents">
<span id="hour-text">00</span>
<span id="colon-text">:</span>
<span id="minute-text">00</span>
<span id="second-text">00</span>
</div>
<div id="date-area" class="contents">
<span id="date-text">Mon 00 Jan</span>
</div>
</div>
</body>
</html>
75
Stage 3-3: Battery UI Layout Summary
Your style.css file should appear as in the following example:
style.css
html, #time-area {
body { margin-top: 25%;
width: 100%; }
height: 100%;
margin: 0 auto; #second-text, #date-text {
padding: 0; font-size: 40px;
background-color: #222222; }
background-image:
url('../image/bg.jpg'); #colon-text, #minute-text {
background-size: 100%; font-size: 100px;
color: #ffffff; }
} #battery-container {
.page { position: absolute;
width: 100%; width: 10%;
height: 100%; height: 5%;
display: table; top: 20%;
} left: 63%;
.contents { border: solid 2px white;
display: block; }
vertical-align: middle;
text-align: center; #battery-fill {
-webkit-tap-highlight-color: width: 50%;
transparent; height: 100%;
} background-color: white;
#hour-text { }
font-size: 100px;
}
htmlElem.innerHTML = newContent;
}
77
Stage 3-3: Battery UI Layout Summary
main.js
function changeTime() {
var date = new Date(),
currentHour = date.getHours(),
currentMinute = date.getMinutes(),
currentSecond = date.getSeconds();
// Make the hour, minute, and second texts show as double-digit numbers
if (currentHour < 10) {
changeHTML("hour-text", "0" + currentHour);
} else {
changeHTML("hour-text", currentHour);
}
main.js
function changeDate() {
var date = new Date(),
currentMonth = date.getMonth(),
currentDate = date.getDate(),
currentDay = date.getDay(),
strDate ="",
arrayMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
arrayDay = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
currentMonth = arrayMonth[currentMonth];
currentDay = arrayDay[currentDay];
changeHTML("date-text", strDate);
}
79
Stage 3-3: Battery UI Layout Summary
main.js
window.onload = function() {
// TODO:: Do your initialization job
setInterval(function() {
changeTime();
}, 1000);
changeDate();
80
Stage 4: Battery Functionality Goal
The goal of Stage 4 is to implement the functionality of the battery indicator
using JavaScript and the Tizen Device API.
81
Stage 4-1: Battery Functionality config.xml
Tizen provides API-level access control for security-sensitive operations
which, if not used correctly, can harm user privacy and system stability.
Therefore, applications that use such sensitive APIs must declare the
required privileges in the config.xml file.
To use the Tizen System Information API for getting the data on the battery
level, first learn how to declare the privilege.
83
Stage 4-1: Battery Functionality config.xml
In the Privileges tab, click + (Add).
84
Stage 4-1: Battery Functionality config.xml
Enter system in the textbox, select
http://tizen.org/privilege/system in the list, and click Finish.
85
Stage 4-1: Battery Functionality config.xml
The http://tizen.org/privilege/system privilege has been added.
86
Stage 4-1: Battery Functionality config.xml
A new line for tizen:privilege has been added in the config.xml file.
You are now ready to use the Tizen System Information API.
87
Stage 4-2: Battery Functionality changeBattery()
Implement a function which gets the battery level of the system using the
Tizen System Information API and changes the battery indicator accordingly.
main.js
...
function changeDate() {
...
}
function changeBattery() {
function onSuccessCallback(battery) {
document.getElementById("battery-fill").style.width = (battery.level * 100) + "%";
}
function onErrorCallback(error) {
alert("Not supported: " + error.message);
}
tizen.systeminfo.addPropertyValueChangeListener("BATTERY", onSuccessCallback,
onErrorCallback);
}
window.onload = function() {
...
};
main.js
...
window.onload = function() {
// TODO:: Do your initialization job
setInterval(function() {
changeTime();
}, 1000);
You can use the Event Injector in the Emulator Control Panel to artificially
create and use any data, including the battery state and level, required
during application execution.
90
Stage 4-2: Battery Functionality changeBattery()
In the Emulator Control Panel, select Battery under Event Injector Category.
91
Stage 4-2: Battery Functionality changeBattery()
Try adjusting the battery level, and confirm that the battery indicator of the
digital watch application changes accordingly.
93
Stage 4-3: Battery Functionality Summary
Your index.html file should appear as in the following example:
index.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-
scale=1.0">
<meta name="description" content="Tizen Wearable Web Basic Template" />
94
Stage 4-3: Battery Functionality Summary
index.html
<body>
<div id="main" class="page">
<div id="battery-container">
<div id="battery-fill"></div>
</div>
<div id="time-area" class="contents">
<span id="hour-text">00</span>
<span id="colon-text">:</span>
<span id="minute-text">00</span>
<span id="second-text">00</span>
</div>
<div id="date-area" class="contents">
<span id="date-text">Mon 00 Jan</span>
</div>
</div>
</body>
</html>
95
Stage 4-3: Battery Functionality Summary
Your style.css file should appear as in the following example:
style.css
html, #time-area {
body { margin-top: 25%;
width: 100%; }
height: 100%;
margin: 0 auto; #second-text, #date-text {
padding: 0; font-size: 40px;
background-color: #222222; }
background-image:
url('../image/bg.jpg'); #colon-text, #minute-text {
background-size: 100%; font-size: 100px;
color: #ffffff; }
} #battery-container {
.page { position: absolute;
width: 100%; width: 10%;
height: 100%; height: 5%;
display: table; top: 20%;
} left: 63%;
.contents { border: solid 2px white;
display: block; }
vertical-align: middle;
text-align: center; #battery-fill {
-webkit-tap-highlight-color: width: 50%;
transparent; height: 100%;
} background-color: white;
#hour-text { }
font-size: 100px;
}
htmlElem.innerHTML = newContent;
}
97
Stage 4-3: Battery Functionality Summary
main.js
function changeTime() {
var date = new Date(),
currentHour = date.getHours(),
currentMinute = date.getMinutes(),
currentSecond = date.getSeconds();
// Make the hour, minute, and second texts show as double-digit numbers
if (currentHour < 10) {
changeHTML("hour-text", "0" + currentHour);
} else {
changeHTML("hour-text", currentHour);
}
main.js
function changeDate() {
var date = new Date(),
currentMonth = date.getMonth(),
currentDate = date.getDate(),
currentDay = date.getDay(),
strDate ="",
arrayMonth = ["Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec" ],
arrayDay = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
currentMonth = arrayMonth[currentMonth];
currentDay = arrayDay[currentDay];
changeHTML("date-text", strDate);
}
99
Stage 4-3: Battery Functionality Summary
main.js
function changeBattery() {
function onSuccessCallback(battery) {
document.getElementById("battery-fill").style.width = (battery.level * 100) + "%";
}
function onErrorCallback(error) {
alert("Not supported: " + error.message);
}
tizen.systeminfo.addPropertyValueChangeListener("BATTERY", onSuccessCallback,
onErrorCallback);
}
100
Stage 4-3: Battery Functionality Summary
main.js
window.onload = function() {
// TODO:: Do your initialization job
setInterval(function() {
changeTime();
}, 1000);
changeDate();
101