User Tools

Site Tools


plugins:own_javascript_plugin

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
plugins:own_javascript_plugin [2015/07/08 09:00]
octazid add zip file
plugins:own_javascript_plugin [2019/09/17 15:35] (current)
Line 8: Line 8:
  
 //Hi Guys, //Hi Guys,
-For those of you that would like to have a go at creating pure JavaScript plugins for DroidScript, I have attached a sample* plugin zip file to this post.//+For those of you that would like to have a go at creating pure JavaScript plugins for DroidScript, I have attached a {{:wiki:myplugin.zip|sample}}* plugin zip file to this post.//
 //You simply need to drop this zip file into a folder called /sdcard/DroidScript/Plugins on your device and DroidScript will import it into the plugins list along with the sample documentation. //You simply need to drop this zip file into a folder called /sdcard/DroidScript/Plugins on your device and DroidScript will import it into the plugins list along with the sample documentation.
 When you come to renaming and making your own plugins, please make sure you use the same format and case for file names as those shown in this sample. When you come to renaming and making your own plugins, please make sure you use the same format and case for file names as those shown in this sample.
Line 15: Line 15:
 (Note: You can make sub folders in the zip file for your documentation images etc if you like)// (Note: You can make sub folders in the zip file for your documentation images etc if you like)//
  
-*(The Sample is a simple **Zip-File** with 4 files. You can find this files below. All you have to do is to Download the files. Put them in one folder and zip this folder.)+*(The Sample is a simple **Zip-File** with 4 files. You can find this files below. All you have to do is to Download the files. Put them in one folder and zip this folder, or download the complete zip file)
  
 ---- ----
Line 59: Line 59:
  <p>Then you can create an instance of the plugin object when you need it like this:</p>  <p>Then you can create an instance of the plugin object when you need it like this:</p>
   
- <div class="samp">&nbsp;plg = app.CreateObject"MyPlugin" );</div>+ <div class="samp">&nbsp;plg = app.CreateMyPlugin();</div>
        
  <br>  <br>
Line 76: Line 76:
  &nbsp;&nbsp;lay.AddChild( btn );<br><br>  &nbsp;&nbsp;lay.AddChild( btn );<br><br>
  <b id="snip1"  style="font-size:100%">  <b id="snip1"  style="font-size:100%">
- &nbsp;&nbsp;plg = app.CreateObject"MyPlugin" );<br>+ &nbsp;&nbsp;plg = app.CreateMyPlugin();<br>
  </b><br>  </b><br>
  &nbsp;&nbsp;app.AddLayout( lay );<br>  &nbsp;&nbsp;app.AddLayout( lay );<br>
Line 107: Line 107:
  &nbsp;&nbsp;lay.AddChild( btn );<br><br>  &nbsp;&nbsp;lay.AddChild( btn );<br><br>
  <b id="snip2"  style="font-size:100%">  <b id="snip2"  style="font-size:100%">
- &nbsp;&nbsp;plg = app.CreateObject"MyPlugin" );<br>+ &nbsp;&nbsp;plg = app.CreateMyPlugin();<br>
  &nbsp;&nbsp;plg.SetOnMyReply( OnMyReply );<br>  &nbsp;&nbsp;plg.SetOnMyReply( OnMyReply );<br>
  </b><br>  </b><br>
Line 140: Line 140:
  
 <code Javascript MyPlugin.inc> <code Javascript MyPlugin.inc>
 +
 +app.CreateMyPlugin = function() 
 +
 +    return new MyPlugin();
 +}
  
 function MyPlugin() function MyPlugin()
Line 150: Line 155:
  }  }
   
-    this.MyFunc = function( txt, num, bool )  +        this.MyFunc = function( txt, num, bool )  
-    +        
  this.callback( txt + " World!!", num+20, !bool );   this.callback( txt + " World!!", num+20, !bool ); 
  }  }
   
-    this.SetOnMyReply = function( cb )  +        this.SetOnMyReply = function( cb )  
-    +        
  this.callback = cb;   this.callback = cb; 
  }  }
Line 168: Line 173:
 </code> </code>
  
-  * **File 4: A blanc jar-file without any text** +  * **It is no longer necessary to add an empty jar-file and we recommend you do not so**
- +
-<code Java MyPlugin.jar> +
- +
-</code>+
  
  
Line 203: Line 204:
   * You can make sub folders in the zip file for your documentation images etc   * You can make sub folders in the zip file for your documentation images etc
  
-=====How can uninstall your plugin?=====+=====How can you uninstall your plugin?===== 
 + 
 +There are two ways at the moment: 
 +You can download and run the following script if you want uninstall a plugin or you uninstall and reinstall Droidscript completely. Using the second option causes all your plugins to be uninstalled so you have to reinstall all plugins. 
 + 
 +<code javascript UninstallPlugin.js> 
 + 
 +//Called when application is started. 
 +function OnStart() 
 +
 +    //Create a layout with objects vertically centered. 
 +    lay = app.CreateLayout( "linear", "VCenter,FillXY" );     
 + 
 +    //Create a text label and add it to layout. 
 +    txt = app.CreateTextEdit( "" ); 
 +    txt.SetHint("Plugin to delete"
 +    lay.AddChild( txt ); 
 + 
 +    btn=app.CreateButton("Delete Plugin"); 
 +    btn.SetOnTouch(DeleteUserPlugin); 
 +    lay.AddChild(btn); 
 +     
 +    privFldr = app.GetPrivateFolder( "Plugins" ); 
 +    plgins = app.ListFolder(privFldr); 
 + 
 +    lvw = app.CreateListView( plgins, "Select a Plugin for uninstalling or press Back" ); 
 +    lvw.SetOnTouch( lvw_OnTouch ); 
 + 
 +    //Add layout to app.     
 +    app.AddLayout( lay ); 
 + 
 +    lvw.Show(); 
 +
 + 
 + 
 +function lvw_OnTouch( item ) 
 +
 +  txt.SetText( item ); 
 +
 + 
 + 
 +function DeleteUserPlugin() 
 +
 +    var plg = "" + txt.GetText() 
 +    if (plg == "") return; 
 +    plugDir = privFldr + "/" + plg.toLowerCase(); 
 +    if (app.FolderExists(plugDir)) 
 +    { 
 +       var list = app.ListFolder(plugDir); 
 +       var yesNo = app.CreateYesNoDialog( "Do you really want to uninstall the plugin " + txt.GetText() + "? \nThe following files or folders will be all deleted:\n\n" + list + "\n\nIt is no way for undo!"); 
 +       yesNo.SetOnTouch( yesNo_OnTouch ); 
 +       yesNo.Show(); 
 +    } 
 +
 + 
 + 
 +function yesNo_OnTouch( yesNoresult ) 
 +
 +    if( yesNoresult == "Yes" ) 
 +    {  
 +        app.DeleteFolder(plugDir); 
 +         
 +        app.Alert("Plugin " + txt.GetText() + " uninstalled!"); 
 +        txt.SetText(""); 
 +    } 
 +    else 
 +    { 
 +        app.ShowPopup("No changings!"); 
 +    } 
 +
 + 
 +</code> 
  
  
plugins/own_javascript_plugin.1436346053.txt.gz · Last modified: 2015/07/08 17:00 (external edit)