Merge branch 'master' into cdvtest
diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
new file mode 100644
index 0000000..1594d12
--- /dev/null
+++ b/CONTRIBUTING.md
@@ -0,0 +1,16 @@
+# Contributing to Apache Cordova
+
+Anyone can contribute to Cordova. And we need your contributions.
+
+There are multiple ways to contribute: report bugs, improve the docs, and
+contribute code.
+
+For instructions on this, start with the
+[contribution overview](http://cordova.apache.org/#contribute).
+
+The details are explained there, but the important items are:
+ - Sign and submit an Apache ICLA (Contributor License Agreement).
+ - Have a Jira issue open that corresponds to your contribution.
+ - Run the tests so your patch doesn't break existing functionality.
+
+We look forward to your contributions!
diff --git a/NOTICE b/NOTICE
new file mode 100644
index 0000000..8ec56a5
--- /dev/null
+++ b/NOTICE
@@ -0,0 +1,5 @@
+Apache Cordova
+Copyright 2012 The Apache Software Foundation
+
+This product includes software developed at
+The Apache Software Foundation (http://www.apache.org/).
diff --git a/README.md b/README.md
index 4bd5977..d0cba9b 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,22 @@
-cordova-plugin-device-motion
-============================
+<!---
+ license: Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
-Standalone plugin to be used together with cordova-pluman, to install into cordova native projects.
-To install this plugin, follow the [Command-line Interface Guide](http://cordova.apache.org/docs/en/edge/guide_cli_index.md.html#The%20Command-line%20Interface).
+ http://www.apache.org/licenses/LICENSE-2.0
-If you are not using the Cordova Command-line Interface, follow [Using Plugman to Manage Plugins](http://cordova.apache.org/docs/en/edge/plugin_ref_plugman.md.html).
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# org.apache.cordova.device-motion
+
+Plugin documentation: [doc/index.md](doc/index.md)
diff --git a/RELEASENOTES.md b/RELEASENOTES.md
index 1509ede..1044990 100644
--- a/RELEASENOTES.md
+++ b/RELEASENOTES.md
@@ -28,3 +28,36 @@
* CB-4889 renaming org.apache.cordova.core.device-motion to org.apache.cordova.device-motion
* Rename CHANGELOG.md -> RELEASENOTES.md
* [CB-4752] Incremented plugin version on dev branch.
+
+### 0.2.3 (Oct 28, 2013)
+* tweak scoping
+* fixed the scope
+* properly stop watching...
+* adding timestamp to the response
+* fix acceleromter for firefox os
+* update firefoxos integration
+* fixed callbacks
+* accelerometer registers, but is not responding
+* fxos added, not working
+* CB-5128: added repo + issue tag to plugin.xml for device motion
+* CB-5012 ensure result is returned
+* [CB-4825] Add CoreMotion.framework to plugin.xml
+* [CB-4825] avoid retain cycle in update block
+* [CB-4825] use CoreMotion framework for accelerometer
+* [CB-4915] Incremented plugin version on dev branch.
+
+### 0.2.4 (Dec 4, 2013)
+* add ubuntu platform
+* 1. Added amazon-fireos platform. 2. Change to use amazon-fireos as the platform if the user agent string contains 'cordova-amazon-fireos'
+
+### 0.2.5 (Jan 02, 2014)
+* CB-5658 Add doc/index.md for Device Motion plugin
+
+### 0.2.6 (Feb 05, 2014)
+* Add Tizen support
+
+### 0.2.7 (Apr 17, 2014)
+* CB-6422: [windows8] use cordova/exec/proxy
+* CB-6460: Update license headers
+* CB-6465: Add license headers to Tizen code
+* Add NOTICE file
diff --git a/doc/index.md b/doc/index.md
new file mode 100644
index 0000000..d0f5127
--- /dev/null
+++ b/doc/index.md
@@ -0,0 +1,157 @@
+<!---
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+# org.apache.cordova.device-motion
+
+This plugin provides access to the device's accelerometer. The accelerometer is
+a motion sensor that detects the change (_delta_) in movement relative to the
+current device orientation, in three dimensions along the _x_, _y_, and _z_
+axis.
+
+## Installation
+
+ cordova plugin add org.apache.cordova.device-motion
+
+## Supported Platforms
+
+- Amazon Fire OS
+- Android
+- BlackBerry 10
+- Firefox OS
+- iOS
+- Tizen
+- Windows Phone 7 and 8
+- Windows 8
+
+## Methods
+
+- navigator.accelerometer.getCurrentAcceleration
+- navigator.accelerometer.watchAcceleration
+- navigator.accelerometer.clearWatch
+
+## Objects
+
+- Acceleration
+
+## navigator.accelerometer.getCurrentAcceleration
+
+Get the current acceleration along the _x_, _y_, and _z_ axes.
+
+These acceleration values are returned to the `accelerometerSuccess`
+callback function.
+
+ navigator.accelerometer.getCurrentAcceleration(accelerometerSuccess, accelerometerError);
+
+
+### Example
+
+ function onSuccess(acceleration) {
+ alert('Acceleration X: ' + acceleration.x + '\n' +
+ 'Acceleration Y: ' + acceleration.y + '\n' +
+ 'Acceleration Z: ' + acceleration.z + '\n' +
+ 'Timestamp: ' + acceleration.timestamp + '\n');
+ };
+
+ function onError() {
+ alert('onError!');
+ };
+
+ navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
+
+### iOS Quirks
+
+- iOS doesn't recognize the concept of getting the current acceleration at any given point.
+
+- You must watch the acceleration and capture the data at given time intervals.
+
+- Thus, the `getCurrentAcceleration` function yields the last value reported from a `watchAccelerometer` call.
+
+## navigator.accelerometer.watchAcceleration
+
+Retrieves the device's current `Acceleration` at a regular interval, executing
+the `accelerometerSuccess` callback function each time. Specify the interval in
+milliseconds via the `acceleratorOptions` object's `frequency` parameter.
+
+The returned watch ID references the accelerometer's watch interval,
+and can be used with `navigator.accelerometer.clearWatch` to stop watching the
+accelerometer.
+
+ var watchID = navigator.accelerometer.watchAcceleration(accelerometerSuccess,
+ accelerometerError,
+ [accelerometerOptions]);
+
+- __accelerometerOptions__: An object with the following optional keys:
+ - __frequency__: How often to retrieve the `Acceleration` in milliseconds. _(Number)_ (Default: 10000)
+
+
+### Example
+
+ function onSuccess(acceleration) {
+ alert('Acceleration X: ' + acceleration.x + '\n' +
+ 'Acceleration Y: ' + acceleration.y + '\n' +
+ 'Acceleration Z: ' + acceleration.z + '\n' +
+ 'Timestamp: ' + acceleration.timestamp + '\n');
+ };
+
+ function onError() {
+ alert('onError!');
+ };
+
+ var options = { frequency: 3000 }; // Update every 3 seconds
+
+ var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
+
+### iOS Quirks
+
+The API calls the success callback function at the interval requested,
+but restricts the range of requests to the device between 40ms and
+1000ms. For example, if you request an interval of 3 seconds,
+(3000ms), the API requests data from the device every 1 second, but
+only executes the success callback every 3 seconds.
+
+## navigator.accelerometer.clearWatch
+
+Stop watching the `Acceleration` referenced by the `watchID` parameter.
+
+ navigator.accelerometer.clearWatch(watchID);
+
+- __watchID__: The ID returned by `navigator.accelerometer.watchAcceleration`.
+
+### Example
+
+ var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
+
+ // ... later on ...
+
+ navigator.accelerometer.clearWatch(watchID);
+
+## Acceleration
+
+Contains `Accelerometer` data captured at a specific point in time.
+Acceleration values include the effect of gravity (9.81 m/s^2), so that when a
+device lies flat and facing up, _x_, _y_, and _z_ values returned should be
+`0`, `0`, and `9.81`.
+
+### Properties
+
+- __x__: Amount of acceleration on the x-axis. (in m/s^2) _(Number)_
+- __y__: Amount of acceleration on the y-axis. (in m/s^2) _(Number)_
+- __z__: Amount of acceleration on the z-axis. (in m/s^2) _(Number)_
+- __timestamp__: Creation timestamp in milliseconds. _(DOMTimeStamp)_
+
diff --git a/docs/acceleration/acceleration.md b/docs/acceleration/acceleration.md
deleted file mode 100644
index 4f982b9..0000000
--- a/docs/acceleration/acceleration.md
+++ /dev/null
@@ -1,109 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-Acceleration
-============
-
-Contains `Accelerometer` data captured at a specific point in time.
-
-Properties
-----------
-
-- __x:__ Amount of acceleration on the x-axis. (in m/s^2) (`Number`)
-- __y:__ Amount of acceleration on the y-axis. (in m/s^2) (`Number`)
-- __z:__ Amount of acceleration on the z-axis. (in m/s^2) (`Number`)
-- __timestamp:__ Creation timestamp in milliseconds. (`DOMTimeStamp`)
-
-Description
------------
-
-This object is created and populated by Cordova, and returned by an `Accelerometer` method. The x, y, z acceleration values include the effect of gravity (9.81 m/s^2), so at when a device is lying flat on a table facing up, the value returned should be x=0, y=0, z=9.81.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iOS
-- Windows Phone 7 and 8
-- Bada 1.2 & 2.x
-- webOS
-- Tizen
-- Windows 8
-
-
-Quick Example
--------------
-
- function onSuccess(acceleration) {
- alert('Acceleration X: ' + acceleration.x + '\n' +
- 'Acceleration Y: ' + acceleration.y + '\n' +
- 'Acceleration Z: ' + acceleration.z + '\n' +
- 'Timestamp: ' + acceleration.timestamp + '\n');
- };
-
- function onError() {
- alert('onError!');
- };
-
- navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
-
-Full Example
-------------
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>Acceleration Example</title>
-
- <script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>
- <script type="text/javascript" charset="utf-8">
-
- // Wait for Cordova to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
-
- // Cordova is ready
- //
- function onDeviceReady() {
- navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
- }
-
- // onSuccess: Get a snapshot of the current acceleration
- //
- function onSuccess(acceleration) {
- alert('Acceleration X: ' + acceleration.x + '\n' +
- 'Acceleration Y: ' + acceleration.y + '\n' +
- 'Acceleration Z: ' + acceleration.z + '\n' +
- 'Timestamp: ' + acceleration.timestamp + '\n');
- }
-
- // onError: Failed to get the acceleration
- //
- function onError() {
- alert('onError!');
- }
-
- </script>
- </head>
- <body>
- <h1>Example</h1>
- <p>getCurrentAcceleration</p>
- </body>
- </html>
diff --git a/docs/accelerometer.clearWatch.md b/docs/accelerometer.clearWatch.md
deleted file mode 100644
index 579a6e7..0000000
--- a/docs/accelerometer.clearWatch.md
+++ /dev/null
@@ -1,114 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-accelerometer.clearWatch
-========================
-
-Stop watching the `Acceleration` referenced by the watch ID parameter.
-
- navigator.accelerometer.clearWatch(watchID);
-
-- __watchID__: The ID returned by `accelerometer.watchAcceleration`.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iPhone
-- Windows Phone 7 and 8
-- Bada 1.2 & 2.x
-- Tizen
-- Windows 8
-
-Quick Example
--------------
-
- var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
-
- // ... later on ...
-
- navigator.accelerometer.clearWatch(watchID);
-
-Full Example
-------------
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>Acceleration Example</title>
-
- <script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>
- <script type="text/javascript" charset="utf-8">
-
- // The watch id references the current `watchAcceleration`
- var watchID = null;
-
- // Wait for Cordova to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
-
- // Cordova is ready
- //
- function onDeviceReady() {
- startWatch();
- }
-
- // Start watching the acceleration
- //
- function startWatch() {
-
- // Update acceleration every 3 seconds
- var options = { frequency: 3000 };
-
- watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
- }
-
- // Stop watching the acceleration
- //
- function stopWatch() {
- if (watchID) {
- navigator.accelerometer.clearWatch(watchID);
- watchID = null;
- }
- }
-
- // onSuccess: Get a snapshot of the current acceleration
- //
- function onSuccess(acceleration) {
- var element = document.getElementById('accelerometer');
- element.innerHTML = 'Acceleration X: ' + acceleration.x + '<br />' +
- 'Acceleration Y: ' + acceleration.y + '<br />' +
- 'Acceleration Z: ' + acceleration.z + '<br />' +
- 'Timestamp: ' + acceleration.timestamp + '<br />';
- }
-
- // onError: Failed to get the acceleration
- //
- function onError() {
- alert('onError!');
- }
-
- </script>
- </head>
- <body>
- <div id="accelerometer">Waiting for accelerometer...</div>
- <button onclick="stopWatch();">Stop Watching</button>
- </body>
- </html>
diff --git a/docs/accelerometer.getCurrentAcceleration.md b/docs/accelerometer.getCurrentAcceleration.md
deleted file mode 100644
index 02e14b3..0000000
--- a/docs/accelerometer.getCurrentAcceleration.md
+++ /dev/null
@@ -1,110 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-accelerometer.getCurrentAcceleration
-====================================
-
-Get the current acceleration along the x, y, and z axis.
-
- navigator.accelerometer.getCurrentAcceleration(accelerometerSuccess, accelerometerError);
-
-Description
------------
-
-The accelerometer is a motion sensor that detects the change (delta) in movement relative to the current device orientation. The accelerometer can detect 3D movement along the x, y, and z axis.
-
-The acceleration is returned using the `accelerometerSuccess` callback function.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iPhone
-- Windows Phone 7 and 8
-- Bada 1.2 & 2.x
-- Tizen
-- Windows 8
-
-Quick Example
--------------
-
- function onSuccess(acceleration) {
- alert('Acceleration X: ' + acceleration.x + '\n' +
- 'Acceleration Y: ' + acceleration.y + '\n' +
- 'Acceleration Z: ' + acceleration.z + '\n' +
- 'Timestamp: ' + acceleration.timestamp + '\n');
- };
-
- function onError() {
- alert('onError!');
- };
-
- navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
-
-Full Example
-------------
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>Acceleration Example</title>
-
- <script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>
- <script type="text/javascript" charset="utf-8">
-
- // Wait for Cordova to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
-
- // Cordova is ready
- //
- function onDeviceReady() {
- navigator.accelerometer.getCurrentAcceleration(onSuccess, onError);
- }
-
- // onSuccess: Get a snapshot of the current acceleration
- //
- function onSuccess(acceleration) {
- alert('Acceleration X: ' + acceleration.x + '\n' +
- 'Acceleration Y: ' + acceleration.y + '\n' +
- 'Acceleration Z: ' + acceleration.z + '\n' +
- 'Timestamp: ' + acceleration.timestamp + '\n');
- }
-
- // onError: Failed to get the acceleration
- //
- function onError() {
- alert('onError!');
- }
-
- </script>
- </head>
- <body>
- <h1>Example</h1>
- <p>getCurrentAcceleration</p>
- </body>
- </html>
-
-iPhone Quirks
--------------
-
-- iPhone doesn't have the concept of getting the current acceleration at any given point.
-- You must watch the acceleration and capture the data at given time intervals.
-- Thus, the `getCurrentAcceleration` function will give you the last value reported from a Cordova `watchAccelerometer` call.
diff --git a/docs/accelerometer.md b/docs/accelerometer.md
deleted file mode 100644
index 3f68d04..0000000
--- a/docs/accelerometer.md
+++ /dev/null
@@ -1,90 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-Accelerometer
-=============
-
-> Captures device motion in the x, y, and z direction.
-
-Methods
--------
-
-- accelerometer.getCurrentAcceleration
-- accelerometer.watchAcceleration
-- accelerometer.clearWatch
-
-Arguments
----------
-
-- accelerometerSuccess
-- accelerometerError
-- accelerometerOptions
-
-Objects (Read-Only)
--------------------
-
-- Acceleration
-
-Permissions
------------
-
-### Android
-
-#### app/res/xml/config.xml
-
- <plugin name="Accelerometer" value="org.apache.cordova.AccelListener" />
-
-### Bada
-
- No permissions are required.
-
-### BlackBerry WebWorks
-
-#### www/plugins.xml
-
- <plugin name="Accelerometer" value="org.apache.cordova.accelerometer.Accelerometer" />
-
-#### www/config.xml
-
- <feature id="blackberry.system" required="true" version="1.0.0.0" />
- <feature id="org.apache.cordova" required="true" version="1.0.0" />
-
-### iOS
-
-#### config.xml
-
- <plugin name="Accelerometer" value="CDVAccelerometer" />
-
-### webOS
-
- No permissions are required.
-
-### Windows Phone
-
-#### Properties/WPAppManifest.xml
-
- <Capabilities>
- <Capability Name="ID_CAP_SENSORS" />
- </Capabilities>
-
-Reference: [Application Manifest for Windows Phone](http://msdn.microsoft.com/en-us/library/ff769509%28v=vs.92%29.aspx)
-
-### Tizen
-
- No permissions are required.
diff --git a/docs/accelerometer.watchAcceleration.md b/docs/accelerometer.watchAcceleration.md
deleted file mode 100644
index 9cc7405..0000000
--- a/docs/accelerometer.watchAcceleration.md
+++ /dev/null
@@ -1,138 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-accelerometer.watchAcceleration
-===============================
-
-At a regular interval, get the acceleration along the x, y, and z axis.
-
- var watchID = navigator.accelerometer.watchAcceleration(accelerometerSuccess,
- accelerometerError,
- [accelerometerOptions]);
-
-Description
------------
-
-The accelerometer is a motion sensor that detects the change (delta) in movement relative to the current position. The accelerometer can detect 3D movement along the x, y, and z axis.
-
-The `accelerometer.watchAcceleration` gets the device's current acceleration at a regular interval. Each time the `Acceleration` is retrieved, the `accelerometerSuccess` callback function is executed. Specify the interval in milliseconds via the `frequency` parameter in the `acceleratorOptions` object.
-
-The returned watch ID references the accelerometer watch interval. The watch ID can be used with `accelerometer.clearWatch` to stop watching the accelerometer.
-
-Supported Platforms
--------------------
-
-- Android
-- BlackBerry WebWorks (OS 5.0 and higher)
-- iPhone
-- Windows Phone 7 and 8
-- Bada 1.2 & 2.x
-- Tizen
-- Windows 8
-
-Quick Example
--------------
-
- function onSuccess(acceleration) {
- alert('Acceleration X: ' + acceleration.x + '\n' +
- 'Acceleration Y: ' + acceleration.y + '\n' +
- 'Acceleration Z: ' + acceleration.z + '\n' +
- 'Timestamp: ' + acceleration.timestamp + '\n');
- };
-
- function onError() {
- alert('onError!');
- };
-
- var options = { frequency: 3000 }; // Update every 3 seconds
-
- var watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
-
-Full Example
-------------
-
- <!DOCTYPE html>
- <html>
- <head>
- <title>Acceleration Example</title>
-
- <script type="text/javascript" charset="utf-8" src="cordova-2.6.0.js"></script>
- <script type="text/javascript" charset="utf-8">
-
- // The watch id references the current `watchAcceleration`
- var watchID = null;
-
- // Wait for Cordova to load
- //
- document.addEventListener("deviceready", onDeviceReady, false);
-
- // Cordova is ready
- //
- function onDeviceReady() {
- startWatch();
- }
-
- // Start watching the acceleration
- //
- function startWatch() {
-
- // Update acceleration every 3 seconds
- var options = { frequency: 3000 };
-
- watchID = navigator.accelerometer.watchAcceleration(onSuccess, onError, options);
- }
-
- // Stop watching the acceleration
- //
- function stopWatch() {
- if (watchID) {
- navigator.accelerometer.clearWatch(watchID);
- watchID = null;
- }
- }
-
- // onSuccess: Get a snapshot of the current acceleration
- //
- function onSuccess(acceleration) {
- var element = document.getElementById('accelerometer');
- element.innerHTML = 'Acceleration X: ' + acceleration.x + '<br />' +
- 'Acceleration Y: ' + acceleration.y + '<br />' +
- 'Acceleration Z: ' + acceleration.z + '<br />' +
- 'Timestamp: ' + acceleration.timestamp + '<br />';
- }
-
- // onError: Failed to get the acceleration
- //
- function onError() {
- alert('onError!');
- }
-
- </script>
- </head>
- <body>
- <div id="accelerometer">Waiting for accelerometer...</div>
- </body>
- </html>
-
- iPhone Quirks
--------------
-
-- At the interval requested, Cordova will call the success callback function and pass the accelerometer results.
-- However, in requests to the device Cordova restricts the interval to minimum of every 40ms and a maximum of every 1000ms.
- - For example, if you request an interval of 3 seconds (3000ms), Cordova will request an interval of 1 second from the device but invoke the success callback at the requested interval of 3 seconds.
diff --git a/docs/parameters/accelerometerError.md b/docs/parameters/accelerometerError.md
deleted file mode 100644
index 814df4d..0000000
--- a/docs/parameters/accelerometerError.md
+++ /dev/null
@@ -1,27 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-accelerometerError
-==================
-
-onError callback function for acceleration functions.
-
- function() {
- // Handle the error
- }
diff --git a/docs/parameters/accelerometerOptions.md b/docs/parameters/accelerometerOptions.md
deleted file mode 100644
index 9e8211d..0000000
--- a/docs/parameters/accelerometerOptions.md
+++ /dev/null
@@ -1,28 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-accelerometerOptions
-====================
-
-An optional parameter to customize the retrieval of the accelerometer.
-
-Options
--------
-
-- __frequency:__ How often to retrieve the `Acceleration` in milliseconds. _(Number)_ (Default: 10000)
diff --git a/docs/parameters/accelerometerSuccess.md b/docs/parameters/accelerometerSuccess.md
deleted file mode 100644
index 4e68fb6..0000000
--- a/docs/parameters/accelerometerSuccess.md
+++ /dev/null
@@ -1,42 +0,0 @@
----
-license: Licensed to the Apache Software Foundation (ASF) under one
- or more contributor license agreements. See the NOTICE file
- distributed with this work for additional information
- regarding copyright ownership. The ASF licenses this file
- to you under the Apache License, Version 2.0 (the
- "License"); you may not use this file except in compliance
- with the License. You may obtain a copy of the License at
-
- http://www.apache.org/licenses/LICENSE-2.0
-
- Unless required by applicable law or agreed to in writing,
- software distributed under the License is distributed on an
- "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- KIND, either express or implied. See the License for the
- specific language governing permissions and limitations
- under the License.
----
-
-accelerometerSuccess
-====================
-
-onSuccess callback function that provides the Acceleration information.
-
- function(acceleration) {
- // Do something
- }
-
-Parameters
-----------
-
-- __acceleration:__ The acceleration at a single moment in time. (Acceleration)
-
-Example
--------
-
- function onSuccess(acceleration) {
- alert('Acceleration X: ' + acceleration.x + '\n' +
- 'Acceleration Y: ' + acceleration.y + '\n' +
- 'Acceleration Z: ' + acceleration.z + '\n' +
- 'Timestamp: ' + acceleration.timestamp + '\n');
- };
diff --git a/plugin.xml b/plugin.xml
index 0c96b4d..c32a175 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -1,13 +1,33 @@
<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
<plugin xmlns="http://apache.org/cordova/ns/plugins/1.0"
id="org.apache.cordova.device-motion"
- version="0.2.2">
+ version="0.2.8-dev">
<name>Device Motion</name>
<description>Cordova Device Motion Plugin</description>
<license>Apache 2.0</license>
<keywords>cordova,device,motion</keywords>
+ <repo>https://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion.git</repo>
+ <issue>https://issues.apache.org/jira/browse/CB/component/12320636</issue>
<js-module src="www/Acceleration.js" name="Acceleration">
<clobbers target="Acceleration" />
@@ -20,6 +40,19 @@
<js-module src="test/tests.js" name="tests">
</js-module>
+ <!-- firefoxos -->
+ <platform name="firefoxos">
+ <config-file target="config.xml" parent="/*">
+ <feature name="Accelerometer">
+ <param name="firefoxos-package" value="Accelerometer" />
+ </feature>
+ </config-file>
+
+ <js-module src="src/firefoxos/accelerometer.js" name="accelerometer-impl">
+ <runs />
+ </js-module>
+ </platform>
+
<!-- android -->
<platform name="android">
@@ -33,6 +66,25 @@
</platform>
+ <!-- amazon-fireos -->
+ <platform name="amazon-fireos">
+
+ <config-file target="res/xml/config.xml" parent="/*">
+ <feature name="Accelerometer">
+ <param name="android-package" value="org.apache.cordova.devicemotion.AccelListener"/>
+ </feature>
+ </config-file>
+
+ <source-file src="src/android/AccelListener.java" target-dir="src/org/apache/cordova/devicemotion" />
+
+ </platform>
+
+ <!-- ubuntu -->
+ <platform name="ubuntu">
+ <header-file src="src/ubuntu/accelerometer.h" />
+ <source-file src="src/ubuntu/accelerometer.cpp" />
+ </platform>
+
<!-- ios -->
<platform name="ios">
@@ -45,6 +97,7 @@
<header-file src="src/ios/CDVAccelerometer.h" />
<source-file src="src/ios/CDVAccelerometer.m" />
+ <framework src="CoreMotion.framework" />
</platform>
<!-- blackberry10 -->
@@ -91,5 +144,11 @@
<merges target="" />
</js-module>
</platform>
-
+
+ <!-- tizen -->
+ <platform name="tizen">
+ <js-module src="src/tizen/AccelerometerProxy.js" name="AccelerometerProxy">
+ <runs/>
+ </js-module>
+ </platform>
</plugin>
diff --git a/src/firefoxos/accelerometer.js b/src/firefoxos/accelerometer.js
new file mode 100644
index 0000000..c0152ad
--- /dev/null
+++ b/src/firefoxos/accelerometer.js
@@ -0,0 +1,41 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+function listener(success, ev) {
+ var acc = ev.accelerationIncludingGravity;
+ acc.timestamp = new Date().getTime();
+ success(acc);
+}
+
+var Accelerometer = {
+ start: function start(success, error) {
+ return window.addEventListener('devicemotion', function(ev) {
+ listener(success, ev);
+ }, false);
+ },
+
+ stop: function stop() {
+ window.removeEventListener('devicemotion', listener, false);
+ }
+};
+
+module.exports = Accelerometer;
+require('cordova/firefoxos/commandProxy').add('Accelerometer', Accelerometer);
diff --git a/src/ios/CDVAccelerometer.h b/src/ios/CDVAccelerometer.h
index 923d0c8..ee1664f 100755
--- a/src/ios/CDVAccelerometer.h
+++ b/src/ios/CDVAccelerometer.h
@@ -20,7 +20,7 @@
#import <UIKit/UIKit.h>
#import <Cordova/CDVPlugin.h>
-@interface CDVAccelerometer : CDVPlugin <UIAccelerometerDelegate>
+@interface CDVAccelerometer : CDVPlugin
{
double x;
double y;
diff --git a/src/ios/CDVAccelerometer.m b/src/ios/CDVAccelerometer.m
index 33093d0..e98aacd 100755
--- a/src/ios/CDVAccelerometer.m
+++ b/src/ios/CDVAccelerometer.m
@@ -17,10 +17,13 @@
under the License.
*/
+#import <CoreMotion/CoreMotion.h>
#import "CDVAccelerometer.h"
@interface CDVAccelerometer () {}
@property (readwrite, assign) BOOL isRunning;
+@property (readwrite, assign) BOOL haveReturnedResult;
+@property (readwrite, strong) CMMotionManager* motionManager;
@end
@implementation CDVAccelerometer
@@ -28,7 +31,7 @@
@synthesize callbackId, isRunning;
// defaults to 10 msec
-#define kAccelerometerInterval 40
+#define kAccelerometerInterval 10
// g constant: -9.81 m/s^2
#define kGravitationalConstant -9.81
@@ -42,6 +45,8 @@
timestamp = 0;
self.callbackId = nil;
self.isRunning = NO;
+ self.haveReturnedResult = YES;
+ self.motionManager = nil;
}
return self;
}
@@ -53,17 +58,31 @@
- (void)start:(CDVInvokedUrlCommand*)command
{
- NSString* cbId = command.callbackId;
- NSTimeInterval desiredFrequency_num = kAccelerometerInterval;
- UIAccelerometer* pAccel = [UIAccelerometer sharedAccelerometer];
+ self.haveReturnedResult = NO;
+ self.callbackId = command.callbackId;
- // accelerometer expects fractional seconds, but we have msecs
- pAccel.updateInterval = desiredFrequency_num / 1000;
- self.callbackId = cbId;
- if (!self.isRunning) {
- pAccel.delegate = self;
- self.isRunning = YES;
+ if (!self.motionManager)
+ {
+ self.motionManager = [[CMMotionManager alloc] init];
}
+
+ if ([self.motionManager isAccelerometerAvailable] == YES) {
+ // Assign the update interval to the motion manager and start updates
+ [self.motionManager setAccelerometerUpdateInterval:kAccelerometerInterval/1000]; // expected in seconds
+ __weak CDVAccelerometer* weakSelf = self;
+ [self.motionManager startAccelerometerUpdatesToQueue:[NSOperationQueue mainQueue] withHandler:^(CMAccelerometerData *accelerometerData, NSError *error) {
+ x = accelerometerData.acceleration.x;
+ y = accelerometerData.acceleration.y;
+ z = accelerometerData.acceleration.z;
+ timestamp = ([[NSDate date] timeIntervalSince1970] * 1000);
+ [weakSelf returnAccelInfo];
+ }];
+
+ if (!self.isRunning) {
+ self.isRunning = YES;
+ }
+ }
+
}
- (void)onReset
@@ -73,24 +92,14 @@
- (void)stop:(CDVInvokedUrlCommand*)command
{
- UIAccelerometer* theAccelerometer = [UIAccelerometer sharedAccelerometer];
-
- theAccelerometer.delegate = nil;
- self.isRunning = NO;
-}
-
-/**
- * Picks up accel updates from device and stores them in this class
- */
-- (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration
-{
- if (self.isRunning) {
- x = acceleration.x;
- y = acceleration.y;
- z = acceleration.z;
- timestamp = ([[NSDate date] timeIntervalSince1970] * 1000);
- [self returnAccelInfo];
+ if ([self.motionManager isAccelerometerAvailable] == YES) {
+ if (self.haveReturnedResult == NO){
+ // block has not fired before stop was called, return whatever result we currently have
+ [self returnAccelInfo];
+ }
+ [self.motionManager stopAccelerometerUpdates];
}
+ self.isRunning = NO;
}
- (void)returnAccelInfo
@@ -106,6 +115,7 @@
CDVPluginResult* result = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:accelProps];
[result setKeepCallback:[NSNumber numberWithBool:YES]];
[self.commandDelegate sendPluginResult:result callbackId:self.callbackId];
+ self.haveReturnedResult = YES;
}
// TODO: Consider using filtering to isolate instantaneous data vs. gravity data -jm
diff --git a/src/tizen/AccelerometerProxy.js b/src/tizen/AccelerometerProxy.js
new file mode 100644
index 0000000..b534422
--- /dev/null
+++ b/src/tizen/AccelerometerProxy.js
@@ -0,0 +1,51 @@
+/*
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+(function(win) {
+ var cordova = require('cordova'),
+ Acceleration = require('org.apache.cordova.device-motion.Acceleration'),
+ accelerometerCallback = null;
+
+ module.exports = {
+ start: function (successCallback, errorCallback) {
+ if (accelerometerCallback) {
+ win.removeEventListener("devicemotion", accelerometerCallback, true);
+ }
+
+ accelerometerCallback = function (motion) {
+ successCallback({
+ x: motion.accelerationIncludingGravity.x,
+ y: motion.accelerationIncludingGravity.y,
+ z: motion.accelerationIncludingGravity.z,
+ timestamp: new Date().getTime()
+ });
+ };
+ win.addEventListener("devicemotion", accelerometerCallback, true);
+ },
+
+ stop: function (successCallback, errorCallback) {
+ win.removeEventListener("devicemotion", accelerometerCallback, true);
+ accelerometerCallback = null;
+ }
+ };
+
+ require("cordova/tizen/commandProxy").add("Accelerometer", module.exports);
+}(window));
diff --git a/src/ubuntu/accelerometer.cpp b/src/ubuntu/accelerometer.cpp
new file mode 100644
index 0000000..8d39174
--- /dev/null
+++ b/src/ubuntu/accelerometer.cpp
@@ -0,0 +1,58 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+#include <cassert>
+#include "accelerometer.h"
+
+DeviceMotion::DeviceMotion(Cordova *cordova): CPlugin(cordova), _scId(0), _ecId(0) {
+ _accelerometerSource = QSharedPointer<QAccelerometer>(new QAccelerometer());
+ _sensorAvaliable = _accelerometerSource->start();
+ connect(_accelerometerSource.data(), SIGNAL(readingChanged()), SLOT(updateSensor()));
+}
+
+void DeviceMotion::start(int scId, int ecId) {
+ assert(_ecId == 0);
+ assert(_scId == 0);
+
+ _ecId = ecId;
+ _scId = scId;
+
+ if (!_sensorAvaliable) {
+ this->cb(ecId);
+ return;
+ }
+}
+
+void DeviceMotion::stop(int, int) {
+ _scId = 0;
+ _ecId = 0;
+}
+
+void DeviceMotion::updateSensor() {
+ QAccelerometerReading *accelerometer = _accelerometerSource->reading();
+
+ QVariantMap obj;
+ obj.insert("x", accelerometer->x());
+ obj.insert("y", accelerometer->y());
+ obj.insert("z", accelerometer->z());
+ // accelerometer->timestamp() is not sutiable.
+ // Timestamps values are microseconds since _a_ fixed point(depend on backend).
+ obj.insert("timestamp", QDateTime::currentDateTime().toMSecsSinceEpoch());
+
+ if (_scId)
+ this->cb(_scId, obj);
+}
diff --git a/src/ubuntu/accelerometer.h b/src/ubuntu/accelerometer.h
new file mode 100644
index 0000000..3f36a16
--- /dev/null
+++ b/src/ubuntu/accelerometer.h
@@ -0,0 +1,55 @@
+/*
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+*/
+
+#ifndef ACCELEROMETER_H
+#define ACCELEROMETER_H
+
+#include <cplugin.h>
+#include <QAccelerometer>
+#include <QtCore>
+
+class DeviceMotion: public CPlugin {
+ Q_OBJECT
+public:
+ explicit DeviceMotion(Cordova *cordova);
+
+ virtual const QString fullName() override {
+ return DeviceMotion::fullID();
+ }
+
+ virtual const QString shortName() override {
+ return "Accelerometer";
+ }
+
+ static const QString fullID() {
+ return "Accelerometer";
+ }
+
+public slots:
+ void start(int scId, int ecId);
+ void stop(int scId, int ecId);
+
+protected slots:
+ void updateSensor();
+
+private:
+ int _scId, _ecId;
+ bool _sensorAvaliable;
+ QSharedPointer<QAccelerometer> _accelerometerSource;
+};
+
+#endif
diff --git a/src/windows8/AccelerometerProxy.js b/src/windows8/AccelerometerProxy.js
index d76e9b2..0b41ba7 100644
--- a/src/windows8/AccelerometerProxy.js
+++ b/src/windows8/AccelerometerProxy.js
@@ -67,4 +67,4 @@
}
};
-require("cordova/windows8/commandProxy").add("Accelerometer",module.exports);
+require("cordova/exec/proxy").add("Accelerometer",module.exports);