|
a |
|
b/compass-app/plugins/org.apache.cordova.splashscreen/test/main.js |
|
|
1 |
/*
|
|
|
2 |
*
|
|
|
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
|
|
|
10 |
*
|
|
|
11 |
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
12 |
*
|
|
|
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
|
|
|
18 |
* under the License.
|
|
|
19 |
*
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
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("name").innerHTML = device.name;
|
|
|
27 |
document.getElementById("model").innerHTML = device.model;
|
|
|
28 |
document.getElementById("width").innerHTML = screen.width;
|
|
|
29 |
document.getElementById("height").innerHTML = screen.height;
|
|
|
30 |
document.getElementById("colorDepth").innerHTML = screen.colorDepth;
|
|
|
31 |
};
|
|
|
32 |
|
|
|
33 |
var getLocation = function() {
|
|
|
34 |
var suc = function(p) {
|
|
|
35 |
alert(p.coords.latitude + " " + p.coords.longitude);
|
|
|
36 |
};
|
|
|
37 |
var locFail = function() {
|
|
|
38 |
};
|
|
|
39 |
navigator.geolocation.getCurrentPosition(suc, locFail);
|
|
|
40 |
};
|
|
|
41 |
|
|
|
42 |
var beep = function() {
|
|
|
43 |
navigator.notification.beep(2);
|
|
|
44 |
};
|
|
|
45 |
|
|
|
46 |
var vibrate = function() {
|
|
|
47 |
navigator.notification.vibrate(0);
|
|
|
48 |
};
|
|
|
49 |
|
|
|
50 |
function roundNumber(num) {
|
|
|
51 |
var dec = 3;
|
|
|
52 |
var result = Math.round(num * Math.pow(10, dec)) / Math.pow(10, dec);
|
|
|
53 |
return result;
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
var accelerationWatch = null;
|
|
|
57 |
|
|
|
58 |
function updateAcceleration(a) {
|
|
|
59 |
document.getElementById('x').innerHTML = roundNumber(a.x);
|
|
|
60 |
document.getElementById('y').innerHTML = roundNumber(a.y);
|
|
|
61 |
document.getElementById('z').innerHTML = roundNumber(a.z);
|
|
|
62 |
}
|
|
|
63 |
|
|
|
64 |
var toggleAccel = function() {
|
|
|
65 |
if (accelerationWatch !== null) {
|
|
|
66 |
navigator.accelerometer.clearWatch(accelerationWatch);
|
|
|
67 |
updateAcceleration({
|
|
|
68 |
x : "",
|
|
|
69 |
y : "",
|
|
|
70 |
z : ""
|
|
|
71 |
});
|
|
|
72 |
accelerationWatch = null;
|
|
|
73 |
} else {
|
|
|
74 |
var options = {};
|
|
|
75 |
options.frequency = 1000;
|
|
|
76 |
accelerationWatch = navigator.accelerometer.watchAcceleration(
|
|
|
77 |
updateAcceleration, function(ex) {
|
|
|
78 |
alert("accel fail (" + ex.name + ": " + ex.message + ")");
|
|
|
79 |
}, options);
|
|
|
80 |
}
|
|
|
81 |
};
|
|
|
82 |
|
|
|
83 |
var preventBehavior = function(e) {
|
|
|
84 |
e.preventDefault();
|
|
|
85 |
};
|
|
|
86 |
|
|
|
87 |
function dump_pic(data) {
|
|
|
88 |
var viewport = document.getElementById('viewport');
|
|
|
89 |
console.log(data);
|
|
|
90 |
viewport.style.display = "";
|
|
|
91 |
viewport.style.position = "absolute";
|
|
|
92 |
viewport.style.top = "10px";
|
|
|
93 |
viewport.style.left = "10px";
|
|
|
94 |
document.getElementById("test_img").src = "data:image/jpeg;base64," + data;
|
|
|
95 |
}
|
|
|
96 |
|
|
|
97 |
function fail(msg) {
|
|
|
98 |
alert(msg);
|
|
|
99 |
}
|
|
|
100 |
|
|
|
101 |
function show_pic() {
|
|
|
102 |
navigator.camera.getPicture(dump_pic, fail, {
|
|
|
103 |
quality : 50
|
|
|
104 |
});
|
|
|
105 |
}
|
|
|
106 |
|
|
|
107 |
function close() {
|
|
|
108 |
var viewport = document.getElementById('viewport');
|
|
|
109 |
viewport.style.position = "relative";
|
|
|
110 |
viewport.style.display = "none";
|
|
|
111 |
}
|
|
|
112 |
|
|
|
113 |
// This is just to do this.
|
|
|
114 |
function readFile() {
|
|
|
115 |
navigator.file.read('/sdcard/cordova.txt', fail, fail);
|
|
|
116 |
}
|
|
|
117 |
|
|
|
118 |
function writeFile() {
|
|
|
119 |
navigator.file.write('foo.txt', "This is a test of writing to a file",
|
|
|
120 |
fail, fail);
|
|
|
121 |
}
|
|
|
122 |
|
|
|
123 |
function contacts_success(contacts) {
|
|
|
124 |
alert(contacts.length
|
|
|
125 |
+ ' contacts returned.'
|
|
|
126 |
+ (contacts[2] && contacts[2].name ? (' Third contact is ' + contacts[2].name.formatted)
|
|
|
127 |
: ''));
|
|
|
128 |
}
|
|
|
129 |
|
|
|
130 |
function get_contacts() {
|
|
|
131 |
var obj = new ContactFindOptions();
|
|
|
132 |
obj.filter = "";
|
|
|
133 |
obj.multiple = true;
|
|
|
134 |
obj.limit = 5;
|
|
|
135 |
navigator.service.contacts.find(
|
|
|
136 |
[ "displayName", "name" ], contacts_success,
|
|
|
137 |
fail, obj);
|
|
|
138 |
}
|
|
|
139 |
|
|
|
140 |
var networkReachableCallback = function(reachability) {
|
|
|
141 |
// There is no consistency on the format of reachability
|
|
|
142 |
var networkState = reachability.code || reachability;
|
|
|
143 |
|
|
|
144 |
var currentState = {};
|
|
|
145 |
currentState[NetworkStatus.NOT_REACHABLE] = 'No network connection';
|
|
|
146 |
currentState[NetworkStatus.REACHABLE_VIA_CARRIER_DATA_NETWORK] = 'Carrier data connection';
|
|
|
147 |
currentState[NetworkStatus.REACHABLE_VIA_WIFI_NETWORK] = 'WiFi connection';
|
|
|
148 |
|
|
|
149 |
confirm("Connection type:\n" + currentState[networkState]);
|
|
|
150 |
};
|
|
|
151 |
|
|
|
152 |
function check_network() {
|
|
|
153 |
navigator.network.isReachable("www.mobiledevelopersolutions.com",
|
|
|
154 |
networkReachableCallback, {});
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
function init() {
|
|
|
158 |
// the next line makes it impossible to see Contacts on the HTC Evo since it
|
|
|
159 |
// doesn't have a scroll button
|
|
|
160 |
// document.addEventListener("touchmove", preventBehavior, false);
|
|
|
161 |
document.addEventListener("deviceready", deviceInfo, true);
|
|
|
162 |
document.getElementById("user-agent").textContent = navigator.userAgent;
|
|
|
163 |
}
|