|
1 |
|
2 <!DOCTYPE html |
|
3 PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> |
|
4 <html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><meta name="copyright" content="(C) Copyright 2009"/><meta name="DC.rights.owner" content="(C) Copyright 2009"/><meta name="DC.Type" content="mobileconcept"/><meta name="DC.Title" content="AppManager Service API example"/><meta name="DC.Relation" scheme="URI" content="GUID-50795090-A429-41CF-8CAA-EA2004D2643A"/><meta name="DC.Relation" scheme="URI" content="GUID-7C69DDA4-16F1-4A8F-BDB2-4CB0015B4E81"/><meta name="DC.Relation" scheme="URI" content="GUID-65AAF569-D347-462B-B59A-9D7CA184AB9C"/><meta name="DC.Relation" scheme="URI" content="GUID-2D651505-F68C-4053-B565-9FF826C5B897"/><meta name="DC.Format" content="XHTML"/><meta name="DC.Identifier" content="GUID-2D47E7D9-199D-4D59-BD6A-592FA9F8B16A"/><title>AppManager Service API example </title><script type="text/javascript"> |
|
5 function initPage() {} |
|
6 </script><link href="../PRODUCT_PLUGIN/book.css" rel="stylesheet" type="text/css"/><link href="css/s60/style.css" rel="stylesheet" type="text/css" media="all"/></head><body onload="initPage();"><div class="body"><div class="contentLeft prTxt"><h1 class="pageHeading" id="GUID-2D47E7D9-199D-4D59-BD6A-592FA9F8B16A">AppManager Service API example</h1><div> |
|
7 <p/> |
|
8 <p>This section presents the full source code of a working sample widget |
|
9 for the <a href="GUID-E092BF10-C076-4476-9E80-87919940201B.html#GUID-E092BF10-C076-4476-9E80-87919940201B">AppManager |
|
10 Service</a>. You can download the <code>wgz</code> package for |
|
11 this widget from section <a href="GUID-775005BC-2FF8-45A9-BBA6-6CED6B5780A2.html#GUID-775005BC-2FF8-45A9-BBA6-6CED6B5780A2">Example widgets</a>.</p> |
|
12 <p>For general information about creating widgets, see section <a href="GUID-0E3095DB-03FF-4240-83F2-6D876AD2083A.html#GUID-0E3095DB-03FF-4240-83F2-6D876AD2083A">Widget component files</a>.</p> |
|
13 <p>For widget development and debugging purposes, this example writes its |
|
14 output to <code>c:\data\jslog_widget.log</code> using <code>console.info</code>. |
|
15 For instructions on how to enable logging in the Web browser for S60, see |
|
16 section <a href="GUID-B584CA90-543B-4AED-B134-A3A616259DB9.html#GUID-B584CA90-543B-4AED-B134-A3A616259DB9">JavaScript console</a>.</p> |
|
17 <div><h3>Info.plist</h3> |
|
18 <pre class="codeblock" id="GUID-A35E60E0-29C4-4323-843F-15C2B8FF0686"><?xml version="1.0" encoding="UTF-8"?> |
|
19 <!DOCTYPE plist PUBLIC "-//Nokia//DTD PLIST 1.0//EN" "http://www.nokia.com/NOKIA_COM_1/DTDs/plist-1.0.dtd"> |
|
20 <plist version="1.0"> |
|
21 <dict> |
|
22 <key>DisplayName</key> |
|
23 <string>AppManagerSample</string> |
|
24 <key>Identifier</key> |
|
25 <string>com.nokia.widget.sapi.appmanager.sample</string> |
|
26 <key>Version</key> |
|
27 <string>1.0</string> |
|
28 <key>MainHTML</key> |
|
29 <string>appmanager-sample.html</string> |
|
30 </dict> |
|
31 </plist></pre> |
|
32 </div> |
|
33 <div><h3>AppManager-sample.html</h3> |
|
34 <pre class="codeblock" id="GUID-5A405838-8192-438B-9114-297402F253C5"><!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> |
|
35 <html> |
|
36 <head> |
|
37 <script type="text/javascript" src="js/common.js"></script> |
|
38 <script type="text/javascript" src="js/appmanager-sample.js"></script> |
|
39 </head> |
|
40 <body id='docBody' bgcolor="#ddeeff" onload="setup()" style=width:100%;height:100%;> |
|
41 |
|
42 <form name="frm"> |
|
43 <h3>AppManager API Sample Widget</h3> |
|
44 <input type="button" onclick="getList('img1')" value="GetList"><img id="img1" src="pic/blank.png" width="25" height="25" align="center"><br> |
|
45 <input type="button" onclick="getFilteredList('img2')" value="GetFilteredList"><img id="img2" src="pic/blank.png" width="25" height="25" align="center"><br> |
|
46 <input type="button" onclick="launchDoc('img3')" value="LaunchDoc"><img id="img3" src="pic/blank.png" width="25" height="25" align="center"><br> |
|
47 <input type="button" onclick="launchApp('img4')" value="LaunchApp"><img id="img4" src="pic/blank.png" width="25" height="25" align="center"><br> |
|
48 <input type="button" onclick="launchDocAsync('img5')" value="LaunchDocAsync"><img id="img5" src="pic/blank.png" width="25" height="25" align="center"><br> |
|
49 <input type="button" onclick="launchAppAsync('img6')" value="LaunchAppAsync"><img id="img6" src="pic/blank.png" width="25" height="25" align="center"><br> |
|
50 <input type="button" onclick="cancelLaunchDocAsync('img7')" value="CancelLaunchDocAsync"><img id="img7" src="pic/blank.png" width="25" height="25" align="center"><br> |
|
51 <input type="button" onclick="cancelLaunchAppAsync('img8')" value="CancelLaunchAppAsync"><img id="img8" src="pic/blank.png" width="25" height="25" align="center"><hr> |
|
52 <div class='appman' id='appman' bgcolor="#ddeeff" style=width:100%;height:100%;overflow:auto> |
|
53 </div> |
|
54 </form> |
|
55 </body> |
|
56 </html></pre> |
|
57 </div> |
|
58 <div><h3>common.js</h3> |
|
59 <pre class="codeblock" id="GUID-21B896E2-D1B1-40D8-A2D4-29DB48BA44F4">// common.js |
|
60 // |
|
61 // This file contains some utility functions |
|
62 |
|
63 // Check the error code and show the information to users |
|
64 function checkError(message, resultList, divId, imgId) |
|
65 { |
|
66 var errCode = resultList.ErrorCode; |
|
67 var msg = ""; |
|
68 |
|
69 if (errCode) { |
|
70 msg = message + "QBRZ" + "Failed Error: " + errCode + "QBRZ"; |
|
71 if(resultList.ErrorMessage != undefined) |
|
72 msg += "Error Message: " + resultList.ErrorMessage; |
|
73 showIMG(imgId,"no"); |
|
74 } else { |
|
75 showIMG(imgId,"yes"); |
|
76 } |
|
77 |
|
78 //Print error message |
|
79 if(divId != null && divId != undefined) |
|
80 document.getElementById(divId).innerHTML = msg; |
|
81 console.info(msg); |
|
82 |
|
83 return errCode; |
|
84 } |
|
85 |
|
86 // Build the message by reading an iterable list in a recursive manner |
|
87 function showIterableList(iterator) |
|
88 { |
|
89 var msg = ""; |
|
90 try |
|
91 { |
|
92 iterator.reset(); |
|
93 var item; |
|
94 while (( item = iterator.getNext()) != undefined ){ |
|
95 msg += showObject( item ); |
|
96 } |
|
97 } |
|
98 catch(e) |
|
99 { |
|
100 alert('QshowIterableListZ ' + e); |
|
101 } |
|
102 return msg; |
|
103 } |
|
104 |
|
105 // Build the message by reading a JS object in a recursive manner |
|
106 function showObject( obj ) |
|
107 { |
|
108 var txt = ""; |
|
109 try { |
|
110 if ( typeof obj != 'object' ) |
|
111 return "" + obj + 'QBR/Z'; |
|
112 else { |
|
113 for(var key in obj) { |
|
114 txt += key + ":"; |
|
115 txt += showObject( obj[key] ); |
|
116 txt += 'QBR/Z'; |
|
117 } |
|
118 txt += 'QBR/Z'; |
|
119 } |
|
120 } |
|
121 catch (e) |
|
122 { |
|
123 alert("showObject: " + e); |
|
124 } |
|
125 return txt; |
|
126 } |
|
127 |
|
128 // Show the image to indicate the test result |
|
129 function showIMG(imgId, isOK) |
|
130 { |
|
131 if(imgId == null || imgId == undefined) |
|
132 return; |
|
133 |
|
134 if(isOK == "yes") |
|
135 document.getElementById(imgId).src = "pic/yes.png"; |
|
136 else if(isOK == "no") |
|
137 document.getElementById(imgId).src = "pic/no.png"; |
|
138 else |
|
139 document.getElementById(imgId).src = "pic/blank.png"; |
|
140 } |
|
141 |
|
142 // Show elements in object by using 'alert' |
|
143 function testObject(obj) |
|
144 { |
|
145 var msg = ""; |
|
146 for(var key in obj) { |
|
147 msg = msg + ":" + key + "=" + obj[key]; |
|
148 } |
|
149 alert(msg); |
|
150 } |
|
151 |
|
152 // Test whether the input is numeric |
|
153 function IsNumeric(sText) |
|
154 { |
|
155 var ValidChars = "0123456789."; |
|
156 var IsNumber=true; |
|
157 var Char; |
|
158 |
|
159 for (i = 0; i Q sText.length && IsNumber == true; i++) |
|
160 { |
|
161 Char = sText.charAt(i); |
|
162 if (ValidChars.indexOf(Char) == -1) |
|
163 { |
|
164 IsNumber = false; |
|
165 } |
|
166 } |
|
167 return IsNumber; |
|
168 } |
|
169 </pre> |
|
170 </div> |
|
171 <div><h3>AppManager-sample.js</h3> |
|
172 <pre class="codeblock" id="GUID-05F658FA-CDFE-40BD-BAAD-18FF22B7B0CA">// common.js |
|
173 // |
|
174 // This file contains some utility functions |
|
175 |
|
176 // Check the error code and show the information to users |
|
177 function checkError(message, resultList, divId, imgId) |
|
178 { |
|
179 var errCode = resultList.ErrorCode; |
|
180 var msg = ""; |
|
181 |
|
182 if (errCode) { |
|
183 msg = message + "QBRZ" + "Failed Error: " + errCode + "QBRZ"; |
|
184 if(resultList.ErrorMessage != undefined) |
|
185 msg += "Error Message: " + resultList.ErrorMessage; |
|
186 showIMG(imgId,"no"); |
|
187 } else { |
|
188 showIMG(imgId,"yes"); |
|
189 } |
|
190 |
|
191 //Print error message |
|
192 if(divId != null && divId != undefined) |
|
193 document.getElementById(divId).innerHTML = msg; |
|
194 console.info(msg); |
|
195 |
|
196 return errCode; |
|
197 } |
|
198 |
|
199 // Build the message by reading an iterable list in a recursive manner |
|
200 function showIterableList(iterator) |
|
201 { |
|
202 var msg = ""; |
|
203 try |
|
204 { |
|
205 iterator.reset(); |
|
206 var item; |
|
207 while (( item = iterator.getNext()) != undefined ){ |
|
208 msg += showObject( item ); |
|
209 } |
|
210 } |
|
211 catch(e) |
|
212 { |
|
213 alert('QshowIterableListZ ' + e); |
|
214 } |
|
215 return msg; |
|
216 } |
|
217 |
|
218 // Build the message by reading a JS object in a recursive manner |
|
219 function showObject( obj ) |
|
220 { |
|
221 var txt = ""; |
|
222 try { |
|
223 if ( typeof obj != 'object' ) |
|
224 return "" + obj + 'QBR/Z'; |
|
225 else { |
|
226 for(var key in obj) { |
|
227 txt += key + ":"; |
|
228 txt += showObject( obj[key] ); |
|
229 txt += 'QBR/Z'; |
|
230 } |
|
231 txt += 'QBR/Z'; |
|
232 } |
|
233 } |
|
234 catch (e) |
|
235 { |
|
236 alert("showObject: " + e); |
|
237 } |
|
238 return txt; |
|
239 } |
|
240 |
|
241 // Show the image to indicate the test result |
|
242 function showIMG(imgId, isOK) |
|
243 { |
|
244 if(imgId == null || imgId == undefined) |
|
245 return; |
|
246 |
|
247 if(isOK == "yes") |
|
248 document.getElementById(imgId).src = "pic/yes.png"; |
|
249 else if(isOK == "no") |
|
250 document.getElementById(imgId).src = "pic/no.png"; |
|
251 else |
|
252 document.getElementById(imgId).src = "pic/blank.png"; |
|
253 } |
|
254 |
|
255 // Show elements in object by using 'alert' |
|
256 function testObject(obj) |
|
257 { |
|
258 var msg = ""; |
|
259 for(var key in obj) { |
|
260 msg = msg + ":" + key + "=" + obj[key]; |
|
261 } |
|
262 alert(msg); |
|
263 } |
|
264 |
|
265 // Test whether the input is numeric |
|
266 function IsNumeric(sText) |
|
267 { |
|
268 var ValidChars = "0123456789."; |
|
269 var IsNumber=true; |
|
270 var Char; |
|
271 |
|
272 for (i = 0; i Q sText.length && IsNumber == true; i++) |
|
273 { |
|
274 Char = sText.charAt(i); |
|
275 if (ValidChars.indexOf(Char) == -1) |
|
276 { |
|
277 IsNumber = false; |
|
278 } |
|
279 } |
|
280 return IsNumber; |
|
281 } |
|
282 </pre> |
|
283 </div> |
|
284 </div></div></div><div class="footer"><hr/><div class="copy">© Nokia 2009.</div></div></body></html> |