--- /dev/null
+<!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>Stop Watch Sample Overview</title>
+</head>
+
+<body class="no-toc" onload="prettyPrint()" style="overflow: auto;">
+
+<div id="toc-navigation">
+</div>
+
+<div id="container"><div id="contents"><div class="content">
+ <div id="profile">
+ <p><img alt="Mobile native" src="../images/mobile_s_n.png"/></p>
+ </div>
+ <h1>Stop Watch Sample Overview</h1>
+
+<p>The Stop watch sample application demonstrates how you can implement a simple stop watch application. The application's user interface consists of a single window, two layouts
+and five buttons.</p>
+
+ <p class="figure">Figure: Application views</p>
+ <p align="center">
+ <img alt="Stop watch view" src="../images/stop_watch_0.png" />
+ </p>
+
+<p>
+
+<p>This application lets you measure the total time and up to 999 laps' times.</p>
+
+<h2>Implementation</h2>
+
+<h3>Main controller</h3>
+
+<p>The time measurement is based on <span style="font-family: Courier New,Courier,monospace">Ecore_Timer</span>.
+The <span style="font-family: Courier New,Courier,monospace">__timer_cb()</span> callback function is called roughly every 10 ms. It is used to
+increment the total time that has passed. It does so by calling the <span style="font-family: Courier New,Courier,monospace">tm_add_milis()</span>
+function from the model module.</p>
+
+<pre class="prettyprint">
+static Eina_Bool __timer_cb(void *data)
+{
+ double tmp = 0.0;
+
+ if (last_timestamp < 0.0)
+ return ECORE_CALLBACK_RENEW;
+
+ tmp = 1000.0 * ecore_time_get();
+ tm_add_milis((int)(tmp - last_timestamp));
+ last_timestamp = tmp;
+ view_update_time(tm_get_milis());
+
+ return ECORE_CALLBACK_RENEW;
+}
+</pre>
+
+<p>Another important function is the <span style="font-family: Courier New,Courier,monospace">__ui_cb()</span> callback function. It responds to any UI events, such as:</p>
+<ul>
+<li><span style="font-family: Courier New,Courier,monospace">UI_EVENT_START_RESUME</span>,</li>
+<li><span style="font-family: Courier New,Courier,monospace">UI_EVENT_STOP</span>,</li>
+<li><span style="font-family: Courier New,Courier,monospace">UI_EVENT_LAP</span>,</li>
+<li><span style="font-family: Courier New,Courier,monospace">UI_EVENT_RESET</span>.</li>
+</ul>
+
+<pre class="prettyprint">
+static void __ui_cb(ui_event_e event)
+{
+ int id = 0;
+ int time = 0;
+ int mark = 0;
+
+ switch (event) {
+ case UI_EVENT_START_RESUME:
+ last_timestamp = 1000.0 * ecore_time_get();
+ break;
+ case UI_EVENT_STOP:
+ last_timestamp = -1.0;
+ break;
+ case UI_EVENT_LAP:
+ if (!tm_store_lap()) {
+ view_show_warn("Maximum number of stopwatch records 999 reached");
+ return;
+ }
+ view_toggle_laps_list(true);
+ if (tm_get_last_lap(&id, &time, &mark))
+ view_add_lap(id, time, mark);
+ break;
+ case UI_EVENT_RESET:
+ tm_reset_milis();
+ view_update_time(tm_get_milis());
+ view_toggle_laps_list(false);
+ view_clear_laps();
+ break;
+ }
+}
+</pre>
+
+<h3>Model</h3>
+
+<p>The <span style="font-family: Courier New,Courier,monospace">tm_add_milis()</span> function is used to update the total time counter.</p>
+
+<pre class="prettyprint">
+void tm_add_milis(int miliseconds)
+{
+ if (miliseconds < 0)
+ return;
+
+ if (((int64_t)data.current_milis + (int64_t)miliseconds) >= (int64_t)INT_MAX) {
+ data.current_milis = INT_MAX;
+ } else {
+ data.current_milis += miliseconds;
+ }
+}
+</pre>
+
+<p>The <span style="font-family: Courier New,Courier,monospace">tm_store_lap()</span> function stores the current lap in the list.</p>
+<pre class="prettyprint">
+bool tm_store_lap(void)
+{
+ int base = 0;
+ lap_t *new_lap = NULL;
+
+ if (eina_list_count(data.laps) >= MAX_NUM_OF_LAPS)
+ return false;
+
+ if (eina_list_count(data.laps) <= 0) {
+ base = data.current_milis;
+ } else {
+ base = ((lap_t *)eina_list_data_get(data.laps))->lap_mark;
+ }
+
+ new_lap = (lap_t *)malloc(sizeof(lap_t));
+
+ if (!new_lap)
+ return false;
+
+ new_lap->lap_mark = data.current_milis;
+ new_lap->lap_time = data.current_milis - base;
+ data.laps = eina_list_prepend(data.laps, new_lap);
+
+ return true;
+}
+</pre>
+
+<p>The <span style="font-family: Courier New,Courier,monospace">tm_get_last_lap()</span> function is useful when it is necessary to obtain the last lap's parameters,
+for example when you want to extend the view list.</p>
+<pre class="prettyprint">
+bool tm_get_last_lap(int *id, int *time, int *mark)
+{
+ int list_len = 0;
+ lap_t *lap = NULL;
+
+ list_len = eina_list_count(data.laps);
+
+ if (list_len == 0)
+ return false;
+
+ if (id)
+ *id = list_len;
+
+ lap = eina_list_nth(data.laps, 0);
+
+ if (!lap)
+ return false;
+
+ if (time)
+ *time = lap->lap_time;
+
+ if (mark)
+ *mark = lap->lap_mark;
+
+ return true;
+}
+</pre>
+
+<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>