Android Question Issue with .GetContentHeight from the WebviewExtras and WebViewExtras2 library

Discussion in 'Android Questions' started by Seneca, Jan 24, 2018.

  1. Seneca

    Seneca Active Member Licensed User

    Hi,

    I have been testing WebViewExtras and WebViewExtras2 to calculate the height of a WV and it occurs to me that the height is calculated correctly only if I execute it in Debug mode and I put a break point in the _pagefinished event (line #36 of the example). In "release" mode it is not calculated correctly.

    How can I solve that?

    Best regards.

    Edit: I had forgotten to attach the file.
     

    Attached Files:

    Last edited: Jan 25, 2018
  2. Erel

    Erel Administrator Staff Member Licensed User

    Try to add Sleep(100).
     
    Seneca likes this.
  3. Seneca

    Seneca Active Member Licensed User

    Hi,

    I still can't test this solution because I'm still working with v.6.5

    I wanted to learn a little more before making a new subscription. I'll try it soon.

    Thanks Erel.
     
  4. Erel

    Erel Administrator Staff Member Licensed User

    You can instead use CallSubUtils or a timer to add a short delay.
     
  5. Seneca

    Seneca Active Member Licensed User

    Hi,

    I've done the test using B4A v.7.8 Trial and it works correctly.

    Thanks Erel.
     
  6. Seneca

    Seneca Active Member Licensed User

    CallSubUtils isn't an external library, right? It was implemented from version v.6.8

    Is this correct?
     
  7. DonManfred

    DonManfred Expert Licensed User

    before 6.8 you can use the Class
     
    Seneca likes this.
  8. Seneca

    Seneca Active Member Licensed User

    Perfect, the class works for me. I'll use it provisionally.

    Thanks
     
  9. Seneca

    Seneca Active Member Licensed User

    Hi,

    I'm doing tests using Sleep (with v7.8 Trial) and now I've found a new issue. The height is only calculated correctly if the WV goes from a lower height to a higher height. But on the contrary it doesn't work.

    Is it a bug?

    Example:

    Code:
    Sub Globals
        
    Dim label1 As Label
        
    Dim wvinfo As WebView
        
    Dim wveInfo As WebViewExtras
        
    Dim infoHTML As String
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    Activity.LoadLayout("webview1")
        wveInfo.Initialize (wvinfo)
        infoHTML = 
    "<html><head><style>body {font-size: 18px;}</style></head><body>Initial text. Initial text. Initial text. Initial text.</body></html>"
        wvinfo.LoadHtml(infoHTML)
    End Sub

    Sub wvinfo_pagefinished (url As String)
        Sleep(
    100)
        label1.Text = 
    "Height: " & wveInfo.GetContentHeight & " - Scale: " & wveInfo.GetScale
        wvinfo.Height = wveInfo.GetContentHeight * wveInfo.GetScale
    End Sub

    Sub Font22_Click
        infoHTML = 
    "<html><head><style>body {font-size: 22px;}</style></head><body>In this Case the height of the WV increases. <b>It Is right.</b> In this Case the height of the WV increases. <b>It Is right.</b></body></html>"
        wvinfo.LoadHtml(infoHTML)
    End Sub


    Sub Font18_Click
        infoHTML = 
    "<html><head><style>body {font-size: 18px;}</style></head><body>In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b> In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b></body></html>"
        wvinfo.LoadHtml(infoHTML)
    End Sub
     

    Attached Files:

  10. Erel

    Erel Administrator Staff Member Licensed User

    I've changed your code to:
    Code:
    Sub Font18_Click
       wvinfo.Height = 
    20dip
       infoHTML = 
    "<html><head><style>body {font-size: 18px;}</style></head><body>In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b> In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b></body></html>"
       wvinfo.LoadHtml(infoHTML)
    End Sub
    Seems to work properly.
     
  11. Seneca

    Seneca Active Member Licensed User

    Hi,

    This solution works, but visually it shows an undesirable effect.

    As an alternative, it has occurred to me to use an auxiliary WV (out of the screen) to do the calculation.

    Code:
    Sub Globals
        
    Dim label1 As Label
        
    Dim wvinfo As WebView
        
    Dim wvAux As WebView       'Is out of screen
        Dim wveInfo As WebViewExtras
        
    Dim infoHTML As String
    End Sub

    Sub Activity_Create(FirstTime As Boolean)
        
    Activity.LoadLayout("webview1")
        wvAux.Width = wvinfo.Width
        wveInfo.Initialize (wvAux)
        infoHTML = 
    "<html><head><style>body {font-size: 18px;}</style></head><body>Initial text. Initial text. Initial text. Initial text.</body></html>"
        wvAux.LoadHtml(infoHTML)
    End Sub

    Sub wvAux_pagefinished (url As String)
        Sleep(
    100)
        label1.Text = 
    "Height: " & wveInfo.GetContentHeight & " - Scale: " & wveInfo.GetScale
        wvinfo.Height = wveInfo.GetContentHeight * wveInfo.GetScale
        wvinfo.LoadHtml(infoHTML)
    End Sub

    Sub Font22_Click
        infoHTML = 
    "<html><head><style>body {font-size: 22px;}</style></head><body>In this Case the height of the WV increases. <b>It Is right.</b> In this Case the height of the WV increases. <b>It Is right.</b></body></html>"
        wvAux.LoadHtml(infoHTML)
    End Sub


    Sub Font18_Click
        infoHTML = 
    "<html><head><style>body {font-size: 18px;}</style></head><body>In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b> In this Case the height of the WV does Not decrease. <b>It Is incorrect.</b></body></html>"
        wvAux.LoadHtml(infoHTML)
    End Sub
     
    Last edited: Jan 28, 2018
Loading...
  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice