[ClassicWatch] document created
authorBoyeon Son <boyeon.son@samsung.com>
Mon, 25 Apr 2016 02:34:50 +0000 (11:34 +0900)
committerBoyeon Son <boyeon.son@samsung.com>
Mon, 25 Apr 2016 09:08:18 +0000 (18:08 +0900)
patch 2: added descriptiion for event listeners

Change-Id: I4a86630c7920e5c9ce220594df0a11eec0da10eb

org.tizen.sampledescriptions/html/images/classicwatch_ww.png [new file with mode: 0644]
org.tizen.sampledescriptions/html/wearable_w/classicwatch_ww.htm [new file with mode: 0644]

diff --git a/org.tizen.sampledescriptions/html/images/classicwatch_ww.png b/org.tizen.sampledescriptions/html/images/classicwatch_ww.png
new file mode 100644 (file)
index 0000000..17b5cfe
Binary files /dev/null and b/org.tizen.sampledescriptions/html/images/classicwatch_ww.png differ
diff --git a/org.tizen.sampledescriptions/html/wearable_w/classicwatch_ww.htm b/org.tizen.sampledescriptions/html/wearable_w/classicwatch_ww.htm
new file mode 100644 (file)
index 0000000..27581f5
--- /dev/null
@@ -0,0 +1,318 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
+<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
+<head>
+    <meta http-equiv="content-type" content="text/html; charset=utf-8" />
+    <meta http-equiv="X-UA-Compatible" content="IE=9" />
+    <link rel="stylesheet" type="text/css" href="../css/styles.css" />
+    <link rel="stylesheet" type="text/css" href="../css/snippet.css" />
+    <script type="text/javascript" src="../scripts/snippet.js"></script>
+    <script type="text/javascript" src="../scripts/jquery.util.js" charset="utf-8"></script>
+    <script type="text/javascript" src="../scripts/common.js" charset="utf-8"></script>
+    <script type="text/javascript" src="../scripts/core.js" charset="utf-8"></script>
+    <script type="text/javascript" src="../scripts/search.js" charset="utf-8"></script>
+
+    <title>Classic Watch Sample Overview</title>
+</head>
+
+<body onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+    <div id="profile">
+        <p><img alt="Wearable Web" src="../images/wearable_s_w.png"/></p>
+    </div>
+    <div id="toc_border">
+    <div id="toc">
+        <p class="toc-title">Related Info</p>
+        <ul class="toc">
+            <li><a href="../../../org.tizen.web.apireference/html/device_api/wearable/tizen/time.html">Time API</a></li>
+       </ul>
+    </div>
+    </div>
+</div>
+
+<div id="container"><div id="contents"><div class="content">
+  <h1>Classic Watch Sample Overview</h1>
+ <p>The Classic Watch sample application demonstrates how you can implement a simple watchface application.</p>
+ <p>For information on creating the sample application project in the IDE, see <a href="../cover_page.htm#create">Creating Web Sample Applications</a>.</p>
+ <p>The following figure illustrates the main screen of the Classic Watch application.</p>
+ <p class="figure">Figure: Classic Watch screen</p>
+ <p align="center">
+     <img alt="Classic Watch screen" src="../images/classicwatch_ww.png" />
+ </p>
+ <p>The application opens with the main screen that shows the current time in an analog watchface.</p>
+
+
+ <h2>Source Files</h2>
+ <p>You can create and view the sample application project including the source files in the IDE.</p>
+ <table border="1">
+ <caption>Table: Source files</caption>
+ <tbody>
+ <tr>
+ <th>File name</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">config.xml</span></td>
+ <td>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.</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">css/style.css</span></td>
+ <td>This file contains the CSS styling for the application UI.</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">index.html</span></td>
+ <td>This is a starting file from which the application starts loading. It contains the layout of the application screens.</td>
+ </tr>
+ <tr>
+ <td><span style="font-family: Courier New,Courier,monospace">js/app.js</span></td>
+ <td>This file starts the application and music controls.</td>
+ </tr>
+ </tbody>
+ </table>
+
+ <h2>Implementation</h2>
+ <h3>Defining the Category for Watchface Application</h3>
+ <p>The <span style="font-family: Courier New,Courier,monospace">config.xml</span> must contain a specific category (<span style="font-family: Courier New,Courier,monospace">http://tizen.org/category/wearable_clock</span>) for watchface applications.</p>
+ <pre class="prettyprint">
+&lt;!--config.xml--&gt;
+
+&lt;?xml version="1.0" encoding="UTF-8"?&gt;
+&lt;widget xmlns="http://www.w3.org/ns/widgets" xmlns:tizen="http://tizen.org/ns/widgets" id="http://yourdomain/ClassicWatch" version="1.0.0" viewmodes="maximized"&gt;
+    &lt;tizen:category name="http://tizen.org/category/wearable_clock"/&gt;
+&lt;/widget&gt; </pre>
+
+ <h3>Defining the Application Layout</h3>
+ <p>To define the application layout for the watchface application:</p>
+<ol>
+<li>
+ <p>Create  <span style="font-family: Courier New,Courier,monospace">&lt;div&gt;</span> element for each component in  <span style="font-family: Courier New,Courier,monospace">index.html</span>.</p>
+ <pre class="prettyprint">
+&lt;!--index.html--&gt;
+
+&lt;!-- Watch Page --&gt;
+&lt;div id="watch-bg"&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- Watch Page : Date --&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="date-bg"&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="date-text"&gt;&lt;/div&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;/div&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- Watch Page : Hour --&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="hands-hr-needle" class="hands-hr"&gt;&lt;/div&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="hands-hr-shadow" class="hands-hr"&gt;&lt;/div&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- Watch Page : Minute --&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="hands-min-needle" class="hands-min"&gt;&lt;/div&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="hands-min-shadow" class="hands-min"&gt;&lt;/div&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;!-- Watch Page : Second --&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="hands-sec-needle" class="hands-sec"&gt;&lt;/div&gt;
+&nbsp;&nbsp;&nbsp;&nbsp;&lt;div id="hands-sec-shadow" class="hands-sec"&gt;&lt;/div&gt;
+&lt;/div&gt;</pre>
+ </li>
+
+ <li>
+ <p>Set styles for the background of the watchface in <span style="font-family: Courier New,Courier,monospace">style.css</span>.</p>
+ <pre class="prettyprint">
+&lt;!--css/style.css--&gt;
+
+/*-------WATCH PAGE-------*/
+
+#watch-bg {
+&nbsp;&nbsp;&nbsp;&nbsp;width: 100%;
+&nbsp;&nbsp;&nbsp;&nbsp;height: 100%;
+&nbsp;&nbsp;&nbsp;&nbsp;position: absolute;
+&nbsp;&nbsp;&nbsp;&nbsp;background-image: url('../image/lux_3_bg_01.png');
+&nbsp;&nbsp;&nbsp;&nbsp;overflow: hidden;
+} </pre>
+ </li>
+
+ <li>
+ <p>Set styles for the hands of the watchface in <span style="font-family: Courier New,Courier,monospace">style.css</span> as well.</p>
+ <p>For example, the hour hand can be described as:</p>
+ <pre class="prettyprint">
+&lt;!--css/style.css--&gt;
+
+/*-------WATCH PAGE : HOUR-------*/
+
+.hands-hr {
+  &nbsp;&nbsp;&nbsp;&nbsp;width: 30px;
+  &nbsp;&nbsp;&nbsp;&nbsp;height: 260px;
+  &nbsp;&nbsp;&nbsp;&nbsp;position: absolute;
+  &nbsp;&nbsp;&nbsp;&nbsp;top: 50px;
+  &nbsp;&nbsp;&nbsp;&nbsp;left: 165px;
+  &nbsp;&nbsp;&nbsp;&nbsp;background-size: 30px 260px;
+}
+
+#hands-hr-needle {
+&nbsp;&nbsp;&nbsp;&nbsp;z-index: 2;
+&nbsp;&nbsp;&nbsp;&nbsp;background-image: url('../image/lux_3_hands_hr.png');
+}
+
+#hands-hr-shadow {
+&nbsp;&nbsp;&nbsp;&nbsp;z-index: 1;
+&nbsp;&nbsp;&nbsp;&nbsp;top: 54px;
+&nbsp;&nbsp;&nbsp;&nbsp;opacity: 0.5;
+&nbsp;&nbsp;&nbsp;&nbsp;background-image: url('../image/lux_3_hands_hr_shadow.png');
+} </pre>
+ </li>
+</ol>
+
+<h3>Displaying the Current Time</h3>
+
+<p>To display the current time:</p>
+
+<ol>
+ <li>
+ <p>Define a function for rotating elements with a specific class name. It will be used to rotate hand elements.</p>
+ <pre class="prettyprint">
+/* js/app.js */
+
+function rotateElements(angle, className) {
+&nbsp;&nbsp;&nbsp;&nbsp;var elements = document.querySelectorAll("." + className),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;i;
+
+&nbsp;&nbsp;&nbsp;&nbsp;for (i = 0; i &lt; elements.length; i++) {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;elements[i].style.transform = "rotate(" + angle + "deg)";
+&nbsp;&nbsp;&nbsp;&nbsp;}
+} </pre>
+ </li>
+
+ <li>
+ <p>Use the <span style="font-family: Courier New,Courier,monospace">getCurrentDateTime()</span> method of the Time API to get the current time object, and rotate each hand element accordingly.</p>
+ <pre class="prettyprint">
+/* js/app.js */
+
+function updateTime() {
+&nbsp;&nbsp;&nbsp;&nbsp;var datetime = tizen.time.getCurrentDateTime(),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;hour = datetime.getHours(),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;minute = datetime.getMinutes(),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;second = datetime.getSeconds();
+
+&nbsp;&nbsp;&nbsp;&nbsp;// Update the hour/minute/second hands
+&nbsp;&nbsp;&nbsp;&nbsp;rotateElements((hour + (minute / 60) + (second / 3600)) * 30, "hands-hr");
+&nbsp;&nbsp;&nbsp;&nbsp;rotateElements((minute + second / 60) * 6, "hands-min");
+&nbsp;&nbsp;&nbsp;&nbsp;rotateElements(second * 6, "hands-sec");
+} </pre>
+ </li>
+</ol>
+
+<h3>Displaying the Current Date</h3>
+
+<p>To display the current date:</p>
+
+<ol>
+ <li>
+ <p>Use the <span style="font-family: courier new,courier,monospace">getCurrentDateTime()</span> method of the Time API to get the current date object, and update the text for the date element.</p>
+ <pre class="prettyprint">
+/* js/app.js */
+
+function updateDate(prevDate) {
+&nbsp;&nbsp;&nbsp;&nbsp;var datetime = tizen.time.getCurrentDateTime(),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;date = datetime.getDate(),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextInterval;
+
+&nbsp;&nbsp;&nbsp;&nbsp;// Update the text for date
+&nbsp;&nbsp;&nbsp;&nbsp;if (date &lt; 10) {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.querySelector("#date-text").innerHTML = "0" + date;
+&nbsp;&nbsp;&nbsp;&nbsp;} else {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.querySelector("#date-text").innerHTML = date;
+&nbsp;&nbsp;&nbsp;&nbsp;}
+} </pre>
+ </li>
+
+ <li>
+ <p>Set a refresh callback to update the date on the next day.</p>
+ <pre class="prettyprint">
+/* js/app.js */
+
+function updateDate(prevDate) {
+&nbsp;&nbsp;&nbsp;&nbsp;var datetime = tizen.time.getCurrentDateTime(),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;date = datetime.getDate(),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextInterval;
+
+&nbsp;&nbsp;&nbsp;&nbsp;// Check the update condition
+&nbsp;&nbsp;&nbsp;&nbsp;// If prevDate is '0', it will always update the date
+&nbsp;&nbsp;&nbsp;&nbsp;if (prevDate === date) {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * If the date was not changed (meaning that something went wrong),
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * call updateDate again after a second
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextInterval = 1000;
+&nbsp;&nbsp;&nbsp;&nbsp;} else {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;/*
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * If the date was changed,
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; * call updateDate at the beginning of the next day
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; */
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;// Calculate how much time is left until the next day
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;nextInterval = (23 - datetime.getHours()) * 60 * 60 * 1000 +
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(59 - datetime.getMinutes()) * 60 * 1000 +
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(59 - datetime.getSeconds()) * 1000 +
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;(1000 - datetime.getMilliseconds()) + 1;
+&nbsp;&nbsp;&nbsp;&nbsp;}
+
+&nbsp;&nbsp;&nbsp;&nbsp;// If an updateDate timer already exists, clear the previous timer
+&nbsp;&nbsp;&nbsp;&nbsp;if (timerUpdateDate) {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;clearTimeout(timerUpdateDate);
+&nbsp;&nbsp;&nbsp;&nbsp;}
+
+&nbsp;&nbsp;&nbsp;&nbsp;// Set next timeout for date update
+&nbsp;&nbsp;&nbsp;&nbsp;timerUpdateDate = setTimeout(function() {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateDate(date);
+&nbsp;&nbsp;&nbsp;&nbsp;}, nextInterval);
+}</pre>
+ </li>
+</ol>
+
+<h3>Adding Event Listeners</h3>
+
+<ul>
+ <li>
+ <p>Add an event listener for <span style="font-family: courier new,courier,monospace">visibilitychange</span> to update the screen immediately when the device wakes up.</p>
+ </li>
+ <li>
+ <p>Add the <span style="font-family: courier new,courier,monospace">setTimezoneChangeListener()</span> method of the Tizen Time API to update the screen when the time zone is changed.</p>
+ </li>
+ <pre class="prettyprint">
+/* js/app.js */
+
+function init() {
+&nbsp;&nbsp;&nbsp;&nbsp;// Add eventListener to update the screen immediately when the device wakes up
+&nbsp;&nbsp;&nbsp;&nbsp;document.addEventListener("visibilitychange", function() {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if (!document.hidden) {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateTime();
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateDate(0);
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}
+&nbsp;&nbsp;&nbsp;&nbsp;});
+
+&nbsp;&nbsp;&nbsp;&nbsp;// Add eventListener to update the screen when the time zone is changed
+&nbsp;&nbsp;&nbsp;&nbsp;tizen.time.setTimezoneChangeListener(function() {
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateTime();
+&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;updateDate(0);
+&nbsp;&nbsp;&nbsp;&nbsp;});
+} </pre>
+
+</ul>
+
+
+
+
+<script type="text/javascript" src="../scripts/jquery.zclip.min.js"></script>
+<script type="text/javascript" src="../scripts/showhide.js"></script>
+</div></div></div>
+
+<a class="top sms" href="#"><img src="../images/btn_top.gif" alt="Go to top" /></a>
+
+<div id="footer">
+<p class="footer">Except as noted, this content - excluding the Code Examples - is licensed under <a href="http://creativecommons.org/licenses/by/3.0/legalcode" target="_blank">Creative Commons Attribution 3.0</a> and all of the Code Examples contained herein are licensed under <a href="https://www.tizen.org/bsd-3-clause-license" target="_blank">BSD-3-Clause</a>.<br/>For details, see the <a href="https://www.tizen.org/content-license" target="_blank">Content License</a>.</p>
+</div>
+
+<script type="text/javascript">
+var _gaq = _gaq || [];
+_gaq.push(['_setAccount', 'UA-25976949-1']);
+_gaq.push(['_trackPageview']);
+(function() {
+var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
+ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
+var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
+})();
+</script>
+
+</body>
+</html>