Android Question why is not executed DrawLine

funker

Member
Licensed User
Hello good day.

why is DrawLine not performed if I jump with the timer1 to zeichne ?
cvsGraph.DrawLine(300,300, 300+x,300+y, Colors.Red, 1)

the values x and y are correctly calculated.

thanks.
greeting


B4X:
#Region Module Attributes
    #FullScreen: False
    #IncludeTitle: True
    #ApplicationLabel: esp8266
    #VersionCode: 1
    #VersionName: 
    #SupportedOrientations: unspecified
    #CanInstallToExternalStorage: False
#End Region

#Region  Activity Attributes 
    #FullScreen: False
    #IncludeTitle: True
#End Region

Sub Process_Globals
    Dim Timer1 As Timer
End Sub

Sub Globals   
      Private hlinks As Button
      Private links As Button
    Private hrechts As Button
    Private mitte As Button
    Private rechts As Button
    Private vor As Button
    Private zurueck As Button
    Private v0 As Button
    Private v1 As Button
    Private v2 As Button
    Private ser0 As Button
    Private ser1 As Button
    Private sharp As Button
    Private edit1 As EditText
   
    Dim WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
   
    Dim zs As String 
    Dim vz As Int
    Dim vzz As Float
    Dim hz As Int
    Dim hzz As Float
    Dim pi As Float
    Dim x As Int
    Dim y As Int
   
    Private image1 As Panel
    Private cvsGraph As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)   
    Timer1.Initialize("Timer1", 400)
      Activity.LoadLayout("esp8266")
    edit1.text =""
    WebView1.Initialize("WebView1")
    WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
   
    cvsGraph.Initialize(image1)
End Sub

Sub Activity_Resume
    Timer1.Enabled = True
    pi=3.14159
    hzz=180
End Sub

Sub Activity_Pause (UserClosed As Boolean)
    Timer1.Enabled = False
End Sub

Sub Exit_App
    Activity.Finish
    ExitApplication
End Sub

Sub WebView1_PageFinished (Url As String)
    Dim Javascript As String
    Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.innerText)"
    ' Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.outerText)"
    ' Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.innerHTML)"
    ' Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.outerHTML)"
    ' Log("PageFinished: " & Javascript) 
    WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub

Sub ProcessHTML(Html As String)
    ' Log(Html)
    zs = Html
End Sub

Sub Timer1_Tick
  WebView1.LoadUrl("http://192.168.2.106/leer")
  edit1.Text=zs
  zeichne
End Sub

Sub rechts_Click
    WebView1.LoadUrl("http://192.168.2.106/rechts")
End Sub

Sub hrechts_Click
    WebView1.LoadUrl("http://192.168.2.106/hrechts")
End Sub

Sub mitte_Click
    WebView1.LoadUrl("http://192.168.2.106/mitte")
End Sub

Sub hlinks_Click
    WebView1.LoadUrl("http://192.168.2.106/hlinks")
End Sub

Sub links_Click
    WebView1.LoadUrl("http://192.168.2.106/links")
End Sub

Sub v0_Click
    WebView1.LoadUrl("http://192.168.2.106/v0")
End Sub

Sub v1_Click
    WebView1.LoadUrl("http://192.168.2.106/v1")
End Sub

Sub v2_Click
    WebView1.LoadUrl("http://192.168.2.106/v2")
End Sub

Sub zurueck_Click
    WebView1.LoadUrl("http://192.168.2.106/zur")
End Sub

Sub vor_Click
    WebView1.LoadUrl("http://192.168.2.106/vor")
End Sub

Sub ser0_Click
    WebView1.LoadUrl("http://192.168.2.106/ser0")
End Sub

Sub ser1_Click
    WebView1.LoadUrl("http://192.168.2.106/ser1")
    vz=1
End Sub

Sub sharp_Click
    WebView1.LoadUrl("http://192.168.2.106/sharp")
    hz=1
End Sub

Sub zeichne()   
    If vz=1 Then
        If vzz < 80 Then
            vzz=vzz+1.8
            x=Sin(vzz*pi/180)*100
            y=Cos(vzz*pi/180)*100
            cvsGraph.DrawLine(300,300, 300+x,300+y, Colors.Red, 1)
        Else
            vz=0
            vzz=0   
        End If   
    End If
   
    If hz=1 Then
        If hzz < 360 Then
            hzz=hzz+1.8
            x=Sin(vzz*pi/180)*100
            y=Cos(vzz*pi/180)*100
            cvsGraph.DrawLine(300,300, 300+x,300+y, Colors.Red, 1)
        Else
            hz=0
            hzz=180   
        End If   
    End If
End Sub

Sub Delay(nMilliSecond As Long)
    Dim nBeginTime As Long
    Dim nEndTime As Long
    nEndTime = DateTime.Now + nMilliSecond
    nBeginTime = DateTime.Now
   
    Do While nBeginTime < nEndTime
        nBeginTime = DateTime.Now
        Log(nBeginTime)
        If nEndTime < nBeginTime Then
            Return
        End If
          DoEvents
    Loop
End Sub
 

Cableguy

Expert
Licensed User
Longtime User
Why the parenthesis in the sub zeichne ()?
Have you tried to log the value of vz and vzz and hz to be sure it's correctly set?
 
Upvote 0

klaus

Expert
Licensed User
Longtime User
You may need either:
image1.Invalidate
image1.Invalidate2
image1.Invalidate3

To force the redraw.

You should avoid a routine like this: Sub Delay(nMilliSecond As Long)
It is blocking the main thread for noting.
You should use a Timer !
 
Last edited:
Upvote 0

funker

Member
Licensed User
Hello thanks.

why missing here now some lines?

greeting

B4X:
Sub Process_Globals
    Dim Timer1 As Timer
End Sub

Sub Globals   
      Private hlinks As Button
      Private links As Button
    Private hrechts As Button
    Private mitte As Button
    Private rechts As Button
    Private vor As Button
    Private zurueck As Button
    Private v0 As Button
    Private v1 As Button
    Private v2 As Button
    Private ser0 As Button
    Private ser1 As Button
    Private sharp As Button
    Private edit1 As EditText
   
    Dim WebView1 As WebView
    Dim WebViewExtras1 As WebViewExtras
   
    Dim zs As String 
    Dim vz As Float
    Dim vzz As Float
    Dim hz As Float
    Dim hzz As Float
    Dim pi As Float
    Dim x As Float
    Dim y As Float
   
    Private image1 As Panel
    Private cvsGraph As Canvas
End Sub

Sub Activity_Create(FirstTime As Boolean)   
    Timer1.Initialize("Timer1", 400)
      Activity.LoadLayout("esp8266")
    edit1.text =""
    WebView1.Initialize("WebView1")
    WebViewExtras1.addJavascriptInterface(WebView1, "B4A")
   
    cvsGraph.Initialize(image1)   
End Sub

Sub Activity_Resume
    Timer1.Enabled = True
    pi=3.14159
    hzz=180
End Sub

Sub Activity_Pause (UserClosed As Boolean)
   
End Sub

Sub Exit_App
    Activity.Finish
    ExitApplication
End Sub

Sub WebView1_PageFinished (Url As String)
    Dim Javascript As String
    Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.innerText)"
    ' Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.outerText)"
    ' Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.innerHTML)"
    ' Javascript = "B4A.CallSub('ProcessHTML', false, document.documentElement.outerHTML)"
    ' Log("PageFinished: " & Javascript) 
    WebViewExtras1.executeJavascript(WebView1, Javascript)
End Sub

Sub ProcessHTML(Html As String)
    ' Log(Html)
    zs = Html
End Sub

Sub Timer1_Tick
  WebView1.LoadUrl("http://192.168.2.106/leer")
  edit1.Text=zs
  zeichne
End Sub

Sub rechts_Click
    WebView1.LoadUrl("http://192.168.2.106/rechts")
End Sub

Sub hrechts_Click
    WebView1.LoadUrl("http://192.168.2.106/hrechts")
End Sub

Sub mitte_Click
    WebView1.LoadUrl("http://192.168.2.106/mitte")
End Sub

Sub hlinks_Click
    WebView1.LoadUrl("http://192.168.2.106/hlinks")
End Sub

Sub links_Click
    WebView1.LoadUrl("http://192.168.2.106/links")
End Sub

Sub v0_Click
    WebView1.LoadUrl("http://192.168.2.106/v0")
End Sub

Sub v1_Click
    WebView1.LoadUrl("http://192.168.2.106/v1")
End Sub

Sub v2_Click
    WebView1.LoadUrl("http://192.168.2.106/v2")
End Sub

Sub zurueck_Click
    WebView1.LoadUrl("http://192.168.2.106/zur")
End Sub

Sub vor_Click
    WebView1.LoadUrl("http://192.168.2.106/vor")
End Sub

Sub ser0_Click
    WebView1.LoadUrl("http://192.168.2.106/ser0")
End Sub

Sub ser1_Click
    WebView1.LoadUrl("http://192.168.2.106/ser1")
    vz=1
End Sub

Sub sharp_Click
    WebView1.LoadUrl("http://192.168.2.106/sharp")
    hz=1
End Sub

Sub zeichne
    If vz=1 Then
        If vzz < 180.0 Then
            vzz=vzz+1.8
            x=Sin(vzz*pi/180)*100.0
            y=Cos(vzz*pi/180)*100.0
            image1.Invalidate
            cvsGraph.DrawLine(300,300, 300+x,300+y, Colors.Red, 1)
        Else
            vz=0.0
            vzz=0.0   
        End If   
    End If
   
    If hz=1 Then
        If hzz < 360.0 Then
            hzz=hzz+1.8
            x=Sin(hzz*pi/180)*100.0
            y=Cos(hzz*pi/180)*100.0
            image1.Invalidate
            cvsGraph.DrawLine(300,300, 300+x,300+y, Colors.Green, 1)
        Else
            hz=0.0
            hzz=180.0   
        End If   
    End If
End Sub
 

Attachments

  • DSCN3865.JPG
    DSCN3865.JPG
    92.2 KB · Views: 334
Upvote 0

klaus

Expert
Licensed User
Longtime User
... why missing here now some lines?
Sorry, but I don't understand !?
You should explain in detail what exactly you want to do.
Explain in detail what the problem is.

Instead of posting the code you should post a project as a zip file so we could test it and see what happens.
This would be much more efficient.
 
Upvote 0
Top