DroidScript can't do everything imaginable. But you can help it to come closer to that by writing plugins.
There are basically two types of plugins: JavaScript plugins which will behave like an extra included JS source script and
Java plugins, which have a second compiled part written in java.
A basic JS plugin consists of 2 parts:
- a MyPlugin.inc file containing the main JS source code
- a MyPlugin.html file containing the main page of your plugin documentation.
However you can add as many resources to it as you want.
There is a generator available which can create, debug and install plugins on the fly. you can even debug your plugin directly from that app.
Download it from the dspk store
Writing java plugins is a bit tricky but once you get used to it you can get almost everything working.
There are two types of Java plugin packages:
1. The standard zip file:
- contains a MyPlugin.inc and a MyPlugin.html file as JS plugins
- a MyPlugin.jar file which contains the compiled classes.dex file.
2. An APK file:
- an assets/ folder containing the MyPlugin.inc and the MyPlugin.html file
- a compiled classes.dex file
APK files are typically exported by AndroidStudio, AIDE and others.
That leads us to the ways how you can write and more importantly compile java plugins.
1. The android app 'AIDE'
- Download AIDE from PlayStore
- Create a new AIDE project using the DroidScript SDK in the DS menu
- Modify, Build, Install and Run the plugin app. A popup will appear once the plugin is ready to be installed on the next DroidScript restart
2. AndroidStudio
- There is a UserPlugin template available on DroidScript's GitHub page
- Follow the instructions in this BlogSpot guide
It may be possible with other IDE's as well (ie. IntelliJ even has a AndroidSDK Plugin), but this has not been tested before or just couldn't be made to work.
In order to use the defined Java functions you have to call them from the JS part somehow.
For this purpose DroidScript provides a _CreatePlugin component:
On the Java side following functions in public class MyPlugin { } will get called by DroidScript: