Sub Class_Globals
Private Root As B4XView 'ignore
Private xui As XUI 'ignore
Private scanner As BarcodeScanner
Private btnStart, btnStop, btnSave As Button
Private lblResult As Label
Private pnlPreview As B4XView
Private hd As HUD
End Sub
'You can add more parameters here.
Public Sub Initialize As Object
Return Me
End Sub
'This event will be called once, before the page becomes visible.
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("frmBarCode")
End Sub
Private Sub B4XPage_Appear
scanner.Initialize("scanner", pnlPreview)
btnSave.Enabled = False
lblResult.Text = ""
scanner.Start
Sleep(100)
Dim scanrect As Rect
scanrect.Initialize(50, 10, 250, 210)
scanner.ScanRect = scanrect
End Sub
Sub pnlPreview_Resize (Width As Float, Height As Float)
scanner.Resize
End Sub
Sub scanner_Ready (Success As Boolean)
btnStart.Enabled = Success
' btnStop.Enabled = False
If Success = True Then
hd.ToastMessageShow("Ready to start", False)
Else
hd.ToastMessageShow("Error starting scanner", True)
End If
End Sub
Sub scanner_Detected (Codes As List)
Dim sb As StringBuilder
sb.Initialize
sb.Append("Detected code:").Append(CRLF)
For Each code As BarcodeCode In Codes
sb.Append(code.Value).Append(CRLF)
Next
lblResult.Text = sb.ToString
btnSave.Enabled = True
End Sub
Private Sub btnStart_Click
scanner.Start
Sleep(100)
Dim scanrect As Rect
scanrect.Initialize(50, 10, 250, 210)
scanner.ScanRect = scanrect
hd.ToastMessageShow("Start...", False)
End Sub
Private Sub btnStop_Click
scanner.Stop
hd.ToastMessageShow("Stopping...", False)
End Sub
Private Sub btnSave_Click
hd.ToastMessageShow("Saving...", True)
End Sub