Rhino, Mozilla's JavaScript engine, plays nicely on Android since it can run in interpreted-only-mode. Thus no need for generating Dalvik byte codes. But, to my great disappointment, it is not possible do subclassing in JavaScript on Android, because here byte code generation is required. It is not possible (as I understand it) to "hook into" the method call when Dalvik calls our Java object without having a proper Java class for the object.
Furthermore, it turns out that implementing interfaces cannot be done in Rhino without code generation. Interfaces that contain only one method, work fine, however. You just specify a JavaScript function object in place of the interface implementation. But with interfaces that have more than one method, you are toast (hehe, nice Android joke there). I have not yet got a good grasp of the inner workings of Rhino, but I am sure that this can be implemented using Java's Proxy classes, either in Rhino, or in the DroidScript app, or even in JavaScript.
I did some experimentation that kept me awake (it is now two a clock in the night here in Stockholm), and here is the result, in JavaScript. A particular tricky case was to make a proxy for an "inner" interface in JavaScript (whatever that is called in Java lingo). Of course, this could be done in Java and called from JavaScript, but it is more fun to use JavaScript all the way ;-)
var Lang = Packages.java.lang;
var proxy = Lang.reflect.Proxy.getProxyClass(
Lang.ClassLoader.getSystemClassLoader(),
Packages.android.view.View.OnClickListener);
var proxy = Lang.reflect.Proxy.getProxyClass(
Lang.ClassLoader.getSystemClassLoader(),
Packages.android.view.View.OnClickListener);
And here we have our proxy class! Will continue to research this tomorrow and during the week.
Sleep well :-)
JavaScript is a good program and very easy to use. I don´t like a complex program. I prefer javascript because i consider it like a device very eficient and it have a good quality.
ReplyDeleteI always looking for the quality that is why i prefer to buy viagra because i always have a great result in my sexual life.