var win = Ti.UI.createWindow({
layout: 'vertical'
});
var enableAccelerometer = Ti.UI.createButton({
title: 'Toggle Accelerometer'
});
win.add(enableAccelerometer);
var labels = ['x', 'y', 'z'].map(function(coord) {
var label = Ti.UI.createLabel({text: coord + ': N/A'});
win.add(label);
return label;
});
function onUpdate(e) {
labels[0].text = e.x;
labels[1].text = e.y;
labels[2].text = e.z;
}
var accelerometerEnabled = false;
enableAccelerometer.addEventListener('click', function() {
accelerometerEnabled ? Ti.Accelerometer.removeEventListener('update', onUpdate)
: Ti.Accelerometer.addEventListener('update', onUpdate);
accelerometerEnabled = !accelerometerEnabled;
});
win.open();
Ready for code review and testing.
Closing ticket as fixed.