Android Question messure the needed higth in a WebView?

mw71

Active Member
Licensed User
Longtime User
Hi,

how i messure the needed higth in a WebView?

B4X:
Dim ret As Int   
Dim cd As CustomDialog
Dim WebMsg As WebView
Dim Wvx As WebViewExtras

WebMsg.LoadHtml(sbn.ToString)
Wait For WebMsg_PageFinished(Url As String)

WebMsg.Initialize("WebMsg")
Wvx.GetContentHeight(WebMsg)

cd.AddView(WebMsg,5dip,5dip,85%x,80%y)
ret=cd.Show(titel,pos,can,neg,Null)

reports 819 on my Tablet. near 200 dip is a good value.
 

mw71

Active Member
Licensed User
Longtime User
I recommend you to avoid using the modal dialogs. Use CustomLayoutDialog instead: Dialogs library 2017 - Custom dialogs and async methods
https://www.b4x.com/android/forum/threads/80204/#content
I know (it's a other "big" Step to Change all the Dialogs in the App that i must go), but the problem with determining the height of the WebView remains, or is there an other way.

https://www.b4x.com/android/forum/threads/80204/#content
Why do you initialize WebMsg again?

this was a mistake by copy, Full Code (without using WebViewExtras)
B4X:
Sub msgbox_html(msg As List,titel As String,pos As String,can As String,neg As String) As Int

Dim ret As Int   
Dim cd As CustomDialog
Dim WebMsg As WebView
'Dim Wvx As WebViewExtras
WebMsg.Initialize("WebMsg")
    

If msg.Size>0 Then
    Dim varGenTable As Boolean
    Dim sbn As StringBuilder
    sbn.Initialize
    sbn.Append($"<!DOCTYPE html Public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">"$)
    sbn.Append($"<html>"$)
    sbn.Append($"<head>"$)
    sbn.Append($"<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">"$)
    sbn.Append($"<title>UDXLog News</title>"$)
    sbn.Append($"</head>"$)

    For i= 0 To msg.Size-1
        Dim str() As String = msg.Get(i)
        If str(0)=Null Or str(0).ToLowerCase="null" Then str(0)=""
        If str(1)=Null Or str(1).ToLowerCase="null" Then str(1)=""
        If str(0)<>"-" And varGenTable=True Then
            sbn.Append("</ul>")
            varGenTable=False
        End If

        If str(0)=Null Then
            sbn.Append("<br>").Append(str(1)).Append(Chr(10))
        Else
            Select Case str(0)
                Case "-"
                    If varGenTable=False Then sbn.Append("<ul>").Append(Chr(10))
                    sbn.Append("  <li>").Append(str(1)).Append("</li>")
                    varGenTable=True
                Case Else
                    sbn.Append("<br>").Append(str(1)).Append(Chr(10))
            End Select
        End If
    Next
    If varGenTable=True Then
        sbn.Append("</ul>")
        varGenTable=False
    End If
    sbn.Append("</body>")
    sbn.Append("</html>")

    WebMsg.LoadHtml(sbn.ToString)
'    Wait For WebMsg_PageFinished(Url As String)
'   
'    Log("----------------------")
'    Log(Wvx.GetContentHeight(WebMsg))
'    Log("----------------------")

    cd.AddView(WebMsg,5dip,5dip,85%x,300dip)'80%y)
    ret=cd.Show(titel,pos,can,neg,Null)
    

Return ret
End If
    
End Sub
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
B4X:
WebMsg.LoadHtml(sbn.ToString)
Wait For WebMsg_PageFinished(Url As String)
Sleep(5000) 'Long Time for Test

unfortunately no change, reports also 819 on my Tablet
 
Upvote 0

mw71

Active Member
Licensed User
Longtime User
Hi,

Test is append. Log reports 743 in all orientations.
 

Attachments

  • TestWebH.zip
    8.5 KB · Views: 199
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
1.
B4X:
Dim sbn As StringBuilder
sbn.Initialize
sbn.Append($"<!DOCTYPE html Public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">"$)
sbn.Append($"<html>"$)
sbn.Append($"<head>"$)
sbn.Append($"<meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">"$)
sbn.Append($"<title>UDXLog News</title>"$)
sbn.Append($"</head>"$)
Better:
B4X:
sbn.Append($"
<!DOCTYPE html Public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
   <html>
       <head>
           <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
       <title>UDXLog News</title>
   </head>
"$)

2. Don't use CustomDialog. Use CustomLayoutDialog.

This code seems to work properly:
B4X:
Sub msgbox_html(msg As List,titel As String,pos As String,can As String,neg As String)

   
   If msg.Size>0 Then
       Dim WebMsg As WebView
       Dim Wvx As WebViewExtras
       WebMsg.Initialize("WebMsg")
       Dim varGenTable As Boolean
       Dim sbn As StringBuilder
       sbn.Initialize
       sbn.Append($"
<!DOCTYPE html Public "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
   <html>
       <head>
           <meta content="text/html; charset=ISO-8859-1" http-equiv="content-type">
       <title>UDXLog News</title>
   </head>
"$)

       For i= 0 To msg.Size-1
           Dim str() As String = msg.Get(i)
           If str(0)=Null Or str(0).ToLowerCase="null" Then str(0)=""
           If str(1)=Null Or str(1).ToLowerCase="null" Then str(1)=""
           If str(0)<>"-" And varGenTable=True Then
               sbn.Append("</ul>")
               varGenTable=False
           End If

           If str(0)=Null Then
               sbn.Append("<br>").Append(str(1)).Append(Chr(10))
           Else
               Select Case str(0)
                   Case "-"
                       If varGenTable=False Then sbn.Append("<ul>").Append(Chr(10))
                       sbn.Append("  <li>").Append(str(1)).Append("</li>")
                       varGenTable=True
                   Case Else
                       sbn.Append("<br>").Append(str(1)).Append(Chr(10))
               End Select
           End If
       Next
       If varGenTable=True Then
           sbn.Append("</ul>")
           varGenTable=False
       End If
       sbn.Append("</body>")
       sbn.Append("</html>")

       WebMsg.LoadHtml(sbn.ToString)
       Wait For WebMsg_PageFinished(Url As String)
       Sleep(100)
   
       Log("----------------------")
       Dim height As Int = Wvx.GetContentHeight(WebMsg) * Wvx.GetScale(WebMsg)
       Log(height)
       Log("----------------------")

           
       Dim cd As CustomLayoutDialog
       Dim sf As Object = cd.ShowAsync("Title", "Yes", "Cancel", "No", Null, False)
       cd.SetSize(85%x, height + 200dip)
       Wait For (sf) Dialog_Ready (DialogPanel As Panel)
       DialogPanel.AddView(WebMsg, 0, 0, DialogPanel.Width, DialogPanel.Height)
       WebMsg.ZoomEnabled = False
       Wait For (sf) Dialog_Result (Result As Int)
       If Result = DialogResponse.POSITIVE Then
           Log("Yes!")
       End If
   End If
End Sub
 
Upvote 0
Top