author | Eugene Ostroukhov <eugeneo@symbian.org> |
Thu, 28 Oct 2010 11:00:31 -0700 | |
changeset 0 | 0b6daedcf7e1 |
child 1 | 8452783e7980 |
permissions | -rw-r--r-- |
0
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
1 |
/* |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
2 |
* JavaScript file |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
3 |
*/ |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
4 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
5 |
var SETUP_ID = 1; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
6 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
7 |
var timervalue = 0; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
8 |
var initialTimer = 0; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
9 |
var timeoutId = null; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
10 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
11 |
function init() |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
12 |
{ |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
13 |
showMainWindow(); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
14 |
widget.setDisplayPortrait(); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
15 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
16 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
17 |
function startTimer() { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
18 |
var hr = parseInt(document.getElementById("hrs").value); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
19 |
var min = parseInt(document.getElementById("min").value); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
20 |
var sec = parseInt(document.getElementById("sec").value); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
21 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
22 |
timervalue = hr * 3600 + min * 60 + sec; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
23 |
initialTimer = timervalue; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
24 |
showMainWindow(); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
25 |
startCountdown(); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
26 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
27 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
28 |
function startCountdown() { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
29 |
if (timeoutId) { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
30 |
clearInterval(timeoutId); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
31 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
32 |
timeoutId = window.setInterval(tick, 1000); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
33 |
tick(); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
34 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
35 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
36 |
function tick() { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
37 |
if (timervalue > 0) { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
38 |
timervalue = timervalue - 1; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
39 |
var hrs = Math.floor(timervalue / 3600); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
40 |
var mins = Math.floor((timervalue % 3600) / 60); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
41 |
var sec = timervalue % 60; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
42 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
43 |
var sz = pad(hrs) + ":" + pad(mins) + ":" + pad(sec); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
44 |
document.getElementById("timervalue").innerHTML = sz; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
45 |
document.getElementById("sand").style.top=(50 * (initialTimer-timervalue)/initialTimer).toFixed(0) + "%"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
46 |
document.getElementById("sand-bottom").style.top=(50+(50 * timervalue/initialTimer)).toFixed(0) + "%"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
47 |
if (timervalue == 0) { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
48 |
cancelTimer(); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
49 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
50 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
51 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
52 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
53 |
function pad(num) { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
54 |
if (num < 10) { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
55 |
return '0' + num; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
56 |
} else { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
57 |
return num; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
58 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
59 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
60 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
61 |
function cancelTimer() { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
62 |
clearInterval(timeoutId); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
63 |
timeoutId = 0; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
64 |
timervalue = 0; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
65 |
document.getElementById("timervalue").innerHTML = "00:00:00"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
66 |
document.getElementById("sand").style.top="50%"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
67 |
document.getElementById("sand-bottom").style.top="50%"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
68 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
69 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
70 |
function showMainWindow() { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
71 |
document.getElementById("main-window").style.display = "inherit"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
72 |
document.getElementById("time-setup").style.display = "none"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
73 |
var item = new MenuItem("Setup timer", SETUP_ID); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
74 |
item.onSelect = showTimerSetup; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
75 |
menu.append(item); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
76 |
menu.setRightSoftkeyLabel("Exit", null); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
77 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
78 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
79 |
function showTimerSetup() { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
80 |
document.getElementById("main-window").style.display = "none"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
81 |
document.getElementById("time-setup").style.display = "inherit"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
82 |
var item = menu.getMenuItemById(SETUP_ID); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
83 |
menu.remove(item); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
84 |
menu.setRightSoftkeyLabel("Cancel", showMainWindow); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
85 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
86 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
87 |
var paused = false; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
88 |
|
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
89 |
function pauseStart() { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
90 |
if (paused) { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
91 |
startCountdown(); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
92 |
document.getElementById("pausestart").style.backgroundPosition = "0px 0px"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
93 |
paused = false; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
94 |
} else { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
95 |
if (timeoutId) { |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
96 |
window.clearInterval(timeoutId); |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
97 |
timeoutId = null; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
98 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
99 |
document.getElementById("pausestart").style.backgroundPosition = "0px 32px"; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
100 |
paused = true; |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
101 |
} |
0b6daedcf7e1
Initial commit of two sample projects
Eugene Ostroukhov <eugeneo@symbian.org>
parents:
diff
changeset
|
102 |
} |