123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- addEvent("onload", init);
- addEvent("onresize", checkOrientation);
- var screenmode = 0;
- var xAxis = 0;
- var yAxis = 0;
- var zAxis = 0;
- var Rotation_timeStamp = null;
- var Rotation_Rotation = null;
- var Accelerometer_timeStamp = null;
- var Accelerometer_AxisData = null;
- var Orientation_timeStamp = null;
- var Orientation_deviceOrientation = null;
- function init(){
-
- Rotation_timeStamp = document.getElementById("Rotation_timeStamp");
- Rotation_Rotation = document.getElementById("Rotation_Rotation");
-
- Accelerometer_timeStamp = document.getElementById("Accelerometer_timeStamp");
- Accelerometer_AxisData = document.getElementById("Accelerometer_AxisData");
-
- Orientation_timeStamp = document.getElementById("Orientation_timeStamp");
- Orientation_deviceOrientation = document.getElementById("Orientation_deviceOrientation");
-
-
- try {
- var myStyleTweaks = new StyleTweaker();
- myStyleTweaks.add("Series60/5.0", "styles/tweaks/S605th.css");
- myStyleTweaks.add("Series60/3.2", "styles/tweaks/S603rdFP2.css");
- myStyleTweaks.tweak();
- // Initiate toggle switch components for enabling / disabling each supported channel
- var toggle_rotation = new ToggleSwitch("toggle_sensors_rotation", toggle_sensors_rotation_click);
- var toggle_accelerometer = new ToggleSwitch("toggle_sensors_accelerometer", toggle_sensors_accelerometer_click);
- var toggle_orientation = new ToggleSwitch("toggle_sensors_orientation", toggle_sensors_orientation_click);
- initSensors();
-
-
- }
-
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- function checkOrientation(){
- try {
- var width = parseInt(screen.width);
- var height = parseInt(screen.height);
-
- //var landscapeTweaker = new StyleTweaker();
- // Landscape tweaks for template styles not available in templates?
- //landscapeTweaker.add("Series60/5.0", "../resources/styles/tweaks/S605thLandscape.css");
-
- if (width > height) {
-
- // if already in landscape mode, return
- if (screenmode == 1)
- return;
- // landscapeTweaker.tweak();
- screenmode = 1;
- }
- else {
- // if already in portrait mode, return
- if (screenmode == 0)
- return;
- // landscapeTweaker.untweak();
- screenmode = 0;
-
- }
- }
-
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- // Callback handler for rotation channel toggle click(Nokia templates object)
- function toggle_sensors_rotation_click(actionobj){
- try {
-
- var state = actionobj.getAttribute("class");
- var on = state.search(/on/) + 1;
- if (on) {
- startRotationSensorChannel();
- }
- else {
- MystopChannel("Rotation");
- }
-
- }
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- // Callback handler for rotation channel toggle click (Nokia templates object)
- function toggle_sensors_orientation_click(actionobj){
- try {
-
- var state = actionobj.getAttribute("class");
- var on = state.search(/on/) + 1;
- if (on) {
-
- startOrientationSensorChannel();
- }
- else {
- MystopChannel("Orientation");
- }
-
- }
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- // Callback handler for accelerometer channel toggle click (Nokia templates object)
- function toggle_sensors_accelerometer_click(actionobj){
- try {
-
- var state = actionobj.getAttribute("class");
- var on = state.search(/on/) + 1;
- if (on) {
- startAccelerometerAxisSensorChannel();
- }
- else {
- MystopChannel("AccelerometerAxis");
- }
-
- }
- catch (e) {
- var error = e.toString();
- alert(error);
- }
- }
- /*
- Displays XYZ channel sensor data in widget ui.
- sensordata object is passed to display function in
- service platform asyncronous callback handlers. sensordata schema:
- "timeStamp": Date,
- "rotationAboutXAxis": Number,
- "rotationAboutYAxis": Number,
- "rotationAboutZAxis": Number
- */
- function displayRotationChannel(sensordata){
- try {
- if (sensordata.timeStamp && sensordata.rotationAboutXAxis.toString.length
- && sensordata.rotationAboutYAxis.toString.length && sensordata.rotationAboutZAxis.toString.length) {
-
- if (xAxis != sensordata.rotationAboutXAxis ||
- yAxis != sensordata.rotationAboutYAxis ||
- zAxis != sensordata.rotationAboutZAxis) {
-
- xAxis = sensordata.rotationAboutXAxis;
- yAxis = sensordata.rotationAboutYAxis;
- zAxis = sensordata.rotationAboutZAxis;
-
- Rotation_timeStamp.innerHTML = (typeof sensordata.timeStamp == 'number'? new Date(sensordata.timeStamp).toLocaleString() : sensordata.timeStamp);
- Rotation_Rotation.innerHTML = "X: " + xAxis + ", Y: " + yAxis + ", Z: " + zAxis;
- }
- }
- }
- catch (e) {
- var error = e.toString();
- alert("displayRotationChannel " +error);
- }
- }
- /*
- Displays Accelerometer channel sensor data in widget ui.
- sensordata object is passed to display function in
- service platform asyncronous callback handlers. sensordata schema:
- /*
- {
- "timeStamp": Date,
- "axisX": Number,
- "axisY": Number,
- "axisZ": Number
- }
- */
- function displayAccelerometerAxisChannel(sensordata){
- try {
- if (sensordata.timeStamp && sensordata.axisX.toString.length
- && sensordata.axisY.toString.length && sensordata.axisZ.toString.length) {
- Accelerometer_timeStamp.innerHTML = (typeof sensordata.timeStamp == 'number'? new Date(sensordata.timeStamp).toLocaleString() : sensordata.timeStamp);;
- Accelerometer_AxisData.innerHTML = "X: " + sensordata.axisX + ", Y: " + sensordata.axisY + ", Z: " + sensordata.axisZ;
- }
- }
- catch (e) {
- var error = e.toString();
- alert("displayAccelerometerAxisChannel" + error);
- }
- }
- /*
- Displays orientation channel sensor data in widget ui.
- sensordata object is passed to display function in
- service platform asyncronous callback handlers. sensordata schema:
- {
- "timeStamp": Date,
- "deviceOrientation": String // supported values are DisplayUp, DisplayDown, DisplayLeftUp, DisplayRightUp, DisplayUpwards, and DisplayDownwards.
- }
- */
- function displayOrientationChannel(sensordata){
- try {
- if (sensordata.timeStamp && sensordata.deviceOrientation.length) {
- Orientation_timeStamp.innerHTML = (typeof sensordata.timeStamp == 'number'? new Date(sensordata.timeStamp).toLocaleString() : sensordata.timeStamp);
- Orientation_deviceOrientation.innerHTML = sensordata.deviceOrientation;
- }
- }
- catch (e) {
- var error = e.toString();
- alert("displayOrientationChannel" +error);
- }
- }
|