DigitalWatch Sample Overview
The DigitalWatch sample application demonstrates how you can create a simple digital watch application.
For information on creating the sample application project in the IDE, see Creating Web Sample Applications.
The following figure illustrates the main screen of the DigitalWatch.
Figure: DigitalWatch screen
The application opens with the main screen that shows the current time and battery status.
Source Files
You can create and view the sample application project including the source files in the IDE.
File name | Description |
---|---|
config.xml | This file contains the application information for the platform to install and launch the application, including the view mode and the icon to be used in the device menu. |
css/ | This directory contains the CSS styling for the application UI. |
index.html | This is a starting file from which the application starts loading. It contains the layout of the application screens. |
js/ | This directory contains the application code. |
Implementation
The config.xml application configuration file contains a specified http://tizen.org/category/wearable_clock category:
<?xml version="1.0" encoding="UTF-8"?> <widget xmlns="http://www.w3.org/ns/widgets"> <tizen:category name="http://tizen.org/category/wearable_clock" /> </widget>
The following code snippet adds an event handler for battery events:
battery.addEventListener('chargingchange', getBatteryState); battery.addEventListener('chargingtimechange', getBatteryState); battery.addEventListener('dischargingtimechange', getBatteryState); battery.addEventListener('levelchange', getBatteryState);
To retrieve the required details:
-
Get the battery level (0 - 100):
var battery_level = Math.floor(battery.level * 100);
-
Get the current time object:
date = tizen.time.getCurrentDateTime();
-
Get the current weekday (MON - SUN):
day = date.getDay();
-
Get the current month (0 - 11) and day (1 - 31):
month = date.getMonth() + 1, day = date.getDate();
-
Get the current hour (0 - 23), minutes (0 - 59), and seconds (0 - 59):
str_hours = date.getHours(); str_minutes = date.getMinutes(); str_second = date.getSeconds();