This shows you the differences between two versions of the page.
plugins:own_javascript_plugin [2017/04/04 12:31] 2.29.76.107 |
plugins:own_javascript_plugin [2019/09/17 15:35] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ======Create you own pure Javascript plugins====== | ||
- | =====(Tutorial)===== | ||
- | |||
- | =====Introduction===== | ||
- | |||
- | ===Here is the announcement from Dave, developer of DroidScript: | ||
- | (posted in the DroidScript-Beta-Testers google-group) | ||
- | |||
- | //Hi Guys, | ||
- | For those of you that would like to have a go at creating pure JavaScript plugins for DroidScript, | ||
- | //You simply need to drop this zip file into a folder called / | ||
- | 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. | ||
- | Let us know how you get on :) | ||
- | |||
- | (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, or download the complete zip file) | ||
- | |||
- | ---- | ||
- | |||
- | =====Usage of the Example===== | ||
- | |||
- | ====First Step:==== | ||
- | |||
- | Download the following 4 Files: | ||
- | |||
- | * **File 1: The html-page for the Documentation** | ||
- | |||
- | <code html MyPlugin.html> | ||
- | |||
- | < | ||
- | < | ||
- | |||
- | < | ||
- | < | ||
- | <meta name=" | ||
- | <style type=" | ||
- | </ | ||
- | </ | ||
- | |||
- | < | ||
- | |||
- | <div data-role=" | ||
- | |||
- | <div data-role=" | ||
- | <a href='#' | ||
- | < | ||
- | </ | ||
- | |||
- | <div data-role=" | ||
- | |||
- | <p> Todo: Documentation for MyPlugin</ | ||
- | |||
- | < | ||
- | using the < | ||
- | |||
- | <div class=" | ||
- | |||
- | < | ||
- | |||
- | <div class=" | ||
- | | ||
- | < | ||
- | < | ||
- | |||
- | <div data-role=" | ||
- | < | ||
- | <div id=" | ||
- | app.LoadPlugin( " | ||
- | < | ||
- | function OnStart()< | ||
- | {< | ||
- | & | ||
- | & | ||
- | & | ||
- | & | ||
- | <b id=" | ||
- | & | ||
- | </ | ||
- | & | ||
- | }< | ||
- | < | ||
- | function CallPlugin()< | ||
- | {< | ||
- | & | ||
- | }< | ||
- | |||
- | </ | ||
- | <div name=" | ||
- | <a href="#" | ||
- | <a href="#" | ||
- | <a href="#" | ||
- | </ | ||
- | </ | ||
- | |||
- | |||
- | <div data-role=" | ||
- | < | ||
- | <div id=" | ||
- | app.LoadPlugin( " | ||
- | < | ||
- | function OnStart()< | ||
- | {< | ||
- | & | ||
- | & | ||
- | & | ||
- | & | ||
- | <b id=" | ||
- | & | ||
- | & | ||
- | </ | ||
- | & | ||
- | }< | ||
- | < | ||
- | function CallPlugin()< | ||
- | {< | ||
- | & | ||
- | }< | ||
- | function OnMyReply( txt, num, bool )<br> | ||
- | {< | ||
- | & | ||
- | }< | ||
- | </ | ||
- | <div name=" | ||
- | <a href="#" | ||
- | <a href="#" | ||
- | <a href="#" | ||
- | </ | ||
- | </ | ||
- | |||
- | </ | ||
- | |||
- | </ | ||
- | |||
- | </ | ||
- | </ | ||
- | </ | ||
- | |||
- | * **File 2: The inc-file with the Plugin-code (Javascript)** | ||
- | |||
- | <code Javascript MyPlugin.inc> | ||
- | |||
- | app.CreateMyPlugin = function() | ||
- | { | ||
- | return new MyPlugin(); | ||
- | } | ||
- | |||
- | function MyPlugin() | ||
- | { | ||
- | this.callback = null; | ||
- | |||
- | this.GetVersion = function( num, txt ) | ||
- | { | ||
- | return 1.0; | ||
- | } | ||
- | |||
- | this.MyFunc = function( txt, num, bool ) | ||
- | { | ||
- | this.callback( txt + " World!!", | ||
- | } | ||
- | |||
- | this.SetOnMyReply = function( cb ) | ||
- | { | ||
- | this.callback = cb; | ||
- | } | ||
- | } | ||
- | </ | ||
- | |||
- | * **File 3: The text-file with the Versionnumber** | ||
- | |||
- | <code text Version.txt> | ||
- | 1.00 | ||
- | </ | ||
- | |||
- | * **File 4: A blanc jar-file without any text** | ||
- | |||
- | <code Java MyPlugin.jar> | ||
- | |||
- | </ | ||
- | |||
- | |||
- | ---- | ||
- | |||
- | |||
- | ====Second Step:==== | ||
- | |||
- | Create a Zip-folder called " | ||
- | |||
- | * Select the 4 Files and use a tool on a Windows Desktop-PC like [[http:// | ||
- | * after this process you should have a file with the following structure: | ||
- | |||
- | MyPlugin.zip | ||
- | | ||
- | | ||
- | | ||
- | | ||
- | |||
- | * Now you go on your Android Device to the folder **/ | ||
- | * Copy the zip-file in this folder and start Droidscript | ||
- | * DroidScript imports the Plugin now in the Droidscript-Pluginfolder in the systempath | ||
- | * Now you can see your plugin if you press the left " | ||
- | * The folder **/ | ||
- | |||
- | =====Notes===== | ||
- | |||
- | * If your Plugin had another name like " | ||
- | * 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! | ||
- | * You can make sub folders in the zip file for your documentation images etc | ||
- | |||
- | =====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> | ||
- | |||
- | // | ||
- | function OnStart() | ||
- | { | ||
- | // | ||
- | lay = app.CreateLayout( " | ||
- | |||
- | // | ||
- | txt = app.CreateTextEdit( "" | ||
- | txt.SetHint(" | ||
- | lay.AddChild( txt ); | ||
- | |||
- | btn=app.CreateButton(" | ||
- | btn.SetOnTouch(DeleteUserPlugin); | ||
- | lay.AddChild(btn); | ||
- | |||
- | privFldr = app.GetPrivateFolder( " | ||
- | plgins = app.ListFolder(privFldr); | ||
- | |||
- | lvw = app.CreateListView( plgins, | ||
- | lvw.SetOnTouch( lvw_OnTouch ); | ||
- | |||
- | // | ||
- | app.AddLayout( lay ); | ||
- | } | ||
- | |||
- | |||
- | function lvw_OnTouch( item ) | ||
- | { | ||
- | txt.SetText( item ); | ||
- | } | ||
- | |||
- | |||
- | function DeleteUserPlugin() | ||
- | { | ||
- | var plg = "" | ||
- | if (plg == "" | ||
- | plugDir = privFldr + "/" | ||
- | if (app.FolderExists(plugDir)) | ||
- | { | ||
- | var list = app.ListFolder(plugDir); | ||
- | var yesNo = app.CreateYesNoDialog( " | ||
- | yesNo.SetOnTouch( yesNo_OnTouch ); | ||
- | | ||
- | } | ||
- | } | ||
- | |||
- | |||
- | function yesNo_OnTouch( yesNoresult ) | ||
- | { | ||
- | if( yesNoresult == " | ||
- | { | ||
- | app.DeleteFolder(plugDir); | ||
- | |||
- | app.Alert(" | ||
- | txt.SetText("" | ||
- | } | ||
- | else | ||
- | { | ||
- | app.ShowPopup(" | ||
- | } | ||
- | } | ||
- | |||
- | </ | ||
- | |||
- | |||
- | |||
- | ---- | ||
- | |||
- | ===== Zip file with all 4 files ===== | ||
- | You can find the Zip-file with all 4 files here: {{: | ||
- | |||
- | |||
- | |||
- | |||
- | |||
- | |||