Sub Process_Globals
'These global variables will be declared once when the application starts.
'These variables can be accessed from all modules.
Dim sURL As String '= "file:///" & Starter.InitFilesFolder & "/login.html"
Dim LastURL As String = sURL
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 CookieManager1 As CookieManager
Dim wv As WebView, wvs As WebViewSettings
Dim WebViewExtras1 As WebViewExtras
Dim WebChromeClient1 As DefaultWebChromeClient
Dim JavascriptInterface1 As DefaultJavascriptInterface
Dim WebViewClient1 As DefaultWebViewClient
Private IME1 As IME
Private ActivityParent As JavaObject
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
Activity.LoadLayout("1")
WebViewExtras1.Initialize(wv)
WebViewExtras1.JavaScriptEnabled = True
JavascriptInterface1.Initialize
WebViewExtras1.AddJavascriptInterface(JavascriptInterface1, "B4A")
WebChromeClient1.Initialize("WebChromeClient1")
WebViewExtras1.SetWebChromeClient(WebChromeClient1)
WebViewClient1.Initialize("wv")
WebViewExtras1.SetWebViewClient(WebViewClient1)
wvs.setUseWideViewPort(wv, True)
wvs.setDisplayZoomControls(wv, False)
wvs.setLoadsImagesAutomatically(wv, True)
IME1.Initialize("IME1")
IME1.AddHeightChangedEvent
Dim jo As JavaObject = Activity
jo.RunMethodJO("getContext", Null).RunMethodJO("getWindow", Null).RunMethod("setSoftInputMode", _
Array As Object(0x20))
ActivityParent = jo.RunMethodJO("getParent", Null)
After_Change
End Sub
Sub Activity_Resume
'call SetAcceptCookie after WebView has been initialized
CookieManager1.SetAcceptCookies(True)
After_Change
If LastURL <> "" Then
Start
End If
End Sub
Sub After_Change
Dim ajo As Panel = Activity
Dim width As Int = ActivityParent.RunMethod("getMeasuredWidth", Null)
Dim height As Int = ActivityParent.RunMethod("getMeasuredHeight", Null)
If width = 0 Or height = 0 Then Return
ajo.width = width 'update the "activity" width and height
ajo.height = height
wv.width = width
wv.height = height
End Sub
Sub Start
ProgressDialogShow("")
wv.LoadUrl(LastURL)
End Sub
Sub If_Exit As Boolean
Dim a As Int = Msgbox2("Exit now ?", "Warning:", "Exit", "Cancel", "Log out", Null)
If a = DialogResponse.POSITIVE Then
Activity.Finish
Return True
Else if a = DialogResponse.NEGATIVE Then
CookieManager1.RemoveAllCookies
Activity.Finish
Return True
End If
Return False
End Sub
Sub wv_PageFinished(URL As String)
ProgressDialogHide
End Sub
'exacute Javascript like Do_JS("document.getElementById('password').value")
Sub Do_JS (JS As String)
Dim Javascript As String
Javascript="B4A.CallSub('Process_HTML', true, " & JS & ")"
WebViewExtras1.executeJavascript( Javascript)
End Sub
Sub Process_HTML(Html As String)
' This is the Sub that we'll get the web page to send it's HTML content to
' Log may truncate a large page so you'll not see all of the HTML in the log but the 'html' String should still contain all of the web page HTML
CallSubDelayed2(Me, "Show_result", Html)
End Sub
'decide yourself what to do with JS result
Sub Show_result (res As String)
Log(res)
End Sub
Sub wv_ReceivedError(ErrorCode As Int, Description As String, FailingUrl As String)
wv.LoadUrl("file:///" & Starter.InitFilesFolder & "/errors.html")
End Sub
Sub wv_OverrideUrl (URL As String) As Boolean
If URL.ToLowerCase.StartsWith("tel:") Then
Dim in As Intent
in.Initialize(in.ACTION_VIEW, URL) '"tel:" & tel
StartActivity(in)
Return True
else If URL.ToLowerCase.StartsWith("adr:") Then 'special href-tag for address opening on a map: adr:London, Big Ben
Dim s() As String = Regex.Split("adr:", URL)
if s(1) <> "" then
Dim p As PhoneIntents
StartActivity (p.OpenBrowser("http://maps.google.com/maps?daddr=" & s(1))) 'open goole map with the address
end if
Return True
End If
#If debug
Log("override=" & URL)
#End If
End Sub
Sub IME1_HeightChanged (NewHeight As Int, OldHeight As Int)
CallSubDelayed(Me, "After_Change")
Start
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean 'Return True to consume the event
If KeyCode = KeyCodes.KEYCODE_BACK Then
Try
If WebViewExtras1.CanGoback Then
ProgressDialogShow("")
wv.Back
Return True
Else
If If_Exit Then
ExitApplication
Return False
Else
Return True 'not exit
End If
End If
Catch
If_Exit
End Try
End If
End Sub