Posted by: pierrot | on December 8, 2016
Posted in | 7 Comments » Tags:
< ![CDATA[
Pierre Hébert
I think the challenge is that you have to extend the abstract Android class contentobserver before you can start instantiating your new, own class.
How is extending done in LL java script? Is that possible at all?
]]>
Yes, using JavaAdapter (https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java) and the genius work of Lukas Morawietz who made it possible to use it in Lightning. There are probably some sample uses of JavaAdapter in the script repository somewhere but I don’t know which.
Sample:
bindClass(“android.util.AsyncTask”);
var task = new JavaAdapter(AsyncTask,{
doInBackground:function(args){
//do something
}
});
task.execute();
I had to change util to os to make the example work.
I tried the same with contentobserver but got and exception, unfortunately.
I tried:
observer=new JavaAdapter(ContentObserver,{
onChange:function(selfChange)
{
//alert(“observed”)
And got:
xxxJavaException: java.lang.NoSuchMethodException: [interface org.mozilla.javascript.Scriptable, class org.mozilla.javascript.ContextFactory]
Broadcastreciever did work though (to listen for volume change events e.g.)
Karsten Franke
I typed that from memory. Of course the correct package name is os.
Karsten Franke you can specify the constructor parameters this way:
var adapter = new JavaAdapter(ArrayAdapter, {
getView: function(position, convertView, parent) {
blabla
}, context, layout, items);
This will create an instance of a subclass of JavaAdapter with the context, layout and items constructor arguments.
Lukas Morawietz no problem at all.
Pierre Hébert And we have a winner. Works like a charm. Big thanks.
Your email address will not be published. Required fields are marked *
Comment
Name *
Email *
Website
< ![CDATA[
Pierre Hébert
I think the challenge is that you have to extend the abstract Android class contentobserver before you can start instantiating your new, own class.
How is extending done in LL java script? Is that possible at all?
]]>
< ![CDATA[
Yes, using JavaAdapter (https://developer.mozilla.org/en-US/docs/Mozilla/Projects/Rhino/Scripting_Java) and the genius work of Lukas Morawietz who made it possible to use it in Lightning. There are probably some sample uses of JavaAdapter in the script repository somewhere but I don’t know which.
]]>
< ![CDATA[
Sample:
bindClass(“android.util.AsyncTask”);
var task = new JavaAdapter(AsyncTask,{
doInBackground:function(args){
//do something
}
});
task.execute();
]]>
< ![CDATA[
I had to change util to os to make the example work.
I tried the same with contentobserver but got and exception, unfortunately.
I tried:
observer=new JavaAdapter(ContentObserver,{
onChange:function(selfChange)
{
//alert(“observed”)
}
});
And got:
xxxJavaException: java.lang.NoSuchMethodException: [interface org.mozilla.javascript.Scriptable, class org.mozilla.javascript.ContextFactory]
Broadcastreciever did work though (to listen for volume change events e.g.)
]]>
< ![CDATA[
Karsten Franke
I typed that from memory. Of course the correct package name is os.
]]>
< ![CDATA[
Karsten Franke you can specify the constructor parameters this way:
var adapter = new JavaAdapter(ArrayAdapter, {
getView: function(position, convertView, parent) {
blabla
}
}, context, layout, items);
This will create an instance of a subclass of JavaAdapter with the context, layout and items constructor arguments.
]]>
< ![CDATA[
Lukas Morawietz no problem at all.
Pierre Hébert And we have a winner. Works like a charm. Big thanks.
]]>