incubator-callback-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bows...@apache.org
Subject [4/50] git commit: add compass demo for Android
Date Tue, 03 Jan 2012 18:57:08 GMT
add compass demo for Android


Project: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/commit/65e3a8a4
Tree: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/tree/65e3a8a4
Diff: http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/diff/65e3a8a4

Branch: refs/heads/master
Commit: 65e3a8a453540d24ad2bad006339b4eb007c2bda
Parents: 1511183
Author: Libby Baldwin <libby.baldwin@gmail.com>
Authored: Mon Dec 19 18:30:54 2011 -0800
Committer: Libby Baldwin <libby.baldwin@gmail.com>
Committed: Mon Dec 19 18:30:54 2011 -0800

----------------------------------------------------------------------
 .../templates/project/assets/www/index.html        |   10 +++++--
 .../phonegap/templates/project/assets/www/main.js  |   19 +++++++++++++++
 2 files changed, 26 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/65e3a8a4/bin/templates/project/phonegap/templates/project/assets/www/index.html
----------------------------------------------------------------------
diff --git a/bin/templates/project/phonegap/templates/project/assets/www/index.html b/bin/templates/project/phonegap/templates/project/assets/www/index.html
index a3bf163..d89121b 100644
--- a/bin/templates/project/phonegap/templates/project/assets/www/index.html
+++ b/bin/templates/project/phonegap/templates/project/assets/www/index.html
@@ -4,7 +4,7 @@
     <meta name="viewport" content="width=320; user-scalable=no" />
     <meta http-equiv="Content-type" content="text/html; charset=utf-8">
     <title>PhoneGap</title>
-	  <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title"
charset="utf-8">
+	  <link rel="stylesheet" href="master.css" type="text/css" media="screen" title="no title">
 	  <script type="text/javascript" charset="utf-8" src="phonegap-1.3.0.js"></script>
 	  <script type="text/javascript" charset="utf-8" src="main.js"></script>
 
@@ -29,8 +29,12 @@
     <a href="#" class="btn large" onclick="beep();">Beep</a>
     <a href="#" class="btn large" onclick="vibrate();">Vibrate</a>
     <a href="#" class="btn large" onclick="show_pic();">Get a Picture</a>
-    <a href="#" class="btn large" onclick="get_contacts();">Get Phone's Contacts</a>
-    <a href="#" class="btn large" onclick="check_network();">Check Network</a>
+    <a href="#" class="btn large" onclick="get_contacts();return false;">Get Phone's
Contacts</a>
+    <a href="#" class="btn large" onclick="check_network();return false;">Check Network</a>
+    <dl>
+	<dt>Compass Heading:</dt><dd id="h">Off</dd>
+    </dl>
+    <a href="#" class="btn large" onclick="toggleCompass();return false;">Toggle Compass</a>
     <div id="viewport" class="viewport" style="display: none;">
       <img style="width:60px;height:60px" id="test_img" src="" />
     </div>

http://git-wip-us.apache.org/repos/asf/incubator-cordova-android/blob/65e3a8a4/bin/templates/project/phonegap/templates/project/assets/www/main.js
----------------------------------------------------------------------
diff --git a/bin/templates/project/phonegap/templates/project/assets/www/main.js b/bin/templates/project/phonegap/templates/project/assets/www/main.js
index 1001aab..f631692 100644
--- a/bin/templates/project/phonegap/templates/project/assets/www/main.js
+++ b/bin/templates/project/phonegap/templates/project/assets/www/main.js
@@ -119,6 +119,25 @@ function check_network() {
     confirm('Connection type:\n ' + states[networkState]);
 }
 
+var watchID = null;
+
+function updateHeading(h) {
+    document.getElementById('h').innerHTML = h.magneticHeading;
+}
+
+function toggleCompass() {
+    if (watchID !== null) {
+        navigator.compass.clearWatch(watchID);
+        watchID = null;
+        updateHeading({ magneticHeading : "Off"});
+    } else {        
+        var options = { frequency: 1000 };
+        watchID = navigator.compass.watchHeading(updateHeading, function(e) {
+            alert('Compass Error: ' + e.code);
+        }, options);
+    }
+}
+
 function init() {
     // the next line makes it impossible to see Contacts on the HTC Evo since it
     // doesn't have a scroll button


Mime
View raw message