Mittwoch, 27. Juni 2012

Android-Binding for GNU Smalltalk ready!

Essentially it's no big thing - just a few lines of Smalltalk-code: i created a GNU Smalltalk star Package including the "Android" class that gives access to the full Android API via SL4A.
Usage is simple. First file in the package with:

PackageLoader fileInPackage: 'Android'.

Then you can use it like this:

| android |
android := Android new.
android makeToast: 'Hello World!'.

A more complex example, using some dialogs, is included in the smalltalk_for_android.apk (you can use the QR-Code below to install the apk - but remember that you need to install sl4a before. See my previous blog-post).
To get an idea what is possible, see the the API reference. I think it is a wonderful perspective to write full blown Android apps with Smalltalk.
Coding Smalltalk on a phone or tablet is fun - the sl4a editor is a big help because it contains an api reference. If you want to hack more complex scripts, you can remote control your phone or emulator, just follow this instructions. Only one difference: you need to set the environment-variable AP_HANDSHAKE to some arbitrary value.
With this setup you can execute your script with "gst myscript.st" or just call the api via the gst console.
Sourcecode etc. is available on github.


Kommentare:

Joachim Tuchel hat gesagt…

Hi Stefan,

sounds great. I'd love to get my hands on this and try it out, but the Nexus 7 is not available yet ;-)

I wonder how a setup would look like t use GNU Smalltalk on my PC or mac to develop a GNU Smalltalk application that is to be deployed on an Android tablet or Smartphone...

Thanks for sharing your code!

Stefan Krecher hat gesagt…

Joachim,
you'll need the Android SDK to create a virtual device (i think you need it too if you connect a real device). Then you have two possibilities:
1. run sl4a with the server-mode on the device - use gst on your pc. When you include Android.star, calls are made to the device
or 2. run the Remote.st script on the device (same as the gst-remote commandline tool) and remote-execute your local scripts.
In both cases you can use your favorite Texteditor and execute your script local - it will run remote.
I'm new to GNU Smalltalk so i don't know what is possible with BLOX or Visual GST