cordova-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ste...@apache.org
Subject [2/7] git commit: [Windows8][CB-4438] added windows 8 support
Date Wed, 14 Aug 2013 22:16:09 GMT
[Windows8][CB-4438] added windows 8 support


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/commit/464115f6
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/tree/464115f6
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/diff/464115f6

Branch: refs/heads/dev
Commit: 464115f68901850b92d8896108d79ca551572c2e
Parents: b085506
Author: purplecabbage <purplecabbage@gmail.com>
Authored: Tue Jul 30 17:36:39 2013 -0700
Committer: purplecabbage <purplecabbage@gmail.com>
Committed: Tue Jul 30 17:36:39 2013 -0700

----------------------------------------------------------------------
 plugin.xml                         |  7 ++++
 src/windows8/AccelerometerProxy.js | 70 +++++++++++++++++++++++++++++++++
 2 files changed, 77 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/464115f6/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 9504ad2..bd03d34 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -81,5 +81,12 @@
 
         <source-file src="src/wp/Accelerometer.cs" />
     </platform>
+
+    <!-- windows8 -->
+    <platform name="windows8">
+        <js-module src="src/windows8/AccelerometerProxy.js" name="AccelerometerProxy">
+            <merges target="" />
+        </js-module>
+    </platform>
     
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-motion/blob/464115f6/src/windows8/AccelerometerProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/AccelerometerProxy.js b/src/windows8/AccelerometerProxy.js
new file mode 100644
index 0000000..a21c361
--- /dev/null
+++ b/src/windows8/AccelerometerProxy.js
@@ -0,0 +1,70 @@
+/*
+ *
+ * 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.
+ *
+*/
+
+/*global Windows:true */
+
+var cordova = require('cordova'),
+    Acceleration = require('org.apache.cordova.core.device-motion.Acceleration');
+
+/* This is the actual implementation part that returns the result on Windows 8
+*/
+
+module.exports = {
+    onDataChanged:null,
+    start:function(win,lose){
+
+        var accel = Windows.Devices.Sensors.Accelerometer.getDefault();
+        if(!accel) {
+            lose && lose("No accelerometer found");
+        }
+        else {
+            var self = this;
+            accel.reportInterval = Math.max(16,accel.minimumReportInterval);
+
+            // store our bound function
+            this.onDataChanged = function(e) {
+                var a = e.reading;
+                win(new Acceleration(a.accelerationX,a.accelerationY,a.accelerationZ));
+            };
+            accel.addEventListener("readingchanged",this.onDataChanged);
+
+            setTimeout(function(){
+                var a = accel.getCurrentReading();
+                win(new Acceleration(a.accelerationX,a.accelerationY,a.accelerationZ));
+            },0); // async do later
+        }
+    },
+    stop:function(win,lose){
+        win = win || function(){};
+        var accel = Windows.Devices.Sensors.Accelerometer.getDefault();
+        if(!accel) {
+            lose && lose("No accelerometer found");
+        }
+        else {
+            accel.removeEventListener("readingchanged",this.onDataChanged);
+            this.onDataChanged = null;
+            accel.reportInterval = 0; // back to the default
+            win();
+        }
+    }
+};
+
+require("cordova/commandProxy").add("Accelerometer",module.exports);
\ No newline at end of file


Mime
View raw message