mirror of
https://github.com/apache/cordova-android.git
synced 2025-02-07 23:03:11 +08:00
[CB-463] added the JS updates for accel refactor
This commit is contained in:
parent
71e47aa772
commit
24adc6d00c
@ -1,6 +1,6 @@
|
|||||||
// commit facaa38a0bd924aa15c14c372537c00382f1e593
|
// commit 7b6ae77e5030060e8e99fe0b79ddcf9d698bf375
|
||||||
|
|
||||||
// File generated at :: Thu May 10 2012 16:39:13 GMT-0700 (PDT)
|
// File generated at :: Mon May 14 2012 13:03:22 GMT-0700 (PDT)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Licensed to the Apache Software Foundation (ASF) under one
|
Licensed to the Apache Software Foundation (ASF) under one
|
||||||
@ -1144,13 +1144,14 @@ module.exports = {
|
|||||||
// file: lib/common/plugin/Acceleration.js
|
// file: lib/common/plugin/Acceleration.js
|
||||||
define("cordova/plugin/Acceleration", function(require, exports, module) {
|
define("cordova/plugin/Acceleration", function(require, exports, module) {
|
||||||
var Acceleration = function(x, y, z, timestamp) {
|
var Acceleration = function(x, y, z, timestamp) {
|
||||||
this.x = x;
|
this.x = x;
|
||||||
this.y = y;
|
this.y = y;
|
||||||
this.z = z;
|
this.z = z;
|
||||||
this.timestamp = timestamp || (new Date()).getTime();
|
this.timestamp = timestamp || (new Date()).getTime();
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = Acceleration;
|
module.exports = Acceleration;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// file: lib/common/plugin/Camera.js
|
// file: lib/common/plugin/Camera.js
|
||||||
@ -3369,11 +3370,16 @@ define("cordova/plugin/accelerometer", function(require, exports, module) {
|
|||||||
* @constructor
|
* @constructor
|
||||||
*/
|
*/
|
||||||
var utils = require("cordova/utils"),
|
var utils = require("cordova/utils"),
|
||||||
exec = require("cordova/exec");
|
exec = require("cordova/exec"),
|
||||||
|
Acceleration = require('cordova/plugin/Acceleration');
|
||||||
|
|
||||||
// Local singleton variables.
|
|
||||||
|
// Keeps reference to watchAcceleration calls.
|
||||||
var timers = {};
|
var timers = {};
|
||||||
|
|
||||||
|
// Last returned acceleration object from native
|
||||||
|
var accel = null;
|
||||||
|
|
||||||
var accelerometer = {
|
var accelerometer = {
|
||||||
/**
|
/**
|
||||||
* Asynchronously aquires the current acceleration.
|
* Asynchronously aquires the current acceleration.
|
||||||
@ -3383,21 +3389,18 @@ var accelerometer = {
|
|||||||
* @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL)
|
* @param {AccelerationOptions} options The options for getting the accelerometer data such as timeout. (OPTIONAL)
|
||||||
*/
|
*/
|
||||||
getCurrentAcceleration: function(successCallback, errorCallback, options) {
|
getCurrentAcceleration: function(successCallback, errorCallback, options) {
|
||||||
|
|
||||||
// successCallback required
|
// successCallback required
|
||||||
if (typeof successCallback !== "function") {
|
if (typeof successCallback !== "function") {
|
||||||
console.log("Accelerometer Error: successCallback is not a function");
|
throw "getCurrentAcceleration must be called with at least a success callback function as first parameter.";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
var win = function(a) {
|
||||||
if (errorCallback && (typeof errorCallback !== "function")) {
|
accel = new Acceleration(a.x, a.y, a.z, a.timestamp);
|
||||||
console.log("Accelerometer Error: errorCallback is not a function");
|
successCallback(accel);
|
||||||
return;
|
};
|
||||||
}
|
|
||||||
|
|
||||||
// Get acceleration
|
// Get acceleration
|
||||||
exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []);
|
exec(win, errorCallback, "Accelerometer", "getAcceleration", []);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -3409,36 +3412,34 @@ var accelerometer = {
|
|||||||
* @return String The watch id that must be passed to #clearWatch to stop watching.
|
* @return String The watch id that must be passed to #clearWatch to stop watching.
|
||||||
*/
|
*/
|
||||||
watchAcceleration: function(successCallback, errorCallback, options) {
|
watchAcceleration: function(successCallback, errorCallback, options) {
|
||||||
|
|
||||||
// Default interval (10 sec)
|
// Default interval (10 sec)
|
||||||
var frequency = (options !== undefined && options.frequency !== undefined)? options.frequency : 10000;
|
var frequency = (options && options.frequency && typeof options.frequency == 'number') ? options.frequency : 10000;
|
||||||
|
|
||||||
// successCallback required
|
// successCallback required
|
||||||
if (typeof successCallback !== "function") {
|
if (typeof successCallback !== "function") {
|
||||||
console.log("Accelerometer Error: successCallback is not a function");
|
throw "watchAcceleration must be called with at least a success callback function as first parameter.";
|
||||||
return;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// errorCallback optional
|
// Keep reference to watch id, and report accel readings as often as defined in frequency
|
||||||
if (errorCallback && (typeof errorCallback !== "function")) {
|
|
||||||
console.log("Accelerometer Error: errorCallback is not a function");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Make sure accelerometer timeout > frequency + 10 sec
|
|
||||||
exec(
|
|
||||||
function(timeout) {
|
|
||||||
if (timeout < (frequency + 10000)) {
|
|
||||||
exec(null, null, "Accelerometer", "setTimeout", [frequency + 10000]);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
function(e) { }, "Accelerometer", "getTimeout", []);
|
|
||||||
|
|
||||||
// Start watch timer
|
|
||||||
var id = utils.createUUID();
|
var id = utils.createUUID();
|
||||||
timers[id] = window.setInterval(function() {
|
timers[id] = window.setInterval(function() {
|
||||||
exec(successCallback, errorCallback, "Accelerometer", "getAcceleration", []);
|
if (accel) {
|
||||||
}, (frequency ? frequency : 1));
|
successCallback(accel);
|
||||||
|
}
|
||||||
|
}, frequency);
|
||||||
|
|
||||||
|
// Success callback from native just updates the accel object.
|
||||||
|
var win = function(a) {
|
||||||
|
accel = new Acceleration(a.x, a.y, a.z, a.timestamp);
|
||||||
|
};
|
||||||
|
|
||||||
|
// Fail callback clears the watch and sends an error back.
|
||||||
|
var fail = function(err) {
|
||||||
|
accelerometer.clearWatch(id);
|
||||||
|
errorCallback(err);
|
||||||
|
};
|
||||||
|
|
||||||
|
exec(win, fail, "Accelerometer", "addWatch", [id, frequency]);
|
||||||
|
|
||||||
return id;
|
return id;
|
||||||
},
|
},
|
||||||
@ -3449,16 +3450,17 @@ var accelerometer = {
|
|||||||
* @param {String} id The id of the watch returned from #watchAcceleration.
|
* @param {String} id The id of the watch returned from #watchAcceleration.
|
||||||
*/
|
*/
|
||||||
clearWatch: function(id) {
|
clearWatch: function(id) {
|
||||||
|
|
||||||
// Stop javascript timer & remove from timer list
|
// Stop javascript timer & remove from timer list
|
||||||
if (id && timers[id] !== undefined) {
|
if (id && timers[id]) {
|
||||||
window.clearInterval(timers[id]);
|
window.clearInterval(timers[id]);
|
||||||
delete timers[id];
|
delete timers[id];
|
||||||
|
exec(null, null, "Accelerometer", "clearWatch", [id]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
module.exports = accelerometer;
|
module.exports = accelerometer;
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// file: lib/android/plugin/android/app.js
|
// file: lib/android/plugin/android/app.js
|
||||||
@ -5172,7 +5174,7 @@ window.cordova = require('cordova');
|
|||||||
// Fire onDeviceReady event once all constructors have run and
|
// Fire onDeviceReady event once all constructors have run and
|
||||||
// cordova info has been received from native side.
|
// cordova info has been received from native side.
|
||||||
channel.join(function() {
|
channel.join(function() {
|
||||||
channel.onDeviceReady.fire();
|
require('cordova').fireDocumentEvent('deviceready');
|
||||||
}, channel.deviceReadyChannelsArray);
|
}, channel.deviceReadyChannelsArray);
|
||||||
|
|
||||||
}, [ channel.onDOMContentLoaded, channel.onNativeReady ]);
|
}, [ channel.onDOMContentLoaded, channel.onNativeReady ]);
|
||||||
@ -5191,4 +5193,5 @@ window.cordova = require('cordova');
|
|||||||
|
|
||||||
}(window));
|
}(window));
|
||||||
|
|
||||||
|
|
||||||
})();
|
})();
|
Loading…
Reference in New Issue
Block a user