Namespace: Motion

CB_Device. Motion

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_getAccelerationConstantly function.

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
callbackOk function

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_getAccelerationNormalized function automatically. Following the same rules as in https://github.com/apache/cordova-plugin-device-motion ("navigator.accelerometer.getCurrentAcceleration" function).

callbackError function

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
callbackOkOrId function | integer <optional>
CB_Device.Motion.cordova_getAccelerationConstantly_lastId

In 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_getAccelerationNormalized function 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.

callbackError function <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.

options Object <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
id integer <optional>
CB_Device.Motion.cordova_getAccelerationConstantly_lastId

The 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
accelerometerData Object

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
eventFunction function | 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.

keepOldFunction boolean <optional>
true

Defines whether we want to keep any possible previous event listener or not.

useCapture float <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