Static class to manage the device's motion. It will return itself if it is tried to be instantiated.
- Source:
- To Do:
-
- Normalize more differences between web clients.
Members
-
<static, readonly> cordova_getAccelerationConstantly_lastId :integer|null
-
Keeps the last watch ID that gets the acceleration constantly using the Apache Cordova's Device Motion plugin. Used by the
CB_Device.Motion.cordova_getAccelerationConstantlyfunction.Type:
- integer | null
- Source:
Methods
-
<static> cordova_getAcceleration(callbackOk, callbackError) → {undefined|false}
-
Gets the acceleration using the Apache Cordova's Device Motion plugin. Uses "navigator.accelerometer.getCurrentAcceleration" internally.
Parameters:
Name Type Description callbackOkfunction The function that will be called when it succeeds getting the acceleration. The event object received will already be normalized by the
CB_Device.Motion.cordova_getAccelerationNormalizedfunction automatically. Following the same rules as in https://github.com/apache/cordova-plugin-device-motion ("navigator.accelerometer.getCurrentAcceleration" function).callbackErrorfunction The function that will be called if there is any error getting the acceleration. Following the same rules as in https://github.com/apache/cordova-plugin-device-motion ("navigator.accelerometer.getCurrentAcceleration" function).
- Source:
Returns:
Returns false in the case that the Apache Cordova's Device Motion plugin is not supported or undefined otherwise.
- Type
- undefined | false
-
<static> cordova_getAccelerationConstantly( [callbackOkOrId] [, callbackError] [, options]) → {integer|undefined|false}
-
Starts or stops getting the acceleration constantly at a regular interval. Uses the Apache Cordova's Device Motion plugin ("navigator.accelerometer.watchAcceleration" and "navigator.accelerometer.clearWatch" functions).
Parameters:
Name Type Argument Default Description callbackOkOrIdfunction | integer <optional>
CB_Device.Motion.cordova_getAccelerationConstantly_lastIdIn the case that we want to start getting the acceleration, use a function callback that will be called regularly when the acceleration is gotten successfully (using the "navigator.accelerometer.watchAcceleration" function) and the event object received will already be normalized by the
CB_Device.Motion.cordova_getAccelerationNormalizedfunction automatically. To stop getting the acceleration, use the watch ID that we want to stop (using the "navigator.accelerometer.clearWatch" function). Following the same rules as the first parameter of the "navigator.accelerometer.watchAcceleration" function (when we want to start watching) or the first parameter of "navigator.accelerometer.clearWatch" function (when we want to stop watching) described in https://github.com/apache/cordova-plugin-device-motion.callbackErrorfunction <optional>
Callback that will be called if there is any error getting the acceleration. Only used when we want to start getting the acceleration ("callbackOkOrId" is a function). Following the same rules as the second parameter of the "navigator.accelerometer.watchAcceleration" function described in https://github.com/apache/cordova-plugin-device-motion.
optionsObject <optional>
Object that represents the desired options. Only used when we want to start getting the acceleration ("callbackOkOrId" is a function). Following the same rules as the third parameter of the "navigator.accelerometer.watchAcceleration" function described in https://github.com/apache/cordova-plugin-device-motion.
- Source:
- To Do:
-
- Add parameters to keep old callbacks and options.
Returns:
Returns false in the case that Apache Cordova's Device Motion plugin is not supported. In the case that we want to start getting the acceleration ("callbackOkOrId" is a function), it will return the watch ID that has been created. In the case that we want to stop getting the acceleration ("callbackOkOrId" is a watch ID), it will return undefined.
- Type
- integer | undefined | false
-
<static> cordova_getAccelerationConstantlyDisable( [id]) → {undefined|false}
-
Stops getting the acceleration constantly at a regular interval. Uses the Apache Cordova's Device Motion plugin ("navigator.accelerometer.clearWatch" function).
Parameters:
Name Type Argument Default Description idinteger <optional>
CB_Device.Motion.cordova_getAccelerationConstantly_lastIdThe watch ID that we want to stop. Following the same rules as the first parameter of the "navigator.accelerometer.clearWatch" function described in https://github.com/apache/cordova-plugin-device-motion.
- Source:
- To Do:
-
- Add parameters to keep old callbacks and options.
Returns:
Returns false in the case that Apache Cordova's Device Motion plugin is not supported or undefined otherwise.
- Type
- undefined | false
-
<static> cordova_getAccelerationNormalized(accelerometerData) → {Event}
-
Normalizes the data gotten from the Apache Cordova's Device Motion plugin to try to match the Device Motion Event and follow always the same rules as much as possible.
Parameters:
Name Type Description accelerometerDataObject The acceleration object that we want to normalize.
- Source:
- To Do:
-
- Normalize the values without gravity too (accelerometerData.acceleration.x, accelerometerData.acceleration.y, accelerometerData.acceleration.z) if possible (needs gyroscope probably) and maybe more properties.
Returns:
Returns the given acceleration object again but normalized (if possible).
- Type
- Event
-
<static> cordova_isAccelerationSupported() → {boolean}
-
Tells whether the Apache Cordova's Device Motion plugin is available or not.
- Source:
Returns:
- Type
- boolean
-
<static> isSupported() → {boolean}
-
Tells whether the Device Motion Event (used by the Device Orientation API or compatible one) is supported or not.
- Source:
Returns:
- Type
- boolean
-
<static> onChange(eventFunction [, keepOldFunction] [, useCapture]) → {undefined|false}
-
Sets a function to execute for the Device Motion Event (used by the Device Orientation API or compatible one) or removes it.
Parameters:
Name Type Argument Default Description eventFunctionfunction | null The function that will be called when the event is fired. Following the same rules as in https://developer.mozilla.org/docs/Web/API/DeviceMotionEvent. If a null value is used, the event will be removed.
keepOldFunctionboolean <optional>
true Defines whether we want to keep any possible previous event listener or not.
useCapturefloat <optional>
false Defines whether the event we want to add will use capture or not. This parameter will be effective only if the current client supports the addEventListener method and will be used as its third parameter.
- Source:
Returns:
Returns false in the case that the Device Motion Event is not supported or undefined otherwise.
- Type
- undefined | false