Created
April 27, 2011 02:15
-
-
Save pec1985/943611 to your computer and use it in GitHub Desktop.
pedometer.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var win = Ti.UI.createWindow({backgroundColor:'#ccc'}); | |
var isRunning = false; | |
var btn = Ti.UI.createButton({ | |
title:'start', | |
bottom:10, | |
height:50, | |
left:10, | |
right:10 | |
}); | |
var slider = Ti.UI.createSlider({ | |
width:240, | |
max:1.0, | |
min:-1.0, | |
value:0 | |
}); | |
win.add(slider); | |
win.add(btn); | |
win.open({modal:true}); | |
function accel(e){ | |
slider.value = e.x; | |
} | |
var stopPedometer = function(){ | |
Titanium.Accelerometer.removeEventListener('update', accel); | |
} | |
var startPedometer = function(){ | |
Titanium.Accelerometer.addEventListener('update', accel); | |
} | |
btn.addEventListener('click', function(){ | |
if( isRunning ) { | |
btn.title = 'start'; | |
stopPedometer(); | |
} else { | |
btn.title = 'stop'; | |
startPedometer(); | |
} | |
switch(isRunning){ | |
case true: isRunning = false; break; | |
case false: isRunning = true; break; | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Pedometer? Does that measure the happiness of: http://is.gd/MJB8Ei