org.symbian.tools.wrttools.doc.WebDeveloper/html/GUID-2D47E7D9-199D-4D59-BD6A-592FA9F8B16A.html
changeset 229 716254ccbcc0
equal deleted inserted replaced
228:913c9751c067 229:716254ccbcc0
       
     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">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
       
    19 &lt;!DOCTYPE plist PUBLIC "-//Nokia//DTD PLIST 1.0//EN" "http://www.nokia.com/NOKIA_COM_1/DTDs/plist-1.0.dtd"&gt;
       
    20 &lt;plist version="1.0"&gt;
       
    21 &lt;dict&gt;
       
    22   &lt;key&gt;DisplayName&lt;/key&gt;
       
    23   &lt;string&gt;AppManagerSample&lt;/string&gt;
       
    24   &lt;key&gt;Identifier&lt;/key&gt;
       
    25   &lt;string&gt;com.nokia.widget.sapi.appmanager.sample&lt;/string&gt;
       
    26   &lt;key&gt;Version&lt;/key&gt;
       
    27   &lt;string&gt;1.0&lt;/string&gt;
       
    28   &lt;key&gt;MainHTML&lt;/key&gt;
       
    29   &lt;string&gt;appmanager-sample.html&lt;/string&gt;
       
    30 &lt;/dict&gt;
       
    31 &lt;/plist&gt;</pre>
       
    32 </div>
       
    33 <div><h3>AppManager-sample.html</h3>
       
    34 <pre class="codeblock" id="GUID-5A405838-8192-438B-9114-297402F253C5">&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt;
       
    35 &lt;html&gt;
       
    36   &lt;head&gt;
       
    37     &lt;script type="text/javascript" src="js/common.js"&gt;&lt;/script&gt;
       
    38     &lt;script type="text/javascript" src="js/appmanager-sample.js"&gt;&lt;/script&gt;
       
    39   &lt;/head&gt;
       
    40   &lt;body id='docBody' bgcolor="#ddeeff" onload="setup()" style=width:100%;height:100%;&gt;
       
    41 
       
    42     &lt;form name="frm"&gt;
       
    43     	&lt;h3&gt;AppManager API Sample Widget&lt;/h3&gt;
       
    44       &lt;input type="button" onclick="getList('img1')" value="GetList"&gt;&lt;img id="img1" src="pic/blank.png" width="25" height="25" align="center"&gt;&lt;br&gt;
       
    45       &lt;input type="button" onclick="getFilteredList('img2')" value="GetFilteredList"&gt;&lt;img id="img2" src="pic/blank.png" width="25" height="25" align="center"&gt;&lt;br&gt;
       
    46       &lt;input type="button" onclick="launchDoc('img3')" value="LaunchDoc"&gt;&lt;img id="img3" src="pic/blank.png" width="25" height="25" align="center"&gt;&lt;br&gt;
       
    47       &lt;input type="button" onclick="launchApp('img4')" value="LaunchApp"&gt;&lt;img id="img4" src="pic/blank.png" width="25" height="25" align="center"&gt;&lt;br&gt;
       
    48       &lt;input type="button" onclick="launchDocAsync('img5')" value="LaunchDocAsync"&gt;&lt;img id="img5" src="pic/blank.png" width="25" height="25" align="center"&gt;&lt;br&gt;
       
    49       &lt;input type="button" onclick="launchAppAsync('img6')" value="LaunchAppAsync"&gt;&lt;img id="img6" src="pic/blank.png" width="25" height="25" align="center"&gt;&lt;br&gt;
       
    50       &lt;input type="button" onclick="cancelLaunchDocAsync('img7')" value="CancelLaunchDocAsync"&gt;&lt;img id="img7" src="pic/blank.png" width="25" height="25" align="center"&gt;&lt;br&gt;
       
    51       &lt;input type="button" onclick="cancelLaunchAppAsync('img8')" value="CancelLaunchAppAsync"&gt;&lt;img id="img8" src="pic/blank.png" width="25" height="25" align="center"&gt;&lt;hr&gt;
       
    52       &lt;div class='appman' id='appman' bgcolor="#ddeeff" style=width:100%;height:100%;overflow:auto&gt;
       
    53       &lt;/div&gt;
       
    54     &lt;/form&gt;
       
    55   &lt;/body&gt;
       
    56 &lt;/html&gt;</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 &amp;&amp; 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 &amp;&amp; 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 &amp;&amp; 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 &amp;&amp; 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>