You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cordova.apache.org by st...@apache.org on 2013/08/15 00:25:04 UTC

[2/8] git commit: [Windows8][CB-4439] Add windows8 support

[Windows8][CB-4439] Add windows8 support


Project: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/repo
Commit: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/commit/4102b086
Tree: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/tree/4102b086
Diff: http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/diff/4102b086

Branch: refs/heads/dev
Commit: 4102b0863fdf0a37189e30a9a35c1833e2104070
Parents: 6f403ad
Author: purplecabbage <pu...@gmail.com>
Authored: Wed Jul 31 14:54:02 2013 -0700
Committer: purplecabbage <pu...@gmail.com>
Committed: Wed Jul 31 14:54:02 2013 -0700

----------------------------------------------------------------------
 plugin.xml                   |  7 +++++
 src/windows8/CompassProxy.js | 65 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 72 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/blob/4102b086/plugin.xml
----------------------------------------------------------------------
diff --git a/plugin.xml b/plugin.xml
index 8626da7..fbdb31a 100644
--- a/plugin.xml
+++ b/plugin.xml
@@ -80,5 +80,12 @@
 
         <source-file src="src/wp/Compass.cs" />
     </platform>
+
+        <!-- windows8 -->
+    <platform name="windows8">
+        <js-module src="src/windows8/CompassProxy.js" name="CompassProxy">
+            <merges target="" />
+        </js-module>
+    </platform>
     
 </plugin>

http://git-wip-us.apache.org/repos/asf/cordova-plugin-device-orientation/blob/4102b086/src/windows8/CompassProxy.js
----------------------------------------------------------------------
diff --git a/src/windows8/CompassProxy.js b/src/windows8/CompassProxy.js
new file mode 100644
index 0000000..aa94b88
--- /dev/null
+++ b/src/windows8/CompassProxy.js
@@ -0,0 +1,65 @@
+/*
+ *
+ * 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'),
+    CompassHeading = require('org.apache.cordova.core.device-orientation.CompassHeading');
+
+
+module.exports = {
+
+    onReadingChanged:null,
+    getHeading:function(win,lose) {
+        var deviceCompass = Windows.Devices.Sensors.Compass.getDefault();
+        if(!deviceCompass) {
+            setTimeout(function(){lose("Compass not available");},0);
+        }
+        else {
+
+            deviceCompass.reportInterval = Math.max(16,deviceCompass.minimumReportInterval);
+
+            this.onReadingChanged = function(e) {
+                var reading = e.reading;
+                var heading = new CompassHeading(reading.headingMagneticNorth, reading.headingTrueNorth);
+                win(heading);
+            };
+            deviceCompass.addEventListener("readingchanged",this.onReadingChanged);
+        }
+
+    },
+    stopHeading:function(win,lose) {
+        var deviceCompass = Windows.Devices.Sensors.Compass.getDefault();
+        if(!deviceCompass) {
+            setTimeout(function(){lose("Compass not available");},0);
+        }
+        else {
+
+            deviceCompass.removeEventListener("readingchanged",this.onReadingChanged);
+            this.onReadingChanged = null;
+            deviceCompass.reportInterval = 0;
+            win();
+        }
+
+    }
+};
+
+require("cordova/commandProxy").add("Compass",module.exports);
\ No newline at end of file