'Activity module
Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
End Sub
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Dim WebView1 As WebView
Dim WebViewExtras1 As WebViewExtras
End Sub
Sub Activity_Create(FirstTime As Boolean)
WebView1.Initialize("WebView1")
WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
WebViewExtras1.addWebChromeClient(WebView1)
Activity.AddView(WebView1, 0, 0, 100%x, 100%y)
WebView1.LoadUrl("http://code.martinpearman.co.uk/deleteme/image_anchors.htm")
End Sub
Sub Activity_Resume
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub ProcessLinks(Json As String)
' Json represents an array of javascript objects
Log(Json)
Dim JavascriptArray As List
Dim JavascriptObject As Map
Dim i As Int
Dim Parser As JSONParser
Parser.Initialize(Json)
JavascriptArray=Parser.NextArray
For i=0 To JavascriptArray.Size-1
JavascriptObject=JavascriptArray.Get(i)
Log(JavascriptObject.Get("imageSource")&" | "&JavascriptObject.Get("href"))
Next
End Sub
Sub WebView1_PageFinished (Url As String)
Dim Javascript As String
Javascript="var anchor,img,parent,imgs=document.getElementsByTagName('img'),i=imgs.length,string=[];while(i--){img=imgs[i];parent=img.parentNode;if(parent.tagName.toLowerCase()==='a'){string.push({imageSource:img.src,href:parent.href})}}B4A.CallSub('ProcessLinks',true,JSON.stringify(string));"
WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub