Uploaded version 4 of DroidScript today, including new example programs! (I use plain sequential version numbers; version 4 is very much in an early experimental stage!) Download info can be found here: http://droidscript.blogspot.com/2010/03/droidscript-getting-started.html
If you already have DroidScript installed, you need to manually update the JavaScript files on the SD-card. One method is to delete the JavaScript files in the droidscript folder on the SD-card; if they are missing when the app started, they will be downloaded automatically. An easier method is to open DroidScript, press the menu button on the device, and select "Update". That will download and overwrite the JavaScript files in the droidscript folder with the latest versions. Then restart DroidScript.
This whole process can of course be improved. One idea is to make DroidScript check the update server for a new version number, and update the JavaScript code if needed. Admittedly, it is a bit of a hazzle to keep track of updating the actual app and the JavaScript files on the SD-card. But there is also a reason for making manual updates; the user might have modified the JavaScript code, and may wish to save the modifications before updating.
The motivation for putting JavaScript files on the SD-card is highest possible transparency. A user always has access to the content of the card, and can easily inspect and edit the JavaScript code if she wishes. This way, DroidScript is much more malleable and exploration-friendly, compared to putting the code hidden away in the application's private space. The drawback is that files might be messed up, and if you swap SD-cards the files are not there anymore (buy then they will be dynamically downloaded).
New in this version is improved error handling, a new view class for writing graphical applications, and more examples programs.
Errors are now trapped in a more robust way, and the application does no longer shut down in case of runtime JavaScript errors. The notification bar is used to display JavaScript errors. It is a big advantage that notifications are decoupled from the application, so if the application becomes faulty, it is still possible to retrieve the error message form the notification bar. Errors are also logged to the logcat output.
A problem with scripting Java from JavaScript on Android is that there is no support for generating Dalvik byte code, and this is needed for subclassing. This means that subclassing of Java classes in JavaScript is not possible. Since the Android API relies heavily on subclassing in certain areas, this sort of spoils the party. Subclassing View to create your own view class with custom drawing, is impossible, for example. However, a nice solution is to make a subclass of View in Java that has pluggable listeners for drawing and other events that normally would be handled through subclassing. This way, we also get a much nice design that allows for runtime configuration of for example the drawing behaviour (subclassing is one nasty compile-time bound relation that I would be happy to avoid and replace by delegation).
The new DroidScript version includes a Java class called Morph that has pluggable listeners for drawing and interaction behaviours, which makes it possible to write JavaScript apps with custom graphical rendering, such as games and painting programs. The name "Morph" means "Shape" and is taken from Self/Squeak; but the DroidScript Morph is nowhere nearly as powerful as a Squeak morph, but it might be one day :-)
There are two new example programs included with the version of DroidScript, a program that displays random colours when the screen is pressed, and a painting program. The speed of the painting program shows that JavaScript applications can run at satisfactory speed on Android (at least on a Nexus One).
Here is the source code of the example programs:
http://github.com/divineprog/droidscript/blob/master/javascript/Colors.js
http://github.com/divineprog/droidscript/blob/master/javascript/Paint.js
The example programs are included in the latest version of DroidScript, so you can run them directly on the device, and you can also copy and paste them into the DroidScript Live Editor and run them from there.
Monday, April 5, 2010
Subscribe to:
Post Comments (Atom)
0 comments:
Post a Comment