使用Tizen泰泽Time API的秒表
Stopwatch is a time based utility that can be used to measure the amount of time elapsed from a particular time until a time of interest reached or an event occurs.秒表是一个基于时间的使用工具,用来测量从特定时间到感兴趣的时间点或事件发生时刻的时间总数。
Using the application
使用应用程序
There are three buttons. Initially all buttons are enabled.
这里有3个按钮。首先所有按钮可用。
1. Start: - Initially the stopwatch is in zero position, “00:00:00:000”. On pressing the “Start” button, the stopwatch starts counting the time elapsed from the point of start.
1.开始: 首先秒表停在"00:00:00:000"。在按了"开始"按钮,秒表开始计时。
After clicking on the “Start” button, “Reset” and “Start” buttons are disabled and “Stop” button is enabled.
在点击"开始"按钮后,"重置"和"开始"按钮不可用。"停止"按钮可用。
2. Stop: - On pressing the “Stop” button, the calculation of elapsed time gets stopped and is shown by the stopwatch.
2.关闭:按了"停止"按钮,停止计数,并且显示在秒表上。
After clicking on the “Stop” button, “Start’ and “Reset” buttons are enabled and “Stop” button is disabled.
在按了"停止"按钮,"重置"按钮可用,"停止"按钮不可用。
3. Reset: - On pressing the “Reset” button, stopwatch is reset to the initial position i.e. “00:00:00:000”.
3.重置:在按了"重置"按钮后,秒表重置时间到"00:00:00:000"。
After clicking on the “Reset” button “Start” button is enabled and “Reset” and “Stop” buttons are disabled.
按了"重置"按钮后,"开始"按钮可用,"重置", "停止"按钮不可用。
https://developer.tizen.org/sites/default/files/resize/users/user-1529/stopwatch_published-240x400.pngFig: Snap shot of stopwatch 秒表截屏Code snippet to start stopwatch
开始秒表的代码片段
Initially the position of stopwatch is zero. Clicking on the “Start” button fetches the current time and invokes the Counter() method, which counts the difference between the current and the start time. ”setTimeout()” is a callback method used for calling the Counter() in every 10 milliseconds.
秒表的最初位置是0。单击"开始"按钮,获取当前时间并调用Counter()方法,计算当前和开始时间的差异。setTimeout()是一个回调函数,用于每10毫秒调用Counter()函数。
function Start() {
startTime
= tizen.time.getCurrentDateTime();
Counter();
...}//code snippet for counter
function Counter() {
var duration = tizen.time.getCurrentDateTime().difference(startTime);
Refresh = setTimeout('Counter()',10);
Time_format(duration.length + Diff);
...}
Code snippet to stop stopwatch
停止秒表代码片段
After clicking on the “Stop” button, the counter stops and shows the difference between the stop and the start time. ”clearTimeout()” method is used to clear the interval.
单击"停止"按钮,计数器停止,并显示差异时间。
function Stop() {
clearTimeout
(Refresh);
var duration = tizen.time.getCurrentDateTime().difference(startTime);
Diff += duration.length;
...}
Code snippet to reset stopwatch
重置秒表代码片段
After clicking on the “Reset” button, the stopwatch is set to initial position. Zero is assigned to the global variable Diff.
按下"重置"按钮后,秒表设为初始态。全局变量 Diff设为 0。
function Reset() {
Stp.innerText ="00:00:00:000";
Diff = 0;
...}
Build Requirements:
构建参数
The application is built for devices with Tizen 2.0 firmware.
SDK Environment used: 2.0.0a2
应用程序基于泰泽2.0固件而构建。
开发工具包环境是2.0.0a2
File attachments:
file:///C:/modules/file/icons/package-x-generic.png stopwatch.zip
路过的帮顶
页:
[1]