mirror of
https://github.com/KeymonSoft/Guna_Cuenta_Kilometros.git
synced 2026-04-17 19:36:36 +00:00
278 lines
7.4 KiB
QBasic
278 lines
7.4 KiB
QBasic
B4A=true
|
|
Group=Default Group
|
|
ModulesStructureVersion=1
|
|
Type=Class
|
|
Version=12.2
|
|
@EndOfDesignText@
|
|
Sub Class_Globals
|
|
Private Root As B4XView 'ignore
|
|
Private xui As XUI 'ignore
|
|
Dim reqManager As DBRequestManager
|
|
Dim b_mapa As Button
|
|
Dim l_ruta As Label
|
|
Private inv As Button
|
|
Private p_principal As Panel
|
|
Dim ime As IME
|
|
Private et_placas As EditText
|
|
Private et_operador As EditText
|
|
Private et_rutaReparto As EditText
|
|
Private b_guardar As Button
|
|
Private ImageView1 As ImageView
|
|
Private ImageView1 As ImageView
|
|
Private p_datos As Panel
|
|
Private p_camara As Panel
|
|
Private b_cerrar As Button
|
|
Private pnlPreview As Panel
|
|
Private camEx As CameraExClass
|
|
|
|
Private toast As BCToast
|
|
Private Capturing As Boolean
|
|
Private rp As RuntimePermissions
|
|
Private detector As JavaObject
|
|
Private camEx As CameraExClass
|
|
Private LastPreview As Long
|
|
Private IntervalBetweenPreviewsMs As Int = 100
|
|
Dim codigoencontrado, codigoBuscado As String
|
|
Private b_escanRuta As Button
|
|
Private b_escanOperador As Button
|
|
Private b_escanPlacas As Button
|
|
Private et_kmsInicial As EditText
|
|
Private et_kmsFinal As EditText
|
|
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
|
|
'load the layout to Root
|
|
Root.LoadLayout("principal")
|
|
reqManager.Initialize(Me, Starter.server)
|
|
B4XPages.MainPage.usuario=Subs.dameUsuarioDeDB
|
|
'Inicia camara
|
|
p_camara.Width = Root.Width
|
|
p_camara.Height= Root.Height
|
|
p_camara.Visible = False
|
|
toast.Initialize(Root)
|
|
StopCamera
|
|
B4XPages.SetTitle(Me, "Barcode Example")
|
|
CreateDetector (Array("AZTEC", "CODE_128", "CODE_39", "CODE_93", "CODABAR", "DATA_MATRIX", "EAN_13", "EAN_8", "ITF", "PDF417", "QR_CODE", "UPC_A", "UPC_E"))
|
|
'Termina camara
|
|
End Sub
|
|
|
|
Sub B4XPage_Appear
|
|
Subs.centraPanel(p_principal, Root.Width)
|
|
|
|
End Sub
|
|
|
|
Sub JobDone(Job As HttpJob)
|
|
' Private r As DBResult = reqManager.HandleJob(Job)
|
|
If Job.Success = False Then
|
|
LogColor("** " & Job.Tag & " Error: " & Job.ErrorMessage, Colors.Red) ' Mod by CHV - 211023
|
|
'ToastMessageShow("Error: " & Job.ErrorMessage, True)
|
|
Else
|
|
LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211023
|
|
If Job.JobName = "DBRequest" Then
|
|
Dim result As DBResult = reqManager.HandleJob(Job)
|
|
If result.Tag = "ins_rechazos" Then 'query tag
|
|
For Each records() As Object In result.Rows
|
|
For Each k As String In result.Columns.Keys
|
|
Log(k & ": " & records(result.Columns.Get(k)))
|
|
Next
|
|
Next
|
|
End If
|
|
End If
|
|
Job.Release
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub B4XPage_CloseRequest As ResumableSub
|
|
' BACK key pressed
|
|
B4XPages.ShowPage("Login")
|
|
' Returning False signals the system to handle the key
|
|
Return False
|
|
End Sub
|
|
|
|
'Inicia camara
|
|
|
|
Private Sub B4XPage_Disappear
|
|
If p_camara.Visible = True Then
|
|
p_camara.Visible = False
|
|
StopCamera
|
|
End If
|
|
End Sub
|
|
|
|
|
|
Sub btnStartStop_Click
|
|
If Capturing = False Then
|
|
p_camara.Visible = True
|
|
StartCamera
|
|
Else
|
|
p_camara.Visible = False
|
|
StopCamera
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub B_cerrar_Click
|
|
' If et_codigo.Text.Length = 0 Then
|
|
' p_camara.Visible = False
|
|
' Else
|
|
' p_camara.Visible = False
|
|
' et_codigo_EnterPressed
|
|
' End If
|
|
StopCamera
|
|
p_camara.Visible = False
|
|
End Sub
|
|
|
|
Private Sub StopCamera
|
|
' et_codigo.Text = ""
|
|
Capturing = False
|
|
pnlPreview.Visible = False
|
|
If camEx.IsInitialized Then
|
|
camEx.Release
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub StartCameraShared
|
|
pnlPreview.Visible = True
|
|
Capturing = True
|
|
End Sub
|
|
|
|
Private Sub FoundBarcode (msg As String)
|
|
' et_codigo.Text = msg
|
|
toast.Show($"Found [Color=Red][b][plain]${msg}[/plain][/b][/Color]"$)
|
|
Log(msg)
|
|
codigoencontrado = msg
|
|
Log($"${codigoencontrado}, ${codigoBuscado}"$)
|
|
If codigoBuscado = "placas" Then
|
|
et_placas.text = codigoencontrado
|
|
Else If codigoBuscado = "operador" Then
|
|
Log("ponemos operador en HOLA")
|
|
et_operador.text = codigoencontrado
|
|
Else If codigoBuscado = "ruta" Then
|
|
et_rutaReparto.text = codigoencontrado
|
|
End If
|
|
' If et_codigo.Text.Length > 1 Then
|
|
B_cerrar_Click
|
|
' End If
|
|
End Sub
|
|
|
|
Private Sub StartCamera
|
|
rp.CheckAndRequest(rp.PERMISSION_CAMERA)
|
|
Wait For B4XPage_PermissionResult (Permission As String, Result As Boolean)
|
|
If Result = False Then
|
|
toast.Show("No permission!")
|
|
Return
|
|
End If
|
|
StartCameraShared
|
|
camEx.Initialize(pnlPreview, False, Me, "Camera1")
|
|
Wait For Camera1_Ready (Success As Boolean)
|
|
If Success Then
|
|
camEx.SetContinuousAutoFocus
|
|
camEx.CommitParameters
|
|
camEx.StartPreview
|
|
Else
|
|
toast.Show("Error opening camera")
|
|
StopCamera
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub CreateDetector (Codes As List)
|
|
Dim ctxt As JavaObject
|
|
ctxt.InitializeContext
|
|
Dim builder As JavaObject
|
|
builder.InitializeNewInstance("com/google/android/gms/vision/barcode/BarcodeDetector.Builder".Replace("/", "."), Array(ctxt))
|
|
Dim barcodeClass As String = "com/google/android/gms/vision/barcode/Barcode".Replace("/", ".")
|
|
Dim barcodeStatic As JavaObject
|
|
barcodeStatic.InitializeStatic(barcodeClass)
|
|
Dim format As Int
|
|
For Each formatName As String In Codes
|
|
format = Bit.Or(format, barcodeStatic.GetField(formatName))
|
|
Next
|
|
builder.RunMethod("setBarcodeFormats", Array(format))
|
|
detector = builder.RunMethod("build", Null)
|
|
Dim operational As Boolean = detector.RunMethod("isOperational", Null)
|
|
If operational = False Then
|
|
toast.Show("Failed to create detector")
|
|
End If
|
|
b_escanOperador.Enabled = operational
|
|
b_escanPlacas.Enabled = operational
|
|
b_escanRuta.Enabled = operational
|
|
End Sub
|
|
|
|
Private Sub Camera1_Preview (data() As Byte)
|
|
If DateTime.Now > LastPreview + IntervalBetweenPreviewsMs Then
|
|
'Dim n As Long = DateTime.Now
|
|
Dim frameBuilder As JavaObject
|
|
Dim bb As JavaObject
|
|
bb = bb.InitializeStatic("java.nio.ByteBuffer").RunMethod("wrap", Array(data))
|
|
frameBuilder.InitializeNewInstance("com/google/android/gms/vision/Frame.Builder".Replace("/", "."), Null)
|
|
Dim cs As CameraSize = camEx.GetPreviewSize
|
|
frameBuilder.RunMethod("setImageData", Array(bb, cs.Width, cs.Height, 842094169))
|
|
Dim frame As JavaObject = frameBuilder.RunMethod("build", Null)
|
|
Dim SparseArray As JavaObject = detector.RunMethod("detect", Array(frame))
|
|
LastPreview = DateTime.Now
|
|
Dim Matches As Int = SparseArray.RunMethod("size", Null)
|
|
If Matches > 0 Then
|
|
Dim barcode As JavaObject = SparseArray.RunMethod("valueAt", Array(0))
|
|
Dim raw As String = barcode.GetField("rawValue")
|
|
FoundBarcode(raw)
|
|
End If
|
|
End If
|
|
End Sub
|
|
|
|
'fin camara
|
|
|
|
Private Sub b_guardar_Click
|
|
Starter.skmt.ExecNonQuery($"insert into CONTROL_KMS (PLACAS, OPERADOR, RUTA, KMS_INICIAL, KMS_FINAL) values ('${et_placas.text}', '${et_operador.text}', '${et_rutaReparto.text}', '${et_kmsInicial.text}', '${et_kmsFinal.text}')"$)
|
|
End Sub
|
|
|
|
Private Sub pnlPreview_Click
|
|
|
|
End Sub
|
|
|
|
Private Sub p_camara_Click
|
|
|
|
End Sub
|
|
|
|
Private Sub b_escanPlacas_Click
|
|
ime.HideKeyboard
|
|
codigoBuscado = "placas"
|
|
Subs.panelVisible(p_camara, 0, 0)
|
|
If Capturing = False Then
|
|
p_camara.Visible = True
|
|
StartCamera
|
|
Else
|
|
p_camara.Visible = False
|
|
StopCamera
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub b_escanOperador_Click
|
|
ime.HideKeyboard
|
|
codigoBuscado = "operador"
|
|
Subs.panelVisible(p_camara, 0, 0)
|
|
If Capturing = False Then
|
|
p_camara.Visible = True
|
|
StartCamera
|
|
Else
|
|
p_camara.Visible = False
|
|
StopCamera
|
|
End If
|
|
End Sub
|
|
|
|
Private Sub b_escanRuta_Click
|
|
ime.HideKeyboard
|
|
codigoBuscado = "ruta"
|
|
Subs.panelVisible(p_camara, 0, 0)
|
|
If Capturing = False Then
|
|
p_camara.Visible = True
|
|
StartCamera
|
|
Else
|
|
p_camara.Visible = False
|
|
StopCamera
|
|
End If
|
|
End Sub |