basic.js 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. addEvent("onload", init);
  2. addEvent("onresize", checkOrientation);
  3. var channelmonitoractive = false;
  4. var screenmode = 0;
  5. var label_start_monitor_label = "START MONITOR";
  6. var label_stop_monitor_label = "STOP MONITOR";
  7. var channel_data_initial_value = "INITIAL";
  8. var ChargingPollTimer = null;
  9. function init(){
  10. try {
  11. document.getElementById("MonitorToggle").innerHTML = label_start_monitor_label;
  12. var myStyleTweaks = new StyleTweaker();
  13. myStyleTweaks.add("Series60/5.0", "styles/tweaks/S605th.css");
  14. myStyleTweaks.add("Series60/3.2", "styles/tweaks/S603rdFP2.css");
  15. myStyleTweaks.tweak();
  16. // Set the timer to update charging channel at three second intervals
  17. // because it does not support notification style calling
  18. ChargingPollTimer = setInterval("pollChargingChannel()", 3000);
  19. initSystemServices();
  20. }
  21. catch (e) {
  22. var error = e.toString();
  23. alert(error);
  24. }
  25. }
  26. /*
  27. Polls for charging channel and if monitoring active, updates widget UI
  28. */
  29. function pollChargingChannel(){
  30. try {
  31. if (channelmonitoractive) {
  32. displayChargingChannel(GetChargingChannel());
  33. }
  34. }
  35. catch (e) {
  36. var error = e.toString();
  37. alert(error);
  38. }
  39. }
  40. function checkOrientation(){
  41. try {
  42. var width = parseInt(screen.width);
  43. var height = parseInt(screen.height);
  44. //var landscapeTweaker = new StyleTweaker();
  45. // Landscape tweaks for template styles not available in templates?
  46. //landscapeTweaker.add("Series60/5.0", "../resources/styles/tweaks/S605thLandscape.css");
  47. if (width > height) {
  48. // if already in landscape mode, return
  49. if (screenmode == 1)
  50. return;
  51. screenmode = 1;
  52. // landscapeTweaker.tweak();
  53. }
  54. else {
  55. // if already in portrait mode, return
  56. if (screenmode == 0)
  57. return;
  58. screenmode = 0;
  59. // landscapeTweaker.untweak();
  60. }
  61. }
  62. catch (e) {
  63. var error = e.toString();
  64. alert(error);
  65. }
  66. }
  67. /*
  68. Onclik handler for start/stop monitoring button
  69. Starts and stops channel monitoring
  70. */
  71. function MonitorToggle_onclick(actionobj){
  72. try {
  73. if (channelmonitoractive) {
  74. actionobj.innerHTML = label_start_monitor_label;
  75. StopChannelMonitoring()
  76. }
  77. else {
  78. actionobj.innerHTML = label_stop_monitor_label;
  79. StartChannelMonitoring()
  80. }
  81. channelmonitoractive = !channelmonitoractive;
  82. }
  83. catch (e) {
  84. var error = e.toString();
  85. alert(error);
  86. }
  87. }
  88. /*
  89. Displays charging channel data in widget ui
  90. {
  91. "chargingStatus ": Boolean // Possible values are true (charging ) and false (not charging)
  92. }
  93. */
  94. function displayChargingChannel(channelData){
  95. try {
  96. document.getElementById("channelCharging").innerHTML = channelData.chargingStatus;
  97. }
  98. catch (e) {
  99. var error = e.toString();
  100. alert(error);
  101. }
  102. }
  103. /*
  104. Displays battery level channel data in widget ui.
  105. outPut object is passed to display function in
  106. service platform asyncronous callback handlers. Schema:
  107. {
  108. "batteryLevel ": Number // Percent charge, 0-100
  109. }
  110. */
  111. function displayBatterylevelChannel(outPut){
  112. try {
  113. document.getElementById("channelBatterylevel_batteryLevel").innerHTML = outPut.batteryLevel + "%";
  114. }
  115. catch (e) {
  116. var error = e.toString();
  117. alert(error);
  118. }
  119. }
  120. /*
  121. Displays signal channel data in widget ui.
  122. outPut object is passed to display function in
  123. service platform asyncronous callback handlers. Schema:
  124. {
  125. "signalStrength ": Number // Percent signal strength, 0-100
  126. }
  127. */
  128. function displaySignalChannel(outPut){
  129. try {
  130. //Note : signalStrength is returned interms of decibels by S60. Approximate conversion is made to get the value in percentage.
  131. document.getElementById("channelSignal_signalStrength").innerHTML = outPut.signalStrength + " %";
  132. }
  133. catch (e) {
  134. var error = e.toString();
  135. alert(error);
  136. }
  137. }
  138. /*
  139. Displays network channel data in widget ui.
  140. outPut object is passed to display function in
  141. service platform asyncronous callback handlers. Schema:
  142. {
  143. "networkName ": String ,// Provides the network name
  144. "networkStatus": String, // Refer networkStatus for the possible values.
  145. "networkMode" : String, // Possible values are ModeGsm,ModeCdma,ModeWcdma
  146. "mobileCountryCode" : String, //Mobile Country Code (MCC)
  147. "mobileNetworkCode" : String, // Mobile Network Code (MNC)
  148. "locationStatus" : Boolean, // true if LAC, CellId are valid, otherwise false
  149. "areaCode" : Number ,// Location Area Code (LAC) (Currently not supported)
  150. "cellID" : Number // CellId (Currently not supported)
  151. }
  152. */
  153. function displayNetworkChannel(outPut){
  154. try {
  155. document.getElementById("channelNetwork_networkName").innerHTML = outPut.networkName;
  156. document.getElementById("channelNetwork_networkStatus").innerHTML = outPut.networkStatus;
  157. document.getElementById("channelNetwork_networkMode").innerHTML = outPut.networkMode;
  158. document.getElementById("channelNetwork_mobileCountryCode").innerHTML = outPut.mobileCountryCode;
  159. document.getElementById("channelNetwork_mobileNetworkCode").innerHTML = outPut.mobileNetworkCode;
  160. document.getElementById("channelNetwork_locationStatus").innerHTML = outPut.locationStatus;
  161. }
  162. catch (e) {
  163. var error = e.toString();
  164. alert(error);
  165. }
  166. }
  167. /*
  168. This function puts initial label for all channeldata elements in UI
  169. */
  170. function UIResetChannels() {
  171. try {
  172. document.getElementById("channelCharging").innerHTML = channel_data_initial_value;
  173. document.getElementById("channelSignal_signalStrength").innerHTML = channel_data_initial_value;
  174. document.getElementById("channelBatterylevel_batteryLevel").innerHTML = channel_data_initial_value;
  175. document.getElementById("channelNetwork_networkName").innerHTML = channel_data_initial_value;
  176. document.getElementById("channelNetwork_networkStatus").innerHTML = channel_data_initial_value;
  177. document.getElementById("channelNetwork_networkMode").innerHTML = channel_data_initial_value;
  178. document.getElementById("channelNetwork_mobileCountryCode").innerHTML = channel_data_initial_value;
  179. document.getElementById("channelNetwork_mobileNetworkCode").innerHTML = channel_data_initial_value;
  180. document.getElementById("channelNetwork_locationStatus").innerHTML = channel_data_initial_value;
  181. }
  182. catch (e) {
  183. var error = e.toString();
  184. alert(error);
  185. }
  186. }