Good evening all
I am having a small problem trying to get my app to navigate to the selected remote location. The method is being called but the redirection is not happening.
I am trying to get the app to redirect to a page once the user has stopped shaking the device.
Here is the code being used:
(function () {
// Initialize variables
var watchID;
var previousAcceleration = {
x: null,
y: null,
z: null
};
var shakeStarted = false;
window.Home = {
// Function when page loaded
show: function () {
var spanTimeStamp = document.getElementById("spanTimeStamp");
spanTimeStamp.textContent = "Started";
var options = {
frequency: 500
}; // Update every .5 seconds
watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
},
// Function when page unloaded
hide: function () {
if (watchID) {
navigator.accelerometer.clearWatch(watchID);
watchID = null;
}
}
};
// Function when the accelerometer is initialized
function onSuccess(acceleration) {
var accelerationChange = {};
// See if there is a previous acceleration
if (previousAcceleration.x !== null) {
accelerationChange.x = Math.abs(previousAcceleration.x - acceleration.x);
accelerationChange.y = Math.abs(previousAcceleration.y - acceleration.y);
accelerationChange.z = Math.abs(previousAcceleration.z - acceleration.z);
}
// Set the previous acceleration
previousAcceleration = {
x: acceleration.x,
y: acceleration.y,
z: acceleration.z
};
// See if the acceleration is a shake
if (accelerationChange.x + accelerationChange.y + accelerationChange.z > 30) {
shakeStarted = true;
var spanDirectionX = document.getElementById("spanDirectionX");
spanDirectionX.textContent = acceleration.timestamp + " :: " + (accelerationChange.x + accelerationChange.y + accelerationChange.z) + " :: ";
} else if (accelerationChange.x + accelerationChange.y + accelerationChange.z < 30 && shakeStarted == true) {
// Call the function when the shaking stops
shakeStarted = false;
ShakeStopped();
}
}
// Function to be called when the shaking stopped
function ShakeStopped() {
var app = new kendo.mobile.Application();
var id = Math.floor(Math.random() * 20) + 1;
var spanTimeStamp = document.getElementById("spanTimeStamp");
spanTimeStamp.textContent = "Stopped from function :: " + id;
app.navigate("views/details.html?##id=" + id);
}
// Function if an error occurs with the accelerometer
function onError() {
alert('onError!');
}
}());
Nay help would be greatly appreicated
Many thanks
Eric