Many thanks
@teddybear,
Now that I read this I realized that there is no way on Android to do what Steve do on a B4J JavaFX WebView, Android only can do it asynch and require callback to no block current thread.
There isn't a way to evaluate Javascript synchronously on Android (i.e. on the current thread) so your best bet is to use evaluateJavascript then wait for the callback:
public void getDataFromJs(String command, WebView webView) {
webView.evaluateJavascript("(function() { return " + command + "; })();", new ValueCallback<String>() {
@Override
public void onReceiveValue(String s) {
returnDataFromJs(s);
}
});
}
public returnDataFromJs(String data) {
// Do something with the result.
}
There isn't a method to evaluate Javascript on the current thread, as Javascript operations can take a while (the JS engine needs time to spin up) and this can block the current thread.
I appreciate a lots your help, but as I explained I want avoid to assign any value to a global variable, I've used it just for tests, my goal at this point is to use Wait For in a way to wait a value directly on the function that evalutate and return a value to the main.
From your code, suppose I have 50 getters in my CodeMirrorWrapper class, to do this I suppose I need to create 100 global variables, each, one to handle value and one to handle jsRunning (one for each to not conflict with others).
Another problem is that this should be done directly on the class and access to the main this way:
Dim Code As String = CodeEditor1.GetCode ' Get current editor text or void string if nothing
Dim Pos As Int = CodeEditor1.getCursorPosition
Dim Selection As String = CodeEditor1.getSelection
I want avoid to use Wait For in the main to retrieve editor values and properties, suppose you want to get a cursor position or somethong else....
Wait For(CodeEditor1.getCursorPosition) Complete(Pos As Int)
Log("Cursor position: " & Pos)
Wait For(CodeEditor1.getSelection) Complete(Text As String)
Log("Selected text: " & Text)
For me this is not a problem on develop, but because this is a class (a library) I want avoid the user use Wait For for any library getters.
Do you have idea on a way that I can do it directly inside a class?
Another option can be use callbacks to the main, using CallSub, CallSubDelayed, but this is to avoid, suppose to get a value, here require the main have a callback for any getter, 50 getters..... ooooh and a lots of global variables to handle values....
Anyway now I will try your advices, but I think I cannot use it in a final class.
Many thanks