Publish Vulpes Preview 15 sources for desktop, Android and Tundra
Share Gaia assets and adapters, keep private profiles and development documents local, and update both public READMEs.
This commit is contained in:
parent
93e3a48004
commit
b38dea0597
25901 changed files with 9982925 additions and 369 deletions
25
assets/webapps/uitest.gaiamobile.org/js/HW/battery.js
Normal file
25
assets/webapps/uitest.gaiamobile.org/js/HW/battery.js
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
'use strict';
|
||||
|
||||
function batteryTest() {
|
||||
var battery = window.navigator.battery;
|
||||
var charging = document.getElementById('charging');
|
||||
var level = document.getElementById('level');
|
||||
var chargingTime = document.getElementById('charging-time');
|
||||
var disChargingTime = document.getElementById('discharging-time');
|
||||
|
||||
function update(evt) {
|
||||
charging.textContent = battery.charging;
|
||||
level.textContent = battery.level * 100;
|
||||
chargingTime.textContent = battery.chargingTime;
|
||||
disChargingTime.textContent = battery.dischargingTime;
|
||||
}
|
||||
|
||||
battery.addEventListener('chargingchange', update);
|
||||
battery.addEventListener('levelchange', update);
|
||||
battery.addEventListener('onchargingtimechange', update);
|
||||
battery.addEventListener('ondischargingtimechange', update);
|
||||
|
||||
update();
|
||||
}
|
||||
|
||||
window.addEventListener('load', batteryTest);
|
||||
99
assets/webapps/uitest.gaiamobile.org/js/HW/bluetooth.js
Normal file
99
assets/webapps/uitest.gaiamobile.org/js/HW/bluetooth.js
Normal file
|
|
@ -0,0 +1,99 @@
|
|||
'use strict';
|
||||
|
||||
function bluetoothTest() {
|
||||
var bluetooth = window.navigator.mozBluetooth;
|
||||
var settings = window.navigator.mozSettings;
|
||||
var switchButton = document.getElementById('switch');
|
||||
var state = document.getElementById('state');
|
||||
var address = document.getElementById('address');
|
||||
var version = document.getElementById('version');
|
||||
var btHelper = new BluetoothHelper();
|
||||
|
||||
function update() {
|
||||
var req = settings.createLock().get('bluetooth.enabled');
|
||||
req.onsuccess = function() {
|
||||
var isBluetoothEnabled = req.result['bluetooth.enabled'];
|
||||
switchButton.checked = isBluetoothEnabled;
|
||||
if (!isBluetoothEnabled) {
|
||||
state.innerHTML = 'Off';
|
||||
address.innerHTML = 'unknown';
|
||||
}
|
||||
else {
|
||||
state.innerHTML = 'On';
|
||||
if (!btHelper.v2) {
|
||||
btHelper.getAddress(function bt_gotAddress(addr) {
|
||||
if (isBluetoothEnabled) {
|
||||
address.innerHTML = addr;
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
// Click on switch will only update settings and
|
||||
// it takes some time for bluetooth hardware to turns on.
|
||||
// That's why we should listen to 'enabled' event of bluetooth
|
||||
function bluetoothSwitch() {
|
||||
settings.createLock().set({'bluetooth.enabled': switchButton.checked});
|
||||
// set enabled stat for BT APIv2
|
||||
if (switchButton.checked) {
|
||||
btHelper.enable();
|
||||
} else {
|
||||
btHelper.disable();
|
||||
}
|
||||
}
|
||||
|
||||
if (btHelper.v2) {
|
||||
version.textContent = "v2";
|
||||
bluetooth.addEventListener('attributechanged', (evt) => {
|
||||
for (var i in evt.attrs) {
|
||||
switch (evt.attrs[i]) {
|
||||
case 'defaultAdapter':
|
||||
var adapter = bluetooth.defaultAdapter;
|
||||
if (adapter.address) { // for default On case
|
||||
address.innerHTML = adapter.address;
|
||||
}
|
||||
adapter.addEventListener('attributechanged', (evt) => {
|
||||
for (var i in evt.attrs) {
|
||||
switch (evt.attrs[i]) {
|
||||
case 'state':
|
||||
if (adapter.state === 'enabled') {
|
||||
switchButton.checked = true;
|
||||
state.innerHTML = 'On';
|
||||
} else if (adapter.state === 'disabled') {
|
||||
switchButton.checked = false;
|
||||
state.innerHTML = 'Off';
|
||||
address.innerHTML = 'unknown';
|
||||
}
|
||||
break;
|
||||
case 'address':
|
||||
address.innerHTML = adapter.address;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
} else {
|
||||
version.textContent = "v1";
|
||||
bluetooth.addEventListener('adapteradded', update);
|
||||
bluetooth.addEventListener('enabled', update);
|
||||
bluetooth.addEventListener('disabled', update);
|
||||
}
|
||||
|
||||
// init
|
||||
switchButton.addEventListener('click', bluetoothSwitch);
|
||||
|
||||
// Update bluetooth information in the first load
|
||||
update();
|
||||
}
|
||||
|
||||
window.addEventListener('load', bluetoothTest);
|
||||
|
||||
19
assets/webapps/uitest.gaiamobile.org/js/HW/camera.js
Normal file
19
assets/webapps/uitest.gaiamobile.org/js/HW/camera.js
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
'use strict';
|
||||
|
||||
var clickHandlers = {
|
||||
'camera': function() {
|
||||
var activity = new MozActivity({
|
||||
name: 'record',
|
||||
data: {
|
||||
type: 'photos'
|
||||
}
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
document.body.addEventListener('click', function(evt) {
|
||||
if (clickHandlers[evt.target.id]) {
|
||||
clickHandlers[evt.target.id].call(this, evt);
|
||||
}
|
||||
});
|
||||
|
||||
154
assets/webapps/uitest.gaiamobile.org/js/HW/fmradio.js
Normal file
154
assets/webapps/uitest.gaiamobile.org/js/HW/fmradio.js
Normal file
|
|
@ -0,0 +1,154 @@
|
|||
'use strict';
|
||||
|
||||
function FMRadioTest() {
|
||||
var messageText = document.getElementById('message');
|
||||
var frequencyMin = document.getElementById('frequency-min');
|
||||
var frequencyMax = document.getElementById('frequency-max');
|
||||
|
||||
var container = document.getElementById('container');
|
||||
var controlPanel = document.getElementById('controlPanel');
|
||||
|
||||
var frequencyInput = document.getElementById('frequency');
|
||||
var switchBtn = document.getElementById('switch');
|
||||
var seekUpBtn = document.getElementById('seekUp');
|
||||
var seekDownBtn = document.getElementById('seekDown');
|
||||
var seekAndCancelBtn = document.getElementById('seekAndCancel');
|
||||
|
||||
if (!navigator.mozFMRadio) {
|
||||
console.log('mozFMRadio not support');
|
||||
container.hidden = true;
|
||||
return;
|
||||
}
|
||||
|
||||
var radio = navigator.mozFMRadio;
|
||||
var prevFreq = radio.frequencyLowerBound;
|
||||
var lock = false;
|
||||
if (radio.enabled) {
|
||||
prevFreq = radio.frequency;
|
||||
}
|
||||
|
||||
switchBtn.textContent = radio.enabled;
|
||||
frequencyMin.textContent = radio.frequencyLowerBound;
|
||||
frequencyMax.textContent = radio.frequencyUpperBound;
|
||||
controlPanel.hidden = !radio.enabled;
|
||||
frequencyInput.value = prevFreq;
|
||||
|
||||
togglePanel();
|
||||
toggleControlPanel();
|
||||
|
||||
radio.addEventListener('antennaavailablechange', togglePanel);
|
||||
radio.addEventListener('frequencychange', frequencyChanged);
|
||||
|
||||
frequencyInput.addEventListener('change', setFrequency);
|
||||
switchBtn.addEventListener('click', onclick_radioSwitch);
|
||||
seekUpBtn.addEventListener('click', seek);
|
||||
seekDownBtn.addEventListener('click', seek);
|
||||
seekAndCancelBtn.addEventListener('click', seekAndCancel);
|
||||
window.addEventListener('unload', uninit);
|
||||
|
||||
function logError() {
|
||||
messageText.textContent = this.error.name;
|
||||
}
|
||||
|
||||
// show/hide panels
|
||||
function togglePanel() {
|
||||
if (radio && radio.antennaAvailable) {
|
||||
container.hidden = false;
|
||||
messageText.textContent = '';
|
||||
}
|
||||
else {
|
||||
container.hidden = true;
|
||||
messageText.textContent = 'Headphone is required for FMRadio';
|
||||
}
|
||||
}
|
||||
|
||||
function toggleControlPanel() {
|
||||
lock = false;
|
||||
controlPanel.hidden = !radio.enabled;
|
||||
if (radio.enabled) {
|
||||
switchBtn.textContent = 'Stop';
|
||||
}
|
||||
else {
|
||||
switchBtn.textContent = 'Start';
|
||||
}
|
||||
switchBtn.disabled = false;
|
||||
}
|
||||
|
||||
function onclick_radioSwitch() {
|
||||
if (lock) {
|
||||
return;
|
||||
}
|
||||
|
||||
// lock button until request is finished
|
||||
lock = true;
|
||||
switchBtn.disabled = true;
|
||||
|
||||
var req;
|
||||
if (!radio.enabled) {
|
||||
messageText.textContent = 'turning on FM, please wait...';
|
||||
req = radio.enable(prevFreq);
|
||||
}
|
||||
else {
|
||||
req = radio.disable();
|
||||
}
|
||||
req.onsuccess = req.onerror = function() {
|
||||
toggleControlPanel();
|
||||
if (this.error) {
|
||||
messageText.textContent = this.error.name;
|
||||
}
|
||||
else {
|
||||
messageText.textContent = '';
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
function frequencyChanged() {
|
||||
console.log('freq changed');
|
||||
frequencyInput.value = radio.frequency;
|
||||
prevFreq = radio.frequency;
|
||||
}
|
||||
|
||||
function setFrequency() {
|
||||
var req = radio.setFrequency(frequencyInput.value);
|
||||
req.onerror = logError;
|
||||
}
|
||||
|
||||
function seek(evt) {
|
||||
var req;
|
||||
if (evt.target.id == 'seekUp') {
|
||||
req = radio.seekUp();
|
||||
}
|
||||
else {
|
||||
req = radio.seekDown();
|
||||
}
|
||||
req.onerror = logError;
|
||||
}
|
||||
|
||||
function seekAndCancel(evt) {
|
||||
var req = radio.seekUp();
|
||||
console.log('seekUP()');
|
||||
req.onsuccess = function() {
|
||||
console.log('seekUP().onsuccess');
|
||||
};
|
||||
req.onerror = function() {
|
||||
console.log('seekUP().onerror:' + this.error.name);
|
||||
};
|
||||
|
||||
var cancel = radio.cancelSeek();
|
||||
console.log('cancel()');
|
||||
cancel.onsuccess = function() {
|
||||
console.log('canelSeek().onsuccess');
|
||||
};
|
||||
cancel.onerror = function() {
|
||||
console.log('cancelSeek().onerror:' + this.error.name);
|
||||
};
|
||||
}
|
||||
|
||||
function uninit() {
|
||||
if (radio.enabled) {
|
||||
radio.disable();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', FMRadioTest);
|
||||
23
assets/webapps/uitest.gaiamobile.org/js/HW/headphone.js
Normal file
23
assets/webapps/uitest.gaiamobile.org/js/HW/headphone.js
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
'use strict';
|
||||
|
||||
function headphoneTest() {
|
||||
var status_display = document.getElementById('status');
|
||||
var acm = navigator.mozAudioChannelManager;
|
||||
if (acm) {
|
||||
acm.addEventListener('headphoneschange', update.bind(this));
|
||||
}
|
||||
else {
|
||||
status_display.textContent = 'mozAudioChannelManager not found';
|
||||
}
|
||||
|
||||
function update() {
|
||||
if (acm.headphones) {
|
||||
status_display.textContent = 'plugged';
|
||||
}
|
||||
else {
|
||||
status_display.textContent = 'unpluged';
|
||||
}
|
||||
}
|
||||
update();
|
||||
}
|
||||
window.addEventListener('load', headphoneTest);
|
||||
71
assets/webapps/uitest.gaiamobile.org/js/HW/lcd.js
Normal file
71
assets/webapps/uitest.gaiamobile.org/js/HW/lcd.js
Normal file
|
|
@ -0,0 +1,71 @@
|
|||
'use strict';
|
||||
|
||||
var LCDTest = {
|
||||
get fullscreenDiv() {
|
||||
delete this.fullScreenDiv;
|
||||
return this.fullScreenDiv = document.getElementById('fullscreen-div');
|
||||
},
|
||||
firstTimeHint: null,
|
||||
init: function() {
|
||||
document.body.addEventListener('click', this);
|
||||
this.fullscreenDiv.addEventListener('click',
|
||||
this.exitFullscreen.bind(this));
|
||||
this.firstTimeHint = true;
|
||||
},
|
||||
enterFullscreen: function(color) {
|
||||
this.fullscreenDiv.mozRequestFullScreen();
|
||||
this.fullscreenDiv.classList.remove('invisible');
|
||||
this.fullscreenDiv.classList.remove('red');
|
||||
this.fullscreenDiv.classList.remove('green');
|
||||
this.fullscreenDiv.classList.remove('blue');
|
||||
this.fullscreenDiv.classList.remove('white');
|
||||
this.fullscreenDiv.classList.remove('black');
|
||||
this.fullscreenDiv.classList.add(color);
|
||||
if (this.firstTimeHint) {
|
||||
this.firstTimeHint = false;
|
||||
alert('Tap screen again to exit fullscreen mode');
|
||||
}
|
||||
},
|
||||
exitFullscreen: function() {
|
||||
document.mozCancelFullScreen();
|
||||
this.fullscreenDiv.classList.add('invisible');
|
||||
},
|
||||
turnOn: function() {
|
||||
navigator.mozPower.screenEnabled = true;
|
||||
|
||||
// no longer need the lock
|
||||
this.wakeLock.unlock();
|
||||
},
|
||||
// Only handle clicks on button, clicks on div is handled by exitFullscreen
|
||||
handleEvent: function(evt) {
|
||||
switch (evt.target.id) {
|
||||
case 'red':
|
||||
this.enterFullscreen('red');
|
||||
break;
|
||||
case 'green':
|
||||
this.enterFullscreen('green');
|
||||
break;
|
||||
case 'blue':
|
||||
this.enterFullscreen('blue');
|
||||
break;
|
||||
case 'white':
|
||||
this.enterFullscreen('white');
|
||||
break;
|
||||
case 'black':
|
||||
this.enterFullscreen('black');
|
||||
break;
|
||||
case 'off':
|
||||
// We are going to shutdown the screen, this may lead to
|
||||
// the sleep of CPU. Use wake lock to prevent from sleeping
|
||||
// which cause setTimeout stop working.
|
||||
this.wakeLock = window.navigator.requestWakeLock('screen');
|
||||
|
||||
setTimeout(this.turnOn.bind(this), 3000);
|
||||
navigator.mozPower.screenEnabled = false;
|
||||
break;
|
||||
}
|
||||
},
|
||||
wakeLock: null
|
||||
};
|
||||
|
||||
window.addEventListener('load', LCDTest.init.bind(LCDTest));
|
||||
26
assets/webapps/uitest.gaiamobile.org/js/HW/physicalkeys.js
Normal file
26
assets/webapps/uitest.gaiamobile.org/js/HW/physicalkeys.js
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
'use strict';
|
||||
|
||||
/*
|
||||
var ringer = function callsHandler() {
|
||||
var phoneSoundURL = new SettingsURL();
|
||||
SettingsListener.observe('dialer.ringtone', '', function(value) {
|
||||
ringtonePlayer.pause();
|
||||
ringtonePlayer.src = phoneSoundURL.set(value);
|
||||
});
|
||||
var ringtonePlayer = ringtonePlayer;
|
||||
ringtonePlayer = new Audio();
|
||||
ringtonePlayer.mozAudioChannelType = 'ringer';
|
||||
ringtonePlayer.src = phoneSoundURL.get();
|
||||
ringtonePlayer.loop = false;
|
||||
|
||||
window.addEventListener('home', function (evt) {
|
||||
evt.preventDefault();
|
||||
ringtonePlayer.play();
|
||||
});
|
||||
window.addEventListener('click', function (evt) {
|
||||
evt.stopPropagation();
|
||||
ringtonePlayer.play();
|
||||
});
|
||||
}();
|
||||
|
||||
*/
|
||||
173
assets/webapps/uitest.gaiamobile.org/js/HW/radio.js
Normal file
173
assets/webapps/uitest.gaiamobile.org/js/HW/radio.js
Normal file
|
|
@ -0,0 +1,173 @@
|
|||
'use strict';
|
||||
|
||||
function IMEI(serviceId) {
|
||||
var IMEIText = document.getElementById('IMEI');
|
||||
|
||||
navigator.mozTelephony.dial('*#06#', serviceId).then(function(call) {
|
||||
return call.result.then(function getIMEI(message) {
|
||||
if (message && (message.serviceCode === 'scImei') &&
|
||||
message.statusMessage) {
|
||||
IMEIText.textContent = message.statusMessage;
|
||||
}
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
// SIM card information such as ICCID, MSISDN
|
||||
function iccInfo(mozIcc, parentContainer)
|
||||
{
|
||||
var messageText = parentContainer.querySelector('[data-type="icc-message"]');
|
||||
var ICCIDText = parentContainer.querySelector('[data-type="ICCID"]');
|
||||
var MSISDNText = parentContainer.querySelector('[data-type="MSISDN"]');
|
||||
var container = parentContainer.querySelector('[data-type="icc-container"]');
|
||||
|
||||
mozIcc.addEventListener('cardstatechange', update_icc);
|
||||
update_icc();
|
||||
|
||||
function update_icc() {
|
||||
if (mozIcc.cardState == null ||
|
||||
!mozIcc.iccInfo) {
|
||||
container.hidden = true;
|
||||
messageText.textContent = 'Airplane mode on';
|
||||
}
|
||||
else {
|
||||
ICCIDText.textContent = mozIcc.iccInfo.iccid;
|
||||
MSISDNText.textContent = mozIcc.iccInfo.msisdn || 'Unknown';
|
||||
container.hidden = false;
|
||||
messageText.textContent = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// data & voice network information
|
||||
function mobileConnectionInfo(conn, parentContainer)
|
||||
{
|
||||
conn.addEventListener('datachange', update_data_network);
|
||||
conn.addEventListener('voicechange', update_voice_network);
|
||||
update_data_network();
|
||||
update_voice_network();
|
||||
|
||||
function update_data_network() {
|
||||
var container = parentContainer.
|
||||
querySelector('[data-type="data-container"]');
|
||||
var message = parentContainer.
|
||||
querySelector('[data-type="data-message"]');
|
||||
var result = update_network(conn.data, container, message);
|
||||
}
|
||||
function update_voice_network() {
|
||||
var container = parentContainer.
|
||||
querySelector('[data-type="voice-container"]');
|
||||
var message = parentContainer.
|
||||
querySelector('[data-type="voice-message"]');
|
||||
var result = update_network(conn.voice, container, message);
|
||||
}
|
||||
function update_network(network, container, message) {
|
||||
if (!conn || conn.radioState != 'enabled' ||
|
||||
!network || !network.connected || network.emergencyCallsOnly) {
|
||||
container.hidden = true;
|
||||
message.textContent = 'Disconnect';
|
||||
}
|
||||
else {
|
||||
container.querySelector('[data-type="network"]').textContent =
|
||||
network.network.shortName;
|
||||
container.querySelector('[data-type="LAC"]').textContent =
|
||||
network.cell.gsmCellId;
|
||||
container.querySelector('[data-type="CID"]').textContent =
|
||||
network.cell.gsmLocationAreaCode;
|
||||
container.querySelector('[data-type="strength"]').textContent =
|
||||
network.relSignalStrength;
|
||||
container.querySelector('[data-type="type"]').textContent =
|
||||
network.type;
|
||||
container.querySelector('[data-type="roaming"]').textContent =
|
||||
network.roaming;
|
||||
container.hidden = false;
|
||||
message.textContent = '';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
function radioTest() {
|
||||
var iccIdIndex = [];
|
||||
var icc_num = 0;
|
||||
|
||||
if (('mozIccManager' in navigator) &&
|
||||
navigator.mozIccManager &&
|
||||
('mozMobileConnections' in navigator) &&
|
||||
navigator.mozMobileConnections.length > 0) {
|
||||
var iccManager = navigator.mozIccManager;
|
||||
|
||||
// IMEI should be the same no matter which connection is used
|
||||
IMEI(0);
|
||||
|
||||
var template = document.getElementById('connection-template');
|
||||
template.hidden = true;
|
||||
|
||||
if (iccManager.iccIds.length > 0) {
|
||||
for (var i = 0; i < iccManager.iccIds.length; i++) {
|
||||
addIcc(iccManager.iccIds[i], i);
|
||||
showInfo(iccManager.iccIds[i]);
|
||||
}
|
||||
} else {
|
||||
document.getElementById('global-message').textContent =
|
||||
'SIM card not found, insert SIM and turn off airplane mode';
|
||||
}
|
||||
|
||||
iccManager.addEventListener('iccdetected', function(evt) {
|
||||
document.getElementById('global-message').textContent = '';
|
||||
addIcc(evt.iccId);
|
||||
showInfo(evt.iccId);
|
||||
});
|
||||
iccManager.addEventListener('iccundetected', function(evt) {
|
||||
removeIcc(evt.iccId);
|
||||
});
|
||||
}
|
||||
else {
|
||||
alert('navigator.mozIccManager or navigator.mozMobileConnections ' +
|
||||
'not supported');
|
||||
}
|
||||
|
||||
function showInfo(iccId) {
|
||||
var i = iccIdIndex[iccId];
|
||||
var connectionContainer = document.getElementById('connection#' + i);
|
||||
|
||||
// show ICC#
|
||||
connectionContainer.querySelector('[data-type="SIM-number"]')
|
||||
.textContent = i;
|
||||
|
||||
iccInfo(navigator.mozIccManager.getIccById(iccId), connectionContainer);
|
||||
|
||||
mobileConnectionInfo(navigator.mozMobileConnections[i],
|
||||
connectionContainer);
|
||||
}
|
||||
|
||||
function addIcc(iccId) {
|
||||
var connectionContainer = document.getElementById('connection#' + icc_num);
|
||||
if (!connectionContainer) {
|
||||
// copy connection-template then modify it.
|
||||
connectionContainer = template.cloneNode(true);
|
||||
connectionContainer.id = 'connection#' + icc_num;
|
||||
connectionContainer.hidden = false;
|
||||
|
||||
document.getElementById('content').appendChild(connectionContainer);
|
||||
}
|
||||
|
||||
iccIdIndex[iccId] = icc_num;
|
||||
icc_num++;
|
||||
}
|
||||
|
||||
function removeIcc(iccId) {
|
||||
var i = iccIdIndex[iccId];
|
||||
if (i != null) {
|
||||
iccIdIndex[iccId] = null;
|
||||
// re-organize index
|
||||
for (var key in iccIdIndex) {
|
||||
if (iccIdIndex[key] >= i) {
|
||||
iccIdIndex[key]--;
|
||||
}
|
||||
}
|
||||
icc_num--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener('load', radioTest);
|
||||
17
assets/webapps/uitest.gaiamobile.org/js/HW/ringer.js
Normal file
17
assets/webapps/uitest.gaiamobile.org/js/HW/ringer.js
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
'use strict';
|
||||
|
||||
var ringtonePlayer = new Audio();
|
||||
|
||||
// Get ringer file path from settings
|
||||
var phoneSoundURL = new SettingsURL();
|
||||
SettingsListener.observe('dialer.ringtone', '', function(value) {
|
||||
ringtonePlayer.pause();
|
||||
ringtonePlayer.src = phoneSoundURL.set(value);
|
||||
});
|
||||
|
||||
document.body.addEventListener('click', function(evt) {
|
||||
if (evt.target.id == 'ring') {
|
||||
ringtonePlayer.play();
|
||||
}
|
||||
});
|
||||
|
||||
85
assets/webapps/uitest.gaiamobile.org/js/HW/sdcards.js
Normal file
85
assets/webapps/uitest.gaiamobile.org/js/HW/sdcards.js
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
'use strict';
|
||||
|
||||
// Whenever the check button is clicked,
|
||||
// we delete previously displayed result (if any) then show new result
|
||||
function checkSDCards() {
|
||||
var sdcards = navigator.getDeviceStorages('sdcard');
|
||||
document.getElementById('numOfCards').textContent = sdcards.length;
|
||||
|
||||
// cardInfo collection
|
||||
var cardsInfo = document.getElementById('cardsInfo');
|
||||
|
||||
// Clear last result
|
||||
while (cardsInfo.firstChild) {
|
||||
cardsInfo.removeChild(cardsInfo.firstChild);
|
||||
}
|
||||
|
||||
// Show new result
|
||||
sdcards.forEach(function showCards(card, index, cards) {
|
||||
// To add a new SD cardInfo,
|
||||
// first copy one from card_template then modify it.
|
||||
var template = document.getElementById('card_template');
|
||||
var cardInfo = template.cloneNode(true);
|
||||
cardInfo.id = 'card' + index;
|
||||
cardInfo.classList.remove('invisible');
|
||||
|
||||
var cardNo =
|
||||
cardInfo.querySelector('#card' + index + ' > .no > span');
|
||||
var cardStatus =
|
||||
cardInfo.querySelector('#card' + index + ' > .status > span');
|
||||
var cardSpace =
|
||||
cardInfo.querySelector('#card' + index + ' > .space');
|
||||
var cardSpaceTotal =
|
||||
cardInfo.querySelector('#card' + index + ' > .space > .totalSpace');
|
||||
var cardSpaceFree =
|
||||
cardInfo.querySelector('#card' + index + ' > .space > .freeSpace');
|
||||
var cardSpaceUsed =
|
||||
cardInfo.querySelector('#card' + index + ' > .space > .usedSpace');
|
||||
cardNo.textContent = index;
|
||||
|
||||
// Show availability and hide other infomation if not available
|
||||
var reqAvailable = card.available();
|
||||
reqAvailable.onsuccess = function() {
|
||||
cardStatus.textContent = this.result;
|
||||
if (this.result == 'shared' || this.result == 'unavailable') {
|
||||
cardSpace.classList.add('invisible');
|
||||
}
|
||||
};
|
||||
reqAvailable.onerror = function() {
|
||||
cardStatus.textContent = 'Unable to get sdcard status' + this.error.name;
|
||||
};
|
||||
|
||||
// Show space info.
|
||||
// If the other space info is already updated, show total space
|
||||
var reqFree = card.freeSpace();
|
||||
reqFree.onsuccess = function() {
|
||||
var spaceGB = this.result / Math.pow(10, 9);
|
||||
cardSpaceFree.textContent = spaceGB;
|
||||
if (cardSpaceTotal.textContent == '') {
|
||||
cardSpaceTotal.textContent = spaceGB;
|
||||
}
|
||||
else {
|
||||
cardSpaceTotal.textContent =
|
||||
parseFloat(cardSpaceTotal.textContent) + spaceGB;
|
||||
}
|
||||
};
|
||||
var reqUsed = card.usedSpace();
|
||||
reqUsed.onsuccess = function() {
|
||||
var spaceGB = this.result / Math.pow(10, 9);
|
||||
cardSpaceUsed.textContent = spaceGB;
|
||||
if (cardSpaceTotal.textContent == '') {
|
||||
cardSpaceTotal.textContent = spaceGB;
|
||||
}
|
||||
else {
|
||||
cardSpaceTotal.textContent =
|
||||
parseFloat(cardSpaceTotal.textContent) + spaceGB;
|
||||
}
|
||||
};
|
||||
|
||||
cardsInfo.appendChild(cardInfo);
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
document.getElementById('check').addEventListener('click', checkSDCards);
|
||||
});
|
||||
67
assets/webapps/uitest.gaiamobile.org/js/HW/sensors.js
Normal file
67
assets/webapps/uitest.gaiamobile.org/js/HW/sensors.js
Normal file
|
|
@ -0,0 +1,67 @@
|
|||
'use strict';
|
||||
|
||||
function sensorTest() {
|
||||
var interval = document.getElementById('interval');
|
||||
var accelerationX = document.getElementById('acceleration-x');
|
||||
var accelerationY = document.getElementById('acceleration-y');
|
||||
var accelerationZ = document.getElementById('acceleration-z');
|
||||
var accelerationGX = document.getElementById('acceleration-gravity-x');
|
||||
var accelerationGY = document.getElementById('acceleration-gravity-y');
|
||||
var accelerationGZ = document.getElementById('acceleration-gravity-z');
|
||||
var rotAlpha = document.getElementById('rot-rate-alpha');
|
||||
var rotBeta = document.getElementById('rot-rate-beta');
|
||||
var rotGamma = document.getElementById('rot-rate-gamma');
|
||||
var orientationAlpha = document.getElementById('orientation-alpha');
|
||||
var orientationBeta = document.getElementById('orientation-beta');
|
||||
var orientationGamma = document.getElementById('orientation-gamma');
|
||||
var proximityMin = document.getElementById('proximity-min');
|
||||
var proximityMax = document.getElementById('proximity-max');
|
||||
var proximityValue = document.getElementById('proximity-value');
|
||||
var compassCalibration = document.getElementById('compassneedscalibration');
|
||||
|
||||
window.addEventListener('devicemotion', function(e) {
|
||||
interval.textContent = e.interval;
|
||||
|
||||
if (e.acceleration) {
|
||||
accelerationX.textContent = e.acceleration.x;
|
||||
accelerationY.textContent = e.acceleration.y;
|
||||
accelerationZ.textContent = e.acceleration.z;
|
||||
}
|
||||
|
||||
if (e.accelerationIncludingGravity) {
|
||||
accelerationGX.textContent = e.accelerationIncludingGravity.x;
|
||||
accelerationGY.textContent = e.accelerationIncludingGravity.y;
|
||||
accelerationGZ.textContent = e.accelerationIncludingGravity.z;
|
||||
}
|
||||
|
||||
if (e.rotationRate) {
|
||||
rotAlpha.textContent = e.rotationRate.alpha;
|
||||
rotBeta.textContent = e.rotationRate.beta;
|
||||
rotGamma.textContent = e.rotationRate.gamma;
|
||||
}
|
||||
}, false);
|
||||
|
||||
window.addEventListener('deviceorientation', function(e) {
|
||||
if (e) {
|
||||
orientationAlpha.textContent = e.alpha;
|
||||
orientationBeta.textContent = e.beta;
|
||||
orientationGamma.textContent = e.gamma;
|
||||
}
|
||||
}, false);
|
||||
|
||||
window.addEventListener('devicelight', function(event) {
|
||||
document.getElementById('light').textContent = event.value;
|
||||
});
|
||||
|
||||
window.addEventListener('deviceproximity', function(event) {
|
||||
proximityMin.textContent = event.min;
|
||||
proximityMax.textContent = event.max;
|
||||
proximityValue.textContent = event.value;
|
||||
});
|
||||
|
||||
window.addEventListener('compassneedscalibration', function(e) {
|
||||
compassCalibration.textContent = 'true';
|
||||
}, false);
|
||||
}
|
||||
|
||||
window.addEventListener('load', sensorTest);
|
||||
448
assets/webapps/uitest.gaiamobile.org/js/HW/touchscreen.js
Normal file
448
assets/webapps/uitest.gaiamobile.org/js/HW/touchscreen.js
Normal file
|
|
@ -0,0 +1,448 @@
|
|||
'use strict';
|
||||
|
||||
// test result indicator
|
||||
var Status = {
|
||||
NOT_FINISHED: 1,
|
||||
FINISHED: 2,
|
||||
ABORT: 3
|
||||
};
|
||||
|
||||
// UTILS
|
||||
var util = {
|
||||
// Use this function to get correct click position on canvas
|
||||
relMouseCoords: function(canvas, evt) {
|
||||
var rect = canvas.getBoundingClientRect();
|
||||
var eventX = evt.clientX - rect.left;
|
||||
var eventY = evt.clientY - rect.top;
|
||||
return {x: eventX, y: eventY};
|
||||
},
|
||||
|
||||
clearScreen: function(ctx) {
|
||||
ctx.fillStyle = 'white';
|
||||
ctx.fillRect(0, 0, ctx.canvas.width, ctx.canvas.height);
|
||||
},
|
||||
|
||||
drawRectFromCoord: function(ctx, x1, y1, x2, y2) {
|
||||
ctx.translate(0.5, 0.5);
|
||||
ctx.strokeRect(x1, y1, x2 - x1, y2 - y1);
|
||||
ctx.translate(-0.5, -0.5);
|
||||
},
|
||||
|
||||
// Fill rect without overlapping border,
|
||||
fillRectFromCoord: function(ctx, x1, y1, x2, y2) {
|
||||
ctx.fillRect(x1 + 1, y1 + 1, (x2 - x1) - 1, (y2 - y1) - 1);
|
||||
},
|
||||
|
||||
drawCircle: function(ctx, x, y, radius, width, color) {
|
||||
ctx.lineWidth = width;
|
||||
ctx.strokeStyle = color;
|
||||
ctx.beginPath();
|
||||
ctx.translate(0.5, 0.5);
|
||||
ctx.arc(x, y, radius, 0, 2 * Math.PI);
|
||||
ctx.translate(-0.5, -0.5);
|
||||
ctx.closePath();
|
||||
ctx.stroke();
|
||||
},
|
||||
|
||||
distance_sqr: function(x1, y1, x2, y2) {
|
||||
return (x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2);
|
||||
},
|
||||
|
||||
// Return the index less or equal to num
|
||||
binary_search: function(arr, num) {
|
||||
var begin = 0;
|
||||
var end = arr.length - 1;
|
||||
while (begin < end) {
|
||||
var pivot = Math.round((begin + end) / 2);
|
||||
if (num < arr[pivot]) {
|
||||
end = pivot - 1;
|
||||
}
|
||||
else if (num > arr[pivot]) {
|
||||
begin = pivot + 1;
|
||||
}
|
||||
else {
|
||||
return pivot;
|
||||
}
|
||||
}
|
||||
if (num < arr[begin]) {
|
||||
return begin - 1;
|
||||
}
|
||||
return begin;
|
||||
}
|
||||
};
|
||||
|
||||
// TEST 1
|
||||
// Draw 4 circles on the corners and 1 circle in the center
|
||||
var test1 = function(canvas) {
|
||||
var ctx = canvas.getContext('2d');
|
||||
var circle_radius = Math.min(canvas.width, canvas.height) * 0.1;
|
||||
var circles_coord =
|
||||
[[circle_radius, circle_radius],
|
||||
[circle_radius, canvas.height - circle_radius],
|
||||
[canvas.width - circle_radius, circle_radius],
|
||||
[canvas.width - circle_radius, canvas.height - circle_radius],
|
||||
[canvas.width / 2, canvas.height / 2]];
|
||||
var lineWidth = 2;
|
||||
var lineColor = 'red';
|
||||
var lineColorClicked = 'lime';
|
||||
var is_clicked = [];
|
||||
|
||||
var exitIconPositionX;
|
||||
var exitIconPositionY;
|
||||
var exitIconWidth;
|
||||
var exitIconHeight;
|
||||
|
||||
(function init() {
|
||||
util.clearScreen(ctx);
|
||||
|
||||
// Draw not-clicked circle
|
||||
for (var i = 0; i < circles_coord.length; i++) {
|
||||
util.drawCircle(ctx, circles_coord[i][0], circles_coord[i][1],
|
||||
circle_radius, lineWidth, lineColor);
|
||||
is_clicked[i] = false;
|
||||
}
|
||||
// Draw exit icon
|
||||
var image = document.getElementById('icon-exit');
|
||||
exitIconWidth = image.width;
|
||||
exitIconHeight = image.height;
|
||||
// Draw icon below center
|
||||
exitIconPositionX = (canvas.width - exitIconWidth) / 2;
|
||||
exitIconPositionY = canvas.height * 0.65;
|
||||
ctx.drawImage(image, exitIconPositionX, exitIconPositionY);
|
||||
})();
|
||||
|
||||
// Touch test, change circle color if touch point is in the circle.
|
||||
// Test ends if all circles are touched
|
||||
this.test = function(x, y) {
|
||||
// Clicked on exit button
|
||||
if (x > exitIconPositionX && x <= exitIconPositionX + exitIconWidth &&
|
||||
y > exitIconPositionY && y <= exitIconPositionY + exitIconHeight) {
|
||||
return Status.ABORT;
|
||||
}
|
||||
for (var i = 0; i < circles_coord.length; i++) {
|
||||
if (!is_clicked[i] &&
|
||||
util.distance_sqr(x, y, circles_coord[i][0], circles_coord[i][1]) <
|
||||
circle_radius * circle_radius) {
|
||||
// Clear red circle by covering a bigger white circle on it
|
||||
util.drawCircle(ctx, circles_coord[i][0], circles_coord[i][1],
|
||||
circle_radius, lineWidth + 2, 'white');
|
||||
// Draw new circle
|
||||
util.drawCircle(ctx, circles_coord[i][0], circles_coord[i][1],
|
||||
circle_radius, lineWidth, lineColorClicked);
|
||||
|
||||
is_clicked[i] = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
for (var i = 0; i < circles_coord.length; i++) {
|
||||
if (!is_clicked[i]) {
|
||||
return Status.NOT_FINISHED;
|
||||
}
|
||||
}
|
||||
// Test over
|
||||
return Status.FINISHED;
|
||||
};
|
||||
};
|
||||
|
||||
// TEST 2
|
||||
// Draw several cubes on the edge of screen
|
||||
var test2 = function(canvas) {
|
||||
var ctx = canvas.getContext('2d');
|
||||
var aspect = canvas.width / canvas.height;
|
||||
var cubes_num_vertical = 20;
|
||||
var cubes_num_horizontal = Math.round(cubes_num_vertical * aspect);
|
||||
var cube_width = canvas.width / cubes_num_horizontal;
|
||||
var cube_height = canvas.height / cubes_num_vertical;
|
||||
|
||||
var cube_coord_x = [];
|
||||
var cube_coord_y = [];
|
||||
var is_clicked_top = [];
|
||||
var is_clicked_bottom = [];
|
||||
var is_clicked_left = [];
|
||||
var is_clicked_right = [];
|
||||
var total_clicked = 0;
|
||||
|
||||
var exitIconPositionX;
|
||||
var exitIconPositionY;
|
||||
var exitIconWidth;
|
||||
var exitIconHeight;
|
||||
|
||||
(function init() {
|
||||
util.clearScreen(ctx);
|
||||
ctx.strokeStyle = 'black';
|
||||
ctx.fillStyle = 'lime';
|
||||
ctx.lineWidth = 1;
|
||||
|
||||
// Because width/height of screen can not be divided evenly
|
||||
// So we precaculate the grid (coordination) of cubes for future use
|
||||
for (var i = 0; i < cubes_num_horizontal; i++) {
|
||||
cube_coord_x[i] = Math.round(cube_width * i);
|
||||
}
|
||||
cube_coord_x[cubes_num_horizontal] = canvas.width - 1;
|
||||
for (var i = 0; i < cubes_num_vertical; i++) {
|
||||
cube_coord_y[i] = Math.round(cube_height * i);
|
||||
}
|
||||
cube_coord_y[cubes_num_vertical] = canvas.height - 1;
|
||||
|
||||
// Draw Top/Bottom/Left/Right cubes
|
||||
for (var i = 0; i < cubes_num_horizontal; i++) {
|
||||
util.drawRectFromCoord(ctx, cube_coord_x[i], cube_coord_y[0],
|
||||
cube_coord_x[i + 1], cube_coord_y[1]);
|
||||
is_clicked_top[i] = false;
|
||||
}
|
||||
for (var i = 0; i < cubes_num_horizontal; i++) {
|
||||
util.drawRectFromCoord(ctx,
|
||||
cube_coord_x[i],
|
||||
cube_coord_y[cubes_num_vertical - 1],
|
||||
cube_coord_x[i + 1],
|
||||
cube_coord_y[cubes_num_vertical]);
|
||||
is_clicked_bottom[i] = false;
|
||||
}
|
||||
for (var i = 0; i < cubes_num_vertical; i++) {
|
||||
util.drawRectFromCoord(ctx,
|
||||
cube_coord_x[0],
|
||||
cube_coord_y[i],
|
||||
cube_coord_x[1],
|
||||
cube_coord_y[i + 1]);
|
||||
is_clicked_left[i] = false;
|
||||
}
|
||||
for (var i = 0; i < cubes_num_vertical; i++) {
|
||||
util.drawRectFromCoord(ctx,
|
||||
cube_coord_x[cubes_num_horizontal - 1],
|
||||
cube_coord_y[i],
|
||||
cube_coord_x[cubes_num_horizontal],
|
||||
cube_coord_y[i + 1]);
|
||||
is_clicked_right[i] = false;
|
||||
}
|
||||
|
||||
// Draw exit icon
|
||||
var image = document.getElementById('icon-exit');
|
||||
exitIconWidth = image.width;
|
||||
exitIconHeight = image.height;
|
||||
exitIconPositionX = (canvas.width - exitIconWidth) / 2;
|
||||
exitIconPositionY = (canvas.height - exitIconHeight) / 2;
|
||||
ctx.drawImage(image, exitIconPositionX, exitIconPositionY);
|
||||
}
|
||||
)();
|
||||
|
||||
// Touch test, fill cubes if touch point is in the cube.
|
||||
// Test ends if all cubes are touched
|
||||
this.test = function(x, y) {
|
||||
// Clicked on exit button
|
||||
if (x > exitIconPositionX && x <= exitIconPositionX + exitIconWidth &&
|
||||
y > exitIconPositionY && y <= exitIconPositionY + exitIconHeight) {
|
||||
return Status.ABORT;
|
||||
}
|
||||
|
||||
if (cube_coord_x[1] <= x && x <= cube_coord_x[cubes_num_horizontal - 1] &&
|
||||
cube_coord_y[1] <= y && y <= cube_coord_y[cubes_num_vertical - 1]) {
|
||||
return Status.NOT_FINISHED;
|
||||
}
|
||||
|
||||
var startXi = util.binary_search(cube_coord_x, x);
|
||||
var startYi = util.binary_search(cube_coord_y, y);
|
||||
util.fillRectFromCoord(ctx,
|
||||
cube_coord_x[startXi],
|
||||
cube_coord_y[startYi],
|
||||
cube_coord_x[startXi + 1],
|
||||
cube_coord_y[startYi + 1]);
|
||||
if (startYi == 0 && !is_clicked_top[startXi]) {
|
||||
is_clicked_top[startXi] = true;
|
||||
}
|
||||
if (startYi == cubes_num_vertical - 1 && !is_clicked_bottom[startXi]) {
|
||||
is_clicked_bottom[startXi] = true;
|
||||
}
|
||||
if (startXi == 0 && !is_clicked_left[startYi]) {
|
||||
is_clicked_left[startYi] = true;
|
||||
}
|
||||
if (startXi == cubes_num_horizontal - 1 && !is_clicked_right[startYi]) {
|
||||
is_clicked_right[startYi] = true;
|
||||
}
|
||||
|
||||
for (var i = 0; i < cubes_num_vertical; i++) {
|
||||
if (!is_clicked_left[i] || !is_clicked_right[i]) {
|
||||
return Status.NOT_FINISHED;
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < cubes_num_horizontal; i++) {
|
||||
if (!is_clicked_top[i] || !is_clicked_bottom[i]) {
|
||||
return Status.NOT_FINISHED;
|
||||
}
|
||||
}
|
||||
// Test over
|
||||
return Status.FINISHED;
|
||||
};
|
||||
};
|
||||
|
||||
var test_driver = function() {
|
||||
var current_test = null;
|
||||
var canvas = document.getElementById('canvas');
|
||||
canvas.width = window.innerWidth;
|
||||
canvas.height = window.innerHeight;
|
||||
canvas.style.width = canvas.width + 'px';
|
||||
canvas.style.height = canvas.height + 'px';
|
||||
|
||||
// returns true if no other tests
|
||||
function proceed() {
|
||||
if (current_test == null) {
|
||||
current_test = new test1(canvas);
|
||||
return false;
|
||||
}
|
||||
else if (current_test instanceof test1) {
|
||||
current_test = new test2(canvas);
|
||||
return false;
|
||||
}
|
||||
else if (current_test instanceof test2) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
proceed();
|
||||
|
||||
// returns whether all tests are finished
|
||||
this.touch = function(x, y) {
|
||||
var touchResult = current_test.test(x, y);
|
||||
if (touchResult == Status.ABORT) {
|
||||
return Status.ABORT;
|
||||
}
|
||||
// one test finished, go on next test
|
||||
if (touchResult == Status.FINISHED) {
|
||||
var isAllFinished = proceed();
|
||||
if (isAllFinished) {
|
||||
return Status.FINISHED;
|
||||
}
|
||||
}
|
||||
return Status.NOT_FINISHED;
|
||||
};
|
||||
};
|
||||
|
||||
// Handle touch input, Codes modified from
|
||||
// https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Events/Touch_events
|
||||
var touchTest = function() {
|
||||
var ongoingTouches = [];
|
||||
var driver = null;
|
||||
var canvas = null;
|
||||
|
||||
function copyTouch(touch) {
|
||||
return { identifier: touch.identifier,
|
||||
pageX: touch.pageX,
|
||||
pageY: touch.pageY };
|
||||
}
|
||||
|
||||
function ongoingTouchIndexById(idToFind) {
|
||||
for (var i = 0; i < ongoingTouches.length; i++) {
|
||||
var id = ongoingTouches[i].identifier;
|
||||
|
||||
if (id == idToFind) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return -1; // not found
|
||||
}
|
||||
|
||||
function handleEvent(evt) {
|
||||
var touches = evt.changedTouches;
|
||||
var result;
|
||||
evt.preventDefault();
|
||||
|
||||
switch (evt.type) {
|
||||
case 'touchstart':
|
||||
for (var i = 0; i < touches.length; i++) {
|
||||
ongoingTouches.push(copyTouch(touches[i]));
|
||||
var coord = util.relMouseCoords(canvas, touches[i]);
|
||||
result = driver.touch(coord.x, coord.y);
|
||||
}
|
||||
break;
|
||||
case 'touchmove':
|
||||
for (var i = 0; i < touches.length; i++) {
|
||||
var coord = util.relMouseCoords(canvas, touches[i]);
|
||||
var idx = ongoingTouchIndexById(touches[i].identifier);
|
||||
|
||||
if (idx >= 0) {
|
||||
var coord_last = util.relMouseCoords(canvas, ongoingTouches[idx]);
|
||||
result = driver.touch(coord.x, coord.y);
|
||||
// swap in the new touch record
|
||||
ongoingTouches.splice(idx, 1, copyTouch(touches[i]));
|
||||
} else {
|
||||
console.log('can\'t figure out which touch to continue');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'touchend':
|
||||
for (var i = 0; i < touches.length; i++) {
|
||||
var coord = util.relMouseCoords(canvas, touches[i]);
|
||||
var idx = ongoingTouchIndexById(touches[i].identifier);
|
||||
|
||||
if (idx >= 0) {
|
||||
ongoingTouches.splice(i, 1); // remove it; we're done
|
||||
} else {
|
||||
console.log('can\'t figure out which touch to end');
|
||||
}
|
||||
}
|
||||
break;
|
||||
case 'touchcancel':
|
||||
for (var i = 0; i < touches.length; i++) {
|
||||
ongoingTouches.splice(i, 1); // remove it; we're done
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
// All tests over
|
||||
if (result == Status.FINISHED || result == Status.ABORT) {
|
||||
// Clear remaining touches
|
||||
touches = null;
|
||||
canvas.removeEventListener('touchstart', handleEvent, false);
|
||||
canvas.removeEventListener('touchend', handleEvent, false);
|
||||
canvas.removeEventListener('touchcancel', handleEvent, false);
|
||||
canvas.removeEventListener('touchleave', handleEvent, false);
|
||||
canvas.removeEventListener('touchmove', handleEvent, false);
|
||||
console.log('uninitialized.');
|
||||
|
||||
if (result == Status.ABORT) {
|
||||
alert('Test terminated by user');
|
||||
} else {
|
||||
alert('Test Success!');
|
||||
}
|
||||
document.mozCancelFullScreen();
|
||||
// This is a hack to close touch test, uitest.js will close this iframe
|
||||
window.parent.window.location.hash = '';
|
||||
}
|
||||
}
|
||||
|
||||
this.init = function() {
|
||||
driver = new test_driver();
|
||||
|
||||
if (canvas == null) {
|
||||
canvas = document.getElementsByTagName('canvas')[0];
|
||||
canvas.addEventListener('touchstart', handleEvent, false);
|
||||
canvas.addEventListener('touchend', handleEvent, false);
|
||||
canvas.addEventListener('touchcancel', handleEvent, false);
|
||||
canvas.addEventListener('touchleave', handleEvent, false);
|
||||
canvas.addEventListener('touchmove', handleEvent, false);
|
||||
console.log('initialized.');
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
// XXX: There is a problem of getting into fullscreen
|
||||
// When we called mozRequestFullscreen, it actually resized two times.
|
||||
// We get almost fullscreen (except status bar) after first event, and truely
|
||||
// fullscreen after second event. So we need to wait for the second event.
|
||||
var resizedTimes = 0;
|
||||
window.addEventListener('resize', function startTest() {
|
||||
if (resizedTimes < 1) {
|
||||
resizedTimes++;
|
||||
}
|
||||
else {
|
||||
window.removeEventListener('resize', startTest);
|
||||
var test = new touchTest;
|
||||
test.init();
|
||||
}
|
||||
});
|
||||
|
||||
window.addEventListener('load', function() {
|
||||
document.getElementById('canvas').classList.remove('invisible');
|
||||
var exitButton = document.getElementById('fullscreen-exit');
|
||||
document.body.mozRequestFullScreen();
|
||||
});
|
||||
54
assets/webapps/uitest.gaiamobile.org/js/HW/vibrator.js
Normal file
54
assets/webapps/uitest.gaiamobile.org/js/HW/vibrator.js
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
'use strict';
|
||||
|
||||
function vibratorTest() {
|
||||
var durationText = document.getElementById('duration-text');
|
||||
var duration = document.getElementById('duration');
|
||||
var timesText = document.getElementById('times-text');
|
||||
var times = document.getElementById('times');
|
||||
|
||||
var clickHandlers = {
|
||||
'off': function() {
|
||||
window.navigator.vibrate(0);
|
||||
},
|
||||
'one-short': function() {
|
||||
window.navigator.vibrate(200);
|
||||
},
|
||||
'two-short': function() {
|
||||
window.navigator.vibrate([200, 100, 200, 100]);
|
||||
},
|
||||
'one-long': function() {
|
||||
window.navigator.vibrate(10000);
|
||||
},
|
||||
'custom-pattern': function() {
|
||||
var timesNum = parseInt(times.value);
|
||||
var pattern = [];
|
||||
for (var i = 0; i < timesNum * 2; i++) {
|
||||
pattern.push(parseInt(duration.value));
|
||||
}
|
||||
window.navigator.vibrate(pattern);
|
||||
}
|
||||
};
|
||||
|
||||
// Update text when sliding bar is changed
|
||||
var changeHandlers = {
|
||||
'duration': function() {
|
||||
durationText.textContent = duration.value;
|
||||
},
|
||||
'times': function() {
|
||||
timesText.textContent = times.value;
|
||||
}
|
||||
};
|
||||
|
||||
document.body.addEventListener('click', function(evt) {
|
||||
if (clickHandlers[evt.target.id]) {
|
||||
clickHandlers[evt.target.id].call(this, evt);
|
||||
}
|
||||
});
|
||||
document.body.addEventListener('input', function(evt) {
|
||||
if (changeHandlers[evt.target.id]) {
|
||||
changeHandlers[evt.target.id].call(this, evt);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
window.addEventListener('load', vibratorTest);
|
||||
37
assets/webapps/uitest.gaiamobile.org/js/HW/wifi.js
Normal file
37
assets/webapps/uitest.gaiamobile.org/js/HW/wifi.js
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
'use strict';
|
||||
|
||||
function wifiTest() {
|
||||
var WiFiMACText = document.getElementById('address');
|
||||
var WiFiStateText = document.getElementById('state');
|
||||
var switchButton = document.getElementById('switch');
|
||||
|
||||
var settings = window.navigator.mozSettings;
|
||||
var wifiManager;
|
||||
function update() {
|
||||
switchButton.checked = wifiManager.enabled;
|
||||
if (wifiManager.enabled) {
|
||||
WiFiStateText.textContent = 'On';
|
||||
WiFiMACText.textContent = wifiManager.macAddress;
|
||||
}
|
||||
else {
|
||||
WiFiStateText.textContent = 'Off';
|
||||
WiFiMACText.textContent = 'Not available';
|
||||
}
|
||||
}
|
||||
if ('mozWifiManager' in navigator) {
|
||||
wifiManager = navigator.mozWifiManager;
|
||||
// navigator.mozWifiManager does not have addEventListener()
|
||||
wifiManager.onenabled = update.bind(this);
|
||||
wifiManager.ondisabled = update.bind(this);
|
||||
update();
|
||||
}
|
||||
// Click on switch will only update settings and
|
||||
// it takes some time for hardware to turns on.
|
||||
// That's why we should listen to enabled/disabled event of wifi
|
||||
function wifiSwitch() {
|
||||
settings.createLock().set({'wifi.enabled': switchButton.checked});
|
||||
}
|
||||
switchButton.addEventListener('click', wifiSwitch);
|
||||
}
|
||||
|
||||
window.addEventListener('load', wifiTest);
|
||||
Loading…
Reference in a new issue