# HG changeset patch # User Eugene Ostroukhov # Date 1288648056 25200 # Node ID 8452783e79803100475d4cfb9e5326549f341c01 # Parent 0b6daedcf7e1b6fd426a7425808b242ddfad38cc Updated eggtimer application diff -r 0b6daedcf7e1 -r 8452783e7980 Eggtimer/.settings/org.symbian.tools.tmw.previewer.xml --- a/Eggtimer/.settings/org.symbian.tools.tmw.previewer.xml Thu Oct 28 11:00:31 2010 -0700 +++ b/Eggtimer/.settings/org.symbian.tools.tmw.previewer.xml Mon Nov 01 14:47:36 2010 -0700 @@ -2,8 +2,9 @@ portrait -false -1 +true WRT 1.1 +1 360x640 +DisplayUp diff -r 0b6daedcf7e1 -r 8452783e7980 Eggtimer/.settings/org.symbian.tools.tmw.ui.xml --- a/Eggtimer/.settings/org.symbian.tools.tmw.ui.xml Thu Oct 28 11:00:31 2010 -0700 +++ b/Eggtimer/.settings/org.symbian.tools.tmw.ui.xml Mon Nov 01 14:47:36 2010 -0700 @@ -1,3 +1,2 @@ - - \ No newline at end of file + \ No newline at end of file diff -r 0b6daedcf7e1 -r 8452783e7980 Eggtimer/basic.css --- a/Eggtimer/basic.css Thu Oct 28 11:00:31 2010 -0700 +++ b/Eggtimer/basic.css Mon Nov 01 14:47:36 2010 -0700 @@ -2,7 +2,6 @@ * Add your Stylesheet contents here */ #remaining-time { - background-color: olive; width: 170px; height: 40px; position: absolute; @@ -17,6 +16,7 @@ right: -138px; top: -32px; background-image: url('images/button.png'); + background-position: 0px 32px } .digits { @@ -31,7 +31,7 @@ } #sand { - background-color: yellow; + background-color: rgb(255, 208, 52); position: absolute; top: 0; bottom: 50%; @@ -40,7 +40,7 @@ } #sand-bottom { - background-color: yellow; + background-color: rgb(255, 208, 52); position: absolute; top: 100%; bottom: 0; diff -r 0b6daedcf7e1 -r 8452783e7980 Eggtimer/basic.js --- a/Eggtimer/basic.js Thu Oct 28 11:00:31 2010 -0700 +++ b/Eggtimer/basic.js Mon Nov 01 14:47:36 2010 -0700 @@ -4,14 +4,70 @@ var SETUP_ID = 1; -var timervalue = 0; -var initialTimer = 0; +var timervalue = 60; +var initialTimer = 60; var timeoutId = null; +var paused = true; +var displayUp = true; function init() { showMainWindow(); widget.setDisplayPortrait(); + watchSensorNotifications(); +} + +// Call this function to add a callback that will be notified of orientation +// changes +function watchSensorNotifications() { + var sensors = device.getServiceObject("Service.Sensor", "ISensor"); + var SensorParams = { + SearchCriterion : "Orientation" + }; + var result = sensors.ISensor.FindSensorChannel(SensorParams); + + if (result.ErrorCode != 0) { + var errorCode = result.ErrorCode; + var errorMessage = result.ErrorMessage; + return null; + } + var result2 = sensors.ISensor.RegisterForNotification( + { ChannelInfoMap : result.ReturnValue[0], + ListeningType : "ChannelData" }, sensorCallback); + if (result.ErrorCode == 0) { + var transactionId = result.TransactionID; + return transactionId; + } else { + var errorCode = result.ErrorCode; + var errorMessage = result.ErrorMessage; + return null; + } +} + +function turn(up) { + if (up != displayUp) { + displayUp = up; + timervalue = initialTimer - timervalue; + showValues(); + } +} + +// This function can be passed as callback to +// sensors.ISensor.RegisterForNotification method +function sensorCallback(transactionId, code, result) { + if (result.ErrorCode == 0) { + var dataType = result.ReturnValue.DataType; + var orientation = result.ReturnValue.DeviceOrientation; + + if (orientation == "DisplayUp") { + turn(true); + } else if (orientation == "DisplayDown") { + turn(false); + } + } else { + var errorCode = result.ErrorCode; + var errorMessage = result.ErrorMessage; + } } function startTimer() { @@ -33,17 +89,40 @@ tick(); } +function showValues() { + var hrs = Math.floor(timervalue / 3600); + var mins = Math.floor((timervalue % 3600) / 60); + var sec = timervalue % 60; + + var sz = pad(hrs) + ":" + pad(mins) + ":" + pad(sec); + document.getElementById("timervalue").innerHTML = sz; + var sand=document.getElementById("sand"); + var sandBottom = document.getElementById("sand-bottom"); + var top, bottom; + top = (50 * (initialTimer-timervalue)/initialTimer).toFixed(0) + "%"; + bottom = "50%"; + if (displayUp) { + sand.style.top = top; + sand.style.bottom = bottom; + } else { + sandBottom.style.bottom = top; + sandBottom.style.top = bottom; + } + bottom = "0%"; + top = (50 + (50 * timervalue/initialTimer)).toFixed(0) + "%"; + if (displayUp) { + sandBottom.style.top = top; + sandBottom.style.bottom = bottom; + } else { + sand.style.top = bottom; + sand.style.bottom = top; + } +} + function tick() { if (timervalue > 0) { timervalue = timervalue - 1; - var hrs = Math.floor(timervalue / 3600); - var mins = Math.floor((timervalue % 3600) / 60); - var sec = timervalue % 60; - - var sz = pad(hrs) + ":" + pad(mins) + ":" + pad(sec); - document.getElementById("timervalue").innerHTML = sz; - document.getElementById("sand").style.top=(50 * (initialTimer-timervalue)/initialTimer).toFixed(0) + "%"; - document.getElementById("sand-bottom").style.top=(50+(50 * timervalue/initialTimer)).toFixed(0) + "%"; + showValues(); if (timervalue == 0) { cancelTimer(); } @@ -84,7 +163,6 @@ menu.setRightSoftkeyLabel("Cancel", showMainWindow); } -var paused = false; function pauseStart() { if (paused) { diff -r 0b6daedcf7e1 -r 8452783e7980 Eggtimer/index.html --- a/Eggtimer/index.html Thu Oct 28 11:00:31 2010 -0700 +++ b/Eggtimer/index.html Mon Nov 01 14:47:36 2010 -0700 @@ -11,7 +11,7 @@
@@ -22,7 +22,7 @@
Specify time: - :: + ::