Skip to content

Commit

Permalink
Manual tests fixed
Browse files Browse the repository at this point in the history
Removing inline scripts from mobile-spec to make it compatible with FFOS priveleged type apps (i.e. using contacts)

added addListenerToClass function which is used to connect buttons with test functions.

Please check it on all platforms and r+ if working.

moved test initialization to JS file (for DRY and privileged apps compatibility)
  • Loading branch information
zalun committed May 14, 2014
1 parent 508f29f commit 0de5e95
Show file tree
Hide file tree
Showing 75 changed files with 2,687 additions and 2,764 deletions.
120 changes: 6 additions & 114 deletions accelerometer/index.html
Expand Up @@ -27,118 +27,10 @@
<title>Cordova Mobile Spec</title>
<link rel="stylesheet" href="../master.css" type="text/css" media="screen" title="no title" charset="utf-8">
<script type="text/javascript" charset="utf-8" src="../cordova-incl.js"></script>


<script type="text/javascript" charset="utf-8">

var deviceReady = false;

function roundNumber(num) {
var dec = 3;
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}

//-------------------------------------------------------------------------
// Acceleration
//-------------------------------------------------------------------------
var watchAccelId = null;

/**
* Start watching acceleration
*/
var watchAccel = function() {
console.log("watchAccel()");

// Success callback
var success = function(a){
document.getElementById('x').innerHTML = roundNumber(a.x);
document.getElementById('y').innerHTML = roundNumber(a.y);
document.getElementById('z').innerHTML = roundNumber(a.z);
console.log("watchAccel success callback");
};

// Fail callback
var fail = function(e){
console.log("watchAccel fail callback with error code "+e);
stopAccel();
setAccelStatus(Accelerometer.ERROR_MSG[e]);
};

// Update acceleration every 1 sec
var opt = {};
opt.frequency = 1000;
watchAccelId = navigator.accelerometer.watchAcceleration(success, fail, opt);

setAccelStatus("Running");
};

/**
* Stop watching the acceleration
*/
var stopAccel = function() {
console.log("stopAccel()");
setAccelStatus("Stopped");
if (watchAccelId) {
navigator.accelerometer.clearWatch(watchAccelId);
watchAccelId = null;
}
};

/**
* Get current acceleration
*/
var getAccel = function() {
console.log("getAccel()");

// Stop accel if running
stopAccel();

// Success callback
var success = function(a){
document.getElementById('x').innerHTML = roundNumber(a.x);
document.getElementById('y').innerHTML = roundNumber(a.y);
document.getElementById('z').innerHTML = roundNumber(a.z);
};

// Fail callback
var fail = function(e){
console.log("getAccel fail callback with error code "+e);
setAccelStatus(Accelerometer.ERROR_MSG[e]);
};

// Make call
var opt = {};
navigator.accelerometer.getCurrentAcceleration(success, fail, opt);
};

/**
* Set accelerometer status
*/
var setAccelStatus = function(status) {
document.getElementById('accel_status').innerHTML = status;
};

/**
* Function called when page has finished loading.
*/
function init() {
console.log("accelerometer.init()");
document.addEventListener("deviceready", function() {
deviceReady = true;
console.log("Device="+device.platform+" "+device.version);
}, false);
window.setTimeout(function() {
if (!deviceReady) {
alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
}
},1000);
}

</script>
<script type="text/javascript" charset="utf-8" src="./index.js"></script>

</head>
<body onload="init();" id="stage" class="theme">
<body id="stage" class="theme">

<h1>Acceleration</h1>
<div id="info">
Expand All @@ -151,9 +43,9 @@ <h1>Acceleration</h1>
</div>

<h2>Action</h2>
<div class="btn large" onclick="getAccel();">Get Acceleration</div>
<div class="btn large" onclick="watchAccel();">Start Watch</div>
<div class="btn large" onclick="stopAccel();">Clear Watch</div>
<h2> </h2><div class="backBtn" onclick="backHome();">Back</div>
<div class="btn large getAccel">Get Acceleration</div>
<div class="btn large watchAccel">Start Watch</div>
<div class="btn large stopAccel">Clear Watch</div>
<h2> </h2><div class="backBtn">Back</div>
</body>
</html>
111 changes: 111 additions & 0 deletions accelerometer/index.js
@@ -0,0 +1,111 @@
var deviceReady = false;

function roundNumber(num) {
var dec = 3;
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}

//-------------------------------------------------------------------------
// Acceleration
//-------------------------------------------------------------------------
var watchAccelId = null;

/**
* Start watching acceleration
*/
var watchAccel = function() {
console.log("watchAccel()");

// Success callback
var success = function(a){
document.getElementById('x').innerHTML = roundNumber(a.x);
document.getElementById('y').innerHTML = roundNumber(a.y);
document.getElementById('z').innerHTML = roundNumber(a.z);
console.log("watchAccel success callback");
};

// Fail callback
var fail = function(e){
console.log("watchAccel fail callback with error code "+e);
stopAccel();
setAccelStatus(Accelerometer.ERROR_MSG[e]);
};

// Update acceleration every 1 sec
var opt = {};
opt.frequency = 1000;
watchAccelId = navigator.accelerometer.watchAcceleration(success, fail, opt);

setAccelStatus("Running");
};

/**
* Stop watching the acceleration
*/
var stopAccel = function() {
console.log("stopAccel()");
setAccelStatus("Stopped");
if (watchAccelId) {
navigator.accelerometer.clearWatch(watchAccelId);
watchAccelId = null;
}
};

/**
* Get current acceleration
*/
var getAccel = function() {
console.log("getAccel()");

// Stop accel if running
stopAccel();

// Success callback
var success = function(a){
document.getElementById('x').innerHTML = roundNumber(a.x);
document.getElementById('y').innerHTML = roundNumber(a.y);
document.getElementById('z').innerHTML = roundNumber(a.z);
};

// Fail callback
var fail = function(e){
console.log("getAccel fail callback with error code "+e);
setAccelStatus(Accelerometer.ERROR_MSG[e]);
};

// Make call
var opt = {};
navigator.accelerometer.getCurrentAcceleration(success, fail, opt);
};

/**
* Set accelerometer status
*/
var setAccelStatus = function(status) {
document.getElementById('accel_status').innerHTML = status;
};

/**
* Function called when page has finished loading.
*/
function init() {
console.log("accelerometer.init()");
document.addEventListener("deviceready", function() {
deviceReady = true;
console.log("Device="+device.platform+" "+device.version);
}, false);
window.setTimeout(function() {
if (!deviceReady) {
alert("Error: Apache Cordova did not initialize. Demo will not run correctly.");
}
},1000);
}

window.onload = function() {
addListenerToClass('getAccel', getAccel);
addListenerToClass('watchAccel', watchAccel);
addListenerToClass('stopAccel', stopAccel);
addListenerToClass('backBtn', backHome);
init();
}

0 comments on commit 0de5e95

Please sign in to comment.