Adding a Custom Plug-in to the Windows Mobile Hybrid Web Container

This procedure shows an example of adding a plug-in class that allows access to the Windows Mobile calculator.

The plug-in class is available under the TPTools\phoneGap\wm directory. To include this plug-in in the Hybrid Web Container, follow these steps:

  1. Add a new class called Calculator into the folder CustomCode and implement the code:
    using   WMGapClassLib.Cordova;       
    namespace Sybase.Hwc.CustomCode   
    {   
       public class Calculator : PluginBase   
       {   
          public void sum(Session session, Sybase.HybridApp.Util.Json.JsonObject arguments)   
          {   
             try   
             {   
                double x = 0;   
                double y = 0;   
                x = double.Parse(arguments.GetString("x"));   
                y = double.Parse(arguments.GetString("y"));       
                this.DispatchCommandResult(session, new PluginResult(PluginResult.Status.OK, x + y));   
             }   
             catch (System.Exception ex)   
             {   
                this.DispatchCommandResult(session, new PluginResult(PluginResult.Status.ERROR, ex.Message));   
             }       
          }   
       }   
    } 
  2. Open the file Plugins.xml, which is located in the HybridWebContainer project, and add the custom plug-in:
    <?xml version="1.0" encoding="utf-8" ?>   
    <plugins>   
      <plugin id="showcertpicker"
            class="Sybase.Hwc.CertificationPickerPlugin"/>       
      <plugin id="Calculator" class="Sybase.Hwc.CustomCode.Calculator"/>   
    </plugins> 
  3. Open the Custom.js file for editing and add this method:
    function calculateSum(x, y, successCb, errorCb){ 
    cordova.require('cordova/exec') (
            successCb, 
            errorCb, 
           "Calculator", "sum", 
    { x: document.getElementById('x').value, y: document.getElementById('y').value }); 
    }
  4. Call this JavaScript method somewhere else to get the result:
    function doCalculateSum() {                  
          calculateSum(   
                                   
            document.getElementById('x').value,                                  
            document.getElementById('y').value,   
            function (res){                                                  
            document.getElementById('res').innerHTML = res;   
                                    },   
           function (e) {   
                                                   
            console.log("Error occurred: " + e);   
                                                   
            document.getElementById('res').innerHTML = "Error occurred: " + e;   
           });   
    }; 
  5. Generate and deploy the application and test the event in the custom.js file that is hooked into the new plug-in.