3
* Licensed to the Apache Software Foundation (ASF) under one
4
* or more contributor license agreements. See the NOTICE file
5
* distributed with this work for additional information
6
* regarding copyright ownership. The ASF licenses this file
7
* to you under the Apache License, Version 2.0 (the
8
* "License"); you may not use this file except in compliance
9
* with the License. You may obtain a copy of the License at
11
* http://www.apache.org/licenses/LICENSE-2.0
13
* Unless required by applicable law or agreed to in writing,
14
* software distributed under the License is distributed on an
15
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
* KIND, either express or implied. See the License for the
17
* specific language governing permissions and limitations
22
var deviceInfo = function() {
23
document.getElementById("platform").innerHTML = device.platform;
24
document.getElementById("version").innerHTML = device.version;
25
document.getElementById("uuid").innerHTML = device.uuid;
26
document.getElementById("model").innerHTML = device.model;
27
document.getElementById("width").innerHTML = screen.width;
28
document.getElementById("height").innerHTML = screen.height;
29
document.getElementById("colorDepth").innerHTML = screen.colorDepth;
32
var getLocation = function() {
33
var suc = function(p) {
34
alert(p.coords.latitude + " " + p.coords.longitude);
36
var locFail = function() {
38
navigator.geolocation.getCurrentPosition(suc, locFail);
41
var beep = function() {
42
navigator.notification.beep(2);
45
var vibrate = function() {
46
navigator.notification.vibrate(0);
49
function roundNumber(num) {
51
var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
55
var accelerationWatch = null;
57
function updateAcceleration(a) {
58
document.getElementById('x').innerHTML = roundNumber(a.x);
59
document.getElementById('y').innerHTML = roundNumber(a.y);
60
document.getElementById('z').innerHTML = roundNumber(a.z);
63
var toggleAccel = function() {
64
if (accelerationWatch !== null) {
65
navigator.accelerometer.clearWatch(accelerationWatch);
71
accelerationWatch = null;
74
options.frequency = 1000;
75
accelerationWatch = navigator.accelerometer.watchAcceleration(
76
updateAcceleration, function(ex) {
77
alert("accel fail (" + ex.name + ": " + ex.message + ")");
82
var preventBehavior = function(e) {
86
function dump_pic(data) {
87
var viewport = document.getElementById('viewport');
89
viewport.style.display = "";
90
viewport.style.position = "absolute";
91
viewport.style.top = "10px";
92
viewport.style.left = "10px";
93
document.getElementById("test_img").src = "data:image/jpeg;base64," + data;
100
function show_pic() {
101
navigator.camera.getPicture(dump_pic, fail, {
107
var viewport = document.getElementById('viewport');
108
viewport.style.position = "relative";
109
viewport.style.display = "none";
112
// This is just to do this.
113
function readFile() {
114
navigator.file.read('/sdcard/cordova.txt', fail, fail);
117
function writeFile() {
118
navigator.file.write('foo.txt', "This is a test of writing to a file",
122
function contacts_success(contacts) {
123
alert(contacts.length
124
+ ' contacts returned.'
125
+ (contacts[2] && contacts[2].name ? (' Third contact is ' + contacts[2].name.formatted)
129
function get_contacts() {
130
var obj = new ContactFindOptions();
134
navigator.service.contacts.find(
135
[ "displayName", "name" ], contacts_success,
139
var networkReachableCallback = function(reachability) {
140
// There is no consistency on the format of reachability
141
var networkState = reachability.code || reachability;
143
var currentState = {};
144
currentState[NetworkStatus.NOT_REACHABLE] = 'No network connection';
145
currentState[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
146
currentState[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
148
confirm("Connection type:\n" + currentState[networkState]);
151
function check_network() {
152
navigator.network.isReachable("www.mobiledevelopersolutions.com",
153
networkReachableCallback, {});
157
// the next line makes it impossible to see Contacts on the HTC Evo since it
158
// doesn't have a scroll button
159
// document.addEventListener("touchmove", preventBehavior, false);
160
document.addEventListener("deviceready", deviceInfo, true);
161
document.getElementById("user-agent").textContent = navigator.userAgent;