#Region Shared Files
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
#End Region
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=%PROJECT_NAME%.zip
Sub Class_Globals
' Root container of the page
Private Root As B4XView
Private xui As XUI
'---------------------- WebView resize helper ----------------------
' Auxiliary WebView used only to calculate the correct height
Private redimencionarWebView As WebView
#If b4a
' Used to execute JavaScript on Android WebView
Dim wve As WebViewExtras
Dim jsi As DefaultJavascriptInterface
#End If
'-------------------------------------------------------------------
' List of HTML texts to display
Private Texts As List
' Main WebViews displayed on screen
Private WebView1 As WebView
Private WebView2 As WebView
End Sub
Public Sub Initialize
End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
' Load layout
Root.LoadLayout("MainPage")
#if b4i
' Wait for resize event on iOS before continuing
Wait For B4XPage_Resize (Width As Int, Height As Int)
#End If
'---------------------- WebView resize setup ----------------------
' Initialize hidden WebView used for measuring content height
redimencionarWebView.Initialize("redimencionarWebView")
Root.AddView(redimencionarWebView, 0, Root.Height, Root.Width, 10dip)
redimencionarWebView.Visible = True
#If b4a
' Initialize JavaScript interface for Android
wve.Initialize(redimencionarWebView)
jsi.Initialize
wve.AddJavascriptInterface(jsi, "B4A")
#End If
'-------------------------------------------------------------------
' Initialize list of sample texts
Texts.Initialize
' Add multiple HTML samples (student behavior reports)
Texts.Add("<p>Hello</p><p>Lucas participated well in today's activity and interacted with his classmates.</p>")
Texts.Add("<p>Hello</p><p>Maria had difficulty concentrating today, getting up several times during class.</p>")
Texts.Add("<p>Hello</p><p>Pedro showed calm behavior, completed the proposed activities, and helped his classmates.</p>")
Texts.Add("<p>Hello</p><p>Julia was very agitated today, ran around the classroom, pushed classmates, and had difficulty following instructions. She required several interventions from the teacher.</p>")
Texts.Add("<p>Hello</p><p>Gabriel had a productive day. He participated in activities, responded well to instructions, and showed interest.</p>")
Texts.Add("<p>Hello</p><p>Ana showed challenging behavior today. She refused to participate in activities, shouted at times, and needed to be removed from the classroom to calm down. After some time, she returned calmer.</p>")
Texts.Add("<p>Hello</p><p>Rafael showed significant progress today. He was able to stay focused longer and interacted positively with classmates during group activities.</p>")
Texts.Add("<p>Hello</p><p>Beatriz was restless for most of the period. She ran around the classroom, tried to climb on furniture, and had difficulty respecting limits. She was redirected several times.</p>")
Texts.Add("<p>Hello</p><p>Matheus had excellent behavior today. He participated in all activities, respected his classmates, and followed instructions independently.</p>")
Texts.Add("<p>Hello</p><p>Carla showed mixed behavior today. At times she participated well, but at others she became agitated, pushed classmates, and had difficulty controlling her emotions. We reinforced the importance of discussing this at home.</p>")
Texts.Add("<p>Hello</p><p>Bruno was attentive during most of the class and completed his tasks with minimal assistance.</p>")
Texts.Add("<p>Hello</p><p>Fernanda showed improvement in following instructions and staying seated during activities.</p>")
Texts.Add("<p>Hello</p><p>Diego had some difficulty sharing materials with classmates but responded well after guidance.</p>")
Texts.Add("<p>Hello</p><p>Larissa participated in group activities and demonstrated good teamwork skills.</p>")
Texts.Add("<p>Hello</p><p>Eduardo was distracted at times but managed to complete his activities with encouragement.</p>")
Texts.Add("<p>Hello</p><p>Camila was calm and cooperative, following classroom rules appropriately.</p>")
Texts.Add("<p>Hello</p><p>Matheus had excellent behavior today. He participated in all activities with great enthusiasm, respected his classmates, and followed instructions independently. He also demonstrated responsibility by organizing his materials and helping maintain a positive classroom environment. His interaction with peers was respectful and cooperative throughout the day.</p>")
Texts.Add("<p>Hello</p><p>Julia showed a positive attitude during today's activities. Although she needed a few reminders to stay focused, she was able to complete her tasks successfully. She interacted well with her classmates and showed kindness during group work. We encourage her to continue improving her concentration and maintaining this positive behavior.</p>")
Texts.Add("<p>Hello</p><p>Gabriel had a productive day overall. He actively participated in class discussions and showed interest in the proposed activities. At times, he became slightly distracted, but responded well to guidance. He demonstrated good problem-solving skills and worked well both independently and in groups.</p>")
Texts.Add("<p>Hello</p><p>Maria had some challenges today with maintaining focus during longer activities. She needed frequent redirection and support from the teacher. However, she showed improvement as the day progressed and was able to complete part of her work. It is important to continue reinforcing routines and encouraging her engagement.</p>")
Texts.Add("<p>Hello</p><p>Lucas demonstrated great progress today. He remained focused for longer periods, followed instructions carefully, and completed all assigned activities. He also interacted positively with classmates and showed respect for classroom rules. We are very pleased with his development.</p>")
Texts.Add("<p>Hello</p><p>Beatriz showed moments of restlessness during the class. She had difficulty staying seated and following some instructions, requiring several reminders. Despite this, she was able to participate in certain activities and showed willingness to improve. Continued support and reinforcement at home would be beneficial.</p>")
Texts.Add("<p>Hello</p><p>Rafael had an excellent day. He demonstrated autonomy in completing his tasks, helped classmates when needed, and followed all instructions without difficulty. His behavior was exemplary, and he contributed positively to the classroom environment.</p>")
Texts.Add("<p>Hello</p><p>Ana presented mixed behavior today. During some periods, she was focused and participated actively. However, at other times she became distracted and had difficulty managing her emotions. With support, she was able to regain control and continue her activities. We recommend reinforcing emotional regulation strategies.</p>")
' Trigger initial load
Panel1_Click
End Sub
Sub B4XPage_Appear
End Sub
Private Sub Panel1_Click
Dim html As String = ""
' Select random text
html = Texts.Get(Rnd(0, Texts.Size))
#if b4i
' Add viewport meta for proper scaling on iOS
html = "<head><meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/></head>" & html
#End If
' Load and resize first WebView
loadHtmlAndResize(WebView1, html)
Wait For loadHtmlAndResizeComplete(Height1 As Int)
'-------------------------
' Position second WebView below the first
WebView2.Top = ((WebView1.Top + WebView1.Height) + 20dip)
' Select another random text
html = Texts.Get(Rnd(0, Texts.Size))
#if b4i
html = "<head><meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/></head>" & html
#End If
' Load and resize second WebView
loadHtmlAndResize(WebView2, html)
Wait For loadHtmlAndResizeComplete(Height1 As Int)
End Sub
'---------------------- WebView resize logic ----------------------
Sub loadHtmlAndResize(xWebView1 As WebView, xHtml1 As String)
Dim finalHeight As Int = 0
' Match helper WebView width to target WebView
redimencionarWebView.Width = xWebView1.Width
' Clear previous content
redimencionarWebView.LoadHtml("")
xWebView1.LoadHtml("")
' Reset heights
redimencionarWebView.Height = 0
xWebView1.Height = 0
' Load HTML into both WebViews
redimencionarWebView.LoadHtml(xHtml1)
xWebView1.LoadHtml(xHtml1)
#if b4a
' Wait for page load
Wait For redimencionarWebView_PageFinished(Url As String)
Sleep(150)
' Execute JavaScript to get content width and height
wve.ExecuteJavascript("B4A.CallSub('SetWVHeight', true, " & _
"document.documentElement.scrollWidth + ',' + document.documentElement.scrollHeight);")
' Receive result from JavaScript
Wait For SetWVHeight(Result As String)
Log("result: " & Result)
Dim parts() As String = Regex.Split(",", Result)
Dim cssWidth As Float = parts(0)
Dim cssHeight As Float = parts(1)
' Calculate scale factor
Dim b4xWidth As Float = redimencionarWebView.Width
Dim scale As Float = cssWidth / b4xWidth
' Debug logs
Log("cssWidth: " & cssWidth)
Log("cssHeight: " & cssHeight)
Log("b4xWidth (DIPs): " & b4xWidth)
Log("scale: " & scale)
Log("finalHeight (DIPs): " & (cssHeight / scale))
' Apply calculated height
finalHeight = cssHeight / scale
redimencionarWebView.Height = finalHeight
xWebView1.Height = finalHeight
#Else b4i
' Wait for page load on iOS
Wait For redimencionarWebView_PageFinished (Success As Boolean, Url As String)
' Execute JavaScript to get content height
wait for (redimencionarWebView.EvaluateJavaScript("document.documentElement.scrollHeight")) redimencionarWebView_JSComplete (Success As Boolean, Result As String)
If Success Then
finalHeight = DipToCurrent(Result)
redimencionarWebView.Height = finalHeight
xWebView1.Height = finalHeight
End If
#End If
' Notify completion with calculated height
CallSubDelayed2(Me,"loadHtmlAndResizeComplete", finalHeight)
End Sub
'-------------------------------------------------------------------