...
Code Block | ||||
---|---|---|---|---|
| ||||
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
startWatch();
}
var watchID;
function startWatch() {
var previousReading = {
x: null,
y: null,
z: null
}
var options = { frequency: 250 }; // Update acceleration every quarter second
watchID = navigator.accelerometer.watchAcceleration(function onSuccess(acceleration) {
var changes = {},
bound = 4; // this controls the sensitivity for detecting the shake event
if (previousReading.x !== null) {
changes.x = Math.abs(previousReading.x, acceleration.x);
changes.y = Math.abs(previousReading.y, acceleration.y);
}
if (changes.x > bound && changes.y > bound) {
stopWatch();
// We are relying on a hidden button with an ID of shake to be present on the Profound UI Rich Display File screen
if (getObj("shake") != null) pui.click("shake");
setTimeout(startWatch, 3000);
}
previousReading = {
x: acceleration.x,
y: acceleration.y,
z: acceleration.z
}
}, function onError() {
alert('Some problem has occurred in reading the accelerometer.');
}, options);
}
function stopWatch() {
if (watchID) {
navigator.accelerometer.clearWatch(watchID);
watchID = null;
}
}
|
To utilize the above in a Profound UI RPG application, simply place a hidden button on the screen. Assign the id of "shake" to the button and bind the response property to a named indicator called Shake. Then, in your RPG code, simply test for the Shake event as follows:
Code Block |
---|
If Shake = *On;
// RPG logic, such as clearing screen data, would go here
EndIf;
|
...