mirror of
https://github.com/apache/cordova-android.git
synced 2025-01-31 17:32:51 +08:00
add compass demo for Android
This commit is contained in:
parent
1511183dfd
commit
65e3a8a453
@ -4,7 +4,7 @@
|
|||||||
<meta name="viewport" content="width=320; user-scalable=no" />
|
<meta name="viewport" content="width=320; user-scalable=no" />
|
||||||
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
<meta http-equiv="Content-type" content="text/html; charset=utf-8">
|
||||||
<title>PhoneGap</title>
|
<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="phonegap-1.3.0.js"></script>
|
||||||
<script type="text/javascript" charset="utf-8" src="main.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="beep();">Beep</a>
|
||||||
<a href="#" class="btn large" onclick="vibrate();">Vibrate</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="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="get_contacts();return false;">Get Phone's Contacts</a>
|
||||||
<a href="#" class="btn large" onclick="check_network();">Check Network</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;">
|
<div id="viewport" class="viewport" style="display: none;">
|
||||||
<img style="width:60px;height:60px" id="test_img" src="" />
|
<img style="width:60px;height:60px" id="test_img" src="" />
|
||||||
</div>
|
</div>
|
||||||
|
@ -119,6 +119,25 @@ function check_network() {
|
|||||||
confirm('Connection type:\n ' + states[networkState]);
|
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() {
|
function init() {
|
||||||
// the next line makes it impossible to see Contacts on the HTC Evo since it
|
// the next line makes it impossible to see Contacts on the HTC Evo since it
|
||||||
// doesn't have a scroll button
|
// doesn't have a scroll button
|
||||||
|
Loading…
Reference in New Issue
Block a user