Acceptance Tests
Location event
var win = Ti.UI.createWindow({
layout: 'vertical'
});
if (!Ti.Geolocation.locationServicesEnabled) {
alert('Please enable location services.');
}
function onLocation(e) {
coordLabels[0].text = 'lat: ' + e.coords.latitude;
coordLabels[1].text = 'long: ' + e.coords.longitude;
}
var geoEnabled = false;
function toggleGeo() {
geoEnabled = !geoEnabled;
geoEnabled ? Ti.Geolocation.addEventListener('location', onLocation)
: Ti.Geolocation.removeEventListener('location', onLocation);
}
var toggleButton = Ti.UI.createButton({
title: 'Toggle Geolocation'
});
toggleButton.addEventListener('click', toggleGeo);
win.add(toggleButton);
var coordLabels = ['lat', 'long'].map(function(text) {
var label = Ti.UI.createLabel({
text: text,
width: Ti.UI.FILL
});
win.add(label);
return label;
});
win.open();
Verify when you click the toggle button your current position is displayed and updated as you move.
Clicking the toggle again should turn off updates. Repeat a few times to verify it switches on/off.
Heading event
var win = Ti.UI.createWindow({
layout: 'vertical'
});
var headingLabel = Ti.UI.createLabel({
text: 'heading = ',
width: Ti.UI.FILL
});
win.add(headingLabel);
var accuracyLabel = Ti.UI.createLabel({
text: 'accuracy = ',
width: Ti.UI.FILL
});
win.add(accuracyLabel);
function onHeading(e) {
headingLabel.text = 'heading = ' + e.heading.magneticHeading;
accuracyLabel.text = 'accuracy = ' + e.heading.accuracy;
}
var compassEnabled = false;
function toggleCompass() {
compassEnabled = !compassEnabled;
compassEnabled ? Ti.Geolocation.addEventListener('heading', onHeading)
: Ti.Geolocation.removeEventListener('heading', onHeading);
}
var toggleButton = Ti.UI.createButton({
title: 'Toggle Compass'
});
toggleButton.addEventListener('click', toggleCompass);
win.add(toggleButton);
win.open();
Verify clicking the toggle button starts displaying compass heading values.
Try rotating the phone to verify the degrees changes. Click the toggle again
to verify the compass events stop.
Created pull request [#36](https://github.com/appcelerator/titanium_mobile_blackberry/pull/36).
Tested with: Appcelerator Studio, build: 3.2.0.201312081316 Titanium SDK, build: 3.2.0.v20131209110113 CLI 3.2.0-beta BlackBerry Z10 10.1.0.2019
To test
add to tiapp.xmlTo test
Run the code below and click the toggle geolocation button http://pastie.org/private/vnc7cbbs0vg1ziwqdof6tqEnvironment
Appcelerator Studio, build: 3.3.0.201405161313 Titanium SDK, build: 3.3.0.v20140523120121 Node.JS Version: v0.10.13 NPM Version: 1.3.2 acs@1.0.14 alloy@1.4.0-alpha4 npm@1.3.2 titanium@3.3.0-alpha5 titanium-code-processor@1.1.1 Device: BB Z10 (10.2.1)the error
PR for master: https://github.com/appcelerator/titanium_mobile_blackberry/pull/246 PR for 3.3.X https://github.com/appcelerator/titanium_mobile_blackberry/pull/247
Tested with Mac osx 10.9.3 Mavericks Appcelerator Studio, build: 3.3.0.201405271647 Titanium SDK, build: 3.3.0.v20140528144113 Node.JS Version: v0.10.13 NPM Version: 1.3.2 acs@1.0.14 alloy@1.4.0-beta npm@1.3.2 titanium@3.3.0-beta titanium-code-processor@1.1.1 Device: BB Z10 (10.2.1) Verified clicking the toggle button starts displaying compass heading values. Rotated the phone to verify the degrees changes. Clicked the toggle again to verify the compass events stop.