Sub Class_Globals
Private fx As JFX
Private imgw As B4XImageView
Private xui As XUI
Public label As String '<
Public Refresh As Timer
Public w As Double = 3.93'larghezza etichetta
Public h As Double = 2.65 'lunghezza etichetta
End Sub
'Initializes the object. You can add parameters to this method if needed.
Public Sub Initialize (target As Object)
imgw = target
Start
End Sub
Sub Start
imgw.Clear
imgw.ResizeMode = "FIT"
imgw.CornersRadius = 4
Refresh.Initialize("Refresh", 2500)
Refresh.Enabled = True
End Sub
Sub LoadView
Refresh.Enabled = False
Dim j As HttpJob
j.Initialize("", Me)
'Dim labelstr As String = File.ReadString(File.DirApp, "Prod_coop.prn")
'j.PostString("http://api.labelary.com/v1/printers/8dpmm/labels/3.937x2.755/0/",labelstr)
j.PostString($"http://api.labelary.com/v1/printers/8dpmm/labels/${w}x${h}/0/"$,label)
j.GetRequest.SetHeader("Accept", "image/png")
Wait For(j) JobDone(j As HttpJob)
Dim b As Boolean = j.Success
If b Then
Dim out As OutputStream = File.OpenOutput(File.DirApp, "label.png", False)
File.Copy2(j.GetInputStream, out)
out.Close
imgw.Load(File.DirApp, "label.png")
End If
j.Release
Refresh.Enabled = True
End Sub
Sub Refresh_Tick
If label.Length > 0 Then CallSub(Me,"LoadView")
End Sub