mirror of
https://github.com/cheveguerra/Pusher_2.0.git
synced 2026-04-17 19:37:05 +00:00
28/9/23 - Se agregó´codigo para guardar las geocercas y recibir mensajes push.
- Se agregó la base de datos y el codigo para guardar y administrar las geocercas. - Se modificó el codigo de los mensajes push recibidos, para que mande una notificación si la ubicación recibida esta dentro de una geocerca.
This commit is contained in:
BIN
Files/layout.bal
BIN
Files/layout.bal
Binary file not shown.
@@ -6,10 +6,12 @@ Version=10.5
|
|||||||
@EndOfDesignText@
|
@EndOfDesignText@
|
||||||
Sub Process_Globals
|
Sub Process_Globals
|
||||||
Private fm As FirebaseMessaging
|
Private fm As FirebaseMessaging
|
||||||
|
Dim db As SQL
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub Service_Create
|
Sub Service_Create
|
||||||
fm.Initialize("fm")
|
fm.Initialize("fm")
|
||||||
|
db = Subs.dbInit
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Public Sub SubscribeToTopics
|
Public Sub SubscribeToTopics
|
||||||
@@ -49,8 +51,32 @@ Sub fm_MessageArrived (Message As RemoteMessage)
|
|||||||
'Si el mensaje es de ubicacion recibida
|
'Si el mensaje es de ubicacion recibida
|
||||||
If Message.GetData.ContainsKey("t") And (Message.GetData.Get("t") = "u" Or Message.GetData.Get("t") = "au") Then
|
If Message.GetData.ContainsKey("t") And (Message.GetData.Get("t") = "u" Or Message.GetData.Get("t") = "au") Then
|
||||||
Log("Recibimos ubicacion")
|
Log("Recibimos ubicacion")
|
||||||
|
Private ubi As Location
|
||||||
Log("Llamamos UbicacionRecibida")
|
Log("Llamamos UbicacionRecibida")
|
||||||
If Message.GetData.Get("t") = "au" Then ToastMessageShow("Ubicacion recibida:"&Message.GetData.Get("d"),False)
|
If Message.GetData.Get("t") = "au" Then
|
||||||
|
' ToastMessageShow("Ubicacion recibida:"&Message.GetData.Get("body"),False)
|
||||||
|
Private coords() As String = Regex.split(",", Message.GetData.Get("body"))
|
||||||
|
ubi.Initialize
|
||||||
|
ubi.Latitude = coords(0)
|
||||||
|
ubi.Longitude = coords(1)
|
||||||
|
Private c As Cursor = db.ExecQuery("select * from geocercas") 'Traemos las geocercas
|
||||||
|
Private estaGC As Location
|
||||||
|
If c.RowCount > 0 Then
|
||||||
|
For i = 0 To c.RowCount - 1
|
||||||
|
c.Position = i
|
||||||
|
estaGC.Initialize
|
||||||
|
estaGC.Latitude = c.GetString("lat")
|
||||||
|
estaGC.Longitude = c.GetString("lon")
|
||||||
|
Log(ubi & "|" & estaGC)
|
||||||
|
Log(ubi.DistanceTo(estaGC))
|
||||||
|
If ubi.DistanceTo(estaGC) < 300 Then 'Revisamos si la ubicaccion recibida esta dentro de alguna geocerca.
|
||||||
|
' ToastMessageShow($"Dentro de ${c.GetString("nombre")}"$, False)
|
||||||
|
Subs.notiHigh("Dentro de Geocerca", $"${Message.GetData.Get("d")} esta dentro de ${c.GetString("nombre")}"$, 777, "Main")
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
' Subs.notiHigh("Dentro de Geocerca", $"${Message.GetData.Get("d")} esta dentro de ${c.GetString("nombre")}"$, 777, "Main")
|
||||||
|
End If
|
||||||
CallSub2(Main, "ubicacionRecibida", Message.GetData)
|
CallSub2(Main, "ubicacionRecibida", Message.GetData)
|
||||||
End If
|
End If
|
||||||
|
|
||||||
|
|||||||
89
Pusher.b4a
89
Pusher.b4a
@@ -45,11 +45,12 @@ Library14=json
|
|||||||
Library15=okhttputils2
|
Library15=okhttputils2
|
||||||
Library16=phone
|
Library16=phone
|
||||||
Library17=randomaccessfile
|
Library17=randomaccessfile
|
||||||
Library18=runtimepermissions
|
Library18=reflection
|
||||||
Library19=xcustomlistview
|
Library19=runtimepermissions
|
||||||
Library2=byteconverter
|
Library2=byteconverter
|
||||||
Library20=xui
|
Library20=xcustomlistview
|
||||||
Library21=reflection
|
Library21=xui
|
||||||
|
Library22=sql
|
||||||
Library3=compressstrings
|
Library3=compressstrings
|
||||||
Library4=core
|
Library4=core
|
||||||
Library5=dateutils
|
Library5=dateutils
|
||||||
@@ -65,7 +66,7 @@ Module4=MyPopup
|
|||||||
Module5=Starter
|
Module5=Starter
|
||||||
Module6=Subs
|
Module6=Subs
|
||||||
NumberOfFiles=18
|
NumberOfFiles=18
|
||||||
NumberOfLibraries=21
|
NumberOfLibraries=22
|
||||||
NumberOfModules=6
|
NumberOfModules=6
|
||||||
Version=12.5
|
Version=12.5
|
||||||
@EndOfDesignText@
|
@EndOfDesignText@
|
||||||
@@ -103,6 +104,7 @@ Sub Process_Globals
|
|||||||
'Api
|
'Api
|
||||||
Private const API_KEY As String = "AAAAv1qt3Lk:APA91bECIR-pHn6ul53eYyoVlpPuOo85RO-0zcAgEXwE7vqw8DFSbBtCaCINiqWQAkBBZXxHtQMdpU6B-jHIqgFKVL196UgwHv0Gw6_IgmipfV_NiItjzlH9d2QNpGLp9y_JUKVjUEhP"
|
Private const API_KEY As String = "AAAAv1qt3Lk:APA91bECIR-pHn6ul53eYyoVlpPuOo85RO-0zcAgEXwE7vqw8DFSbBtCaCINiqWQAkBBZXxHtQMdpU6B-jHIqgFKVL196UgwHv0Gw6_IgmipfV_NiItjzlH9d2QNpGLp9y_JUKVjUEhP"
|
||||||
Private rp As RuntimePermissions
|
Private rp As RuntimePermissions
|
||||||
|
Dim db As SQL
|
||||||
Dim phn As Phone
|
Dim phn As Phone
|
||||||
Dim devModel As String
|
Dim devModel As String
|
||||||
Dim dUbicados As Int 'Dispositivos con ubicacion
|
Dim dUbicados As Int 'Dispositivos con ubicacion
|
||||||
@@ -124,6 +126,7 @@ Sub Process_Globals
|
|||||||
Private hInicio, hFinal As String
|
Private hInicio, hFinal As String
|
||||||
Private distanciaRecorrida As String = "0"
|
Private distanciaRecorrida As String = "0"
|
||||||
Private usuario As String
|
Private usuario As String
|
||||||
|
dim punto as LatLng
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub Globals
|
Sub Globals
|
||||||
@@ -181,20 +184,25 @@ Sub Globals
|
|||||||
Private et_gc_nombre As EditText
|
Private et_gc_nombre As EditText
|
||||||
Private b_gc_cancelar As Button
|
Private b_gc_cancelar As Button
|
||||||
Private b_gc_ok As Button
|
Private b_gc_ok As Button
|
||||||
|
Private b_geocercas As Button
|
||||||
|
Private p_geocercas As Panel
|
||||||
|
Private lv_geocercas As ListView
|
||||||
|
Private b_cerrar As Button
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub Activity_Create(FirstTime As Boolean) 'ignore
|
Sub Activity_Create(FirstTime As Boolean) 'ignore
|
||||||
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
|
Starter.rp.CheckAndRequest(Starter.rp.PERMISSION_WRITE_EXTERNAL_STORAGE)
|
||||||
' Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
' Wait For Activity_PermissionResult (Permission As String, Result As Boolean)
|
||||||
Dim p As String
|
db = Subs.dbInit
|
||||||
|
Dim p As String 'ignore
|
||||||
If File.ExternalWritable Then
|
If File.ExternalWritable Then
|
||||||
p = File.DirRootExternal
|
p = File.DirRootExternal
|
||||||
Else
|
Else
|
||||||
p = File.DirInternal
|
p = File.DirInternal
|
||||||
End If
|
End If
|
||||||
Log("rootExternal="&p)
|
' Log("rootExternal="&p)
|
||||||
Log("File.DirInternal="&File.DirInternal)
|
' Log("File.DirInternal="&File.DirInternal)
|
||||||
Log("File.DirRootExternal="&File.DirRootExternal)
|
' Log("File.DirRootExternal="&File.DirRootExternal)
|
||||||
|
|
||||||
Activity.LoadLayout("Layout")
|
Activity.LoadLayout("Layout")
|
||||||
clientes.Initialize
|
clientes.Initialize
|
||||||
@@ -222,6 +230,9 @@ Sub Activity_Create(FirstTime As Boolean) 'ignore
|
|||||||
topInicialBuscador = p_buscador.top
|
topInicialBuscador = p_buscador.top
|
||||||
s_tracker.AddAll(clientes)
|
s_tracker.AddAll(clientes)
|
||||||
cb_puntosIntermedios.Checked = True
|
cb_puntosIntermedios.Checked = True
|
||||||
|
|
||||||
|
p_geocercas.BringToFront
|
||||||
|
p_geocercas.Left = (Activity.Width / 2) - (p_geocercas.Width / 2)
|
||||||
' reqManager.Initialize(Me, "http://10.0.0.205:1782")
|
' reqManager.Initialize(Me, "http://10.0.0.205:1782")
|
||||||
' s_hora.AddAll(Array As String("00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"))
|
' s_hora.AddAll(Array As String("00", "01", "02", "03", "04", "05", "06", "07", "08", "09", "10", "11", "12", "13", "14", "15", "16", "17", "18", "19", "20", "21", "22", "23"))
|
||||||
End Sub
|
End Sub
|
||||||
@@ -304,6 +315,7 @@ Sub JobDone(Job As HttpJob)
|
|||||||
Subs.SetDateFormat("es", "MX", "MMM d")
|
Subs.SetDateFormat("es", "MX", "MMM d")
|
||||||
distanciaRecorrida = 0
|
distanciaRecorrida = 0
|
||||||
cont = 0
|
cont = 0
|
||||||
|
Private c As Cursor = db.ExecQuery("select * from geocercas")
|
||||||
For Each records() As Object In result.Rows
|
For Each records() As Object In result.Rows
|
||||||
' Log(records(result.Columns.Get("FECHA")))
|
' Log(records(result.Columns.Get("FECHA")))
|
||||||
If cont = 0 Then
|
If cont = 0 Then
|
||||||
@@ -329,12 +341,29 @@ Sub JobDone(Job As HttpJob)
|
|||||||
End If
|
End If
|
||||||
End If
|
End If
|
||||||
cont = cont + 1
|
cont = cont + 1
|
||||||
|
|
||||||
coordsAnt.Latitude = estasCoords.Latitude
|
coordsAnt.Latitude = estasCoords.Latitude
|
||||||
coordsAnt.Longitude = estasCoords.Longitude
|
coordsAnt.Longitude = estasCoords.Longitude
|
||||||
fechaFinRutaGPS = Subs.fechaKMT2Ticks(records(result.Columns.Get("FECHA")))
|
fechaFinRutaGPS = Subs.fechaKMT2Ticks(records(result.Columns.Get("FECHA")))
|
||||||
DateTime.timeformat = "HH:mm"
|
DateTime.timeformat = "HH:mm"
|
||||||
fechaFinRutaGPS = DateTime.Date(fechaFinRutaGPS) & ", " & DateTime.Time(fechaFinRutaGPS)
|
fechaFinRutaGPS = DateTime.Date(fechaFinRutaGPS) & ", " & DateTime.Time(fechaFinRutaGPS)
|
||||||
Next
|
Next
|
||||||
|
Private estaGC As Location
|
||||||
|
If c.RowCount > 0 Then
|
||||||
|
For i = 0 To c.RowCount - 1
|
||||||
|
c.Position = i
|
||||||
|
estaGC.Initialize
|
||||||
|
estaGC.Latitude = c.GetString("lat")
|
||||||
|
estaGC.Longitude = c.GetString("lon")
|
||||||
|
' Log(estasCoords & "|" & thisGC)
|
||||||
|
Log(estasCoords.DistanceTo(estaGC))
|
||||||
|
If estasCoords.DistanceTo(estaGC) < 300 Then
|
||||||
|
ToastMessageShow($"Dentro de ${c.GetString("nombre")}"$, False)
|
||||||
|
' Subs.notiHigh("Dentro de Geocerca", $"${usuario} esta dentro de ${c.GetString("nombre")}"$, 777, "Main")
|
||||||
|
End If
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
c.Close
|
||||||
ToastMessageShow("Recibimos ruta con " & reqManager.HandleJob(Job).Rows.Size & " puntos.", False)
|
ToastMessageShow("Recibimos ruta con " & reqManager.HandleJob(Job).Rows.Size & " puntos.", False)
|
||||||
' Log(rutaGPS)
|
' Log(rutaGPS)
|
||||||
LogColor($"Distancia recorrida: $1.1{distanciaRecorrida/1000} kms."$, Colors.Magenta)
|
LogColor($"Distancia recorrida: $1.1{distanciaRecorrida/1000} kms."$, Colors.Magenta)
|
||||||
@@ -533,6 +562,7 @@ Sub MapFragment2_LongClick(Point As LatLng)
|
|||||||
p_addGeofence.BringToFront
|
p_addGeofence.BringToFront
|
||||||
p_addGeofence.Left = (Activity.Width / 2) - (p_addGeofence.Width / 2)
|
p_addGeofence.Left = (Activity.Width / 2) - (p_addGeofence.Width / 2)
|
||||||
p_addGeofence.Visible = True
|
p_addGeofence.Visible = True
|
||||||
|
punto = Point
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Sub InfoWindowAdapter1_GetInfoContents(Marker1 As Marker) As View
|
Sub InfoWindowAdapter1_GetInfoContents(Marker1 As Marker) As View
|
||||||
@@ -681,6 +711,7 @@ Sub b_buscar_longClick
|
|||||||
p_ruta.Height = Activity.Height
|
p_ruta.Height = Activity.Height
|
||||||
p_periodoInfo.Top = Activity.Height - p_periodoInfo.Height - 5
|
p_periodoInfo.Top = Activity.Height - p_periodoInfo.Height - 5
|
||||||
b_regresar.Top = Activity.Height - b_regresar.Height - 5
|
b_regresar.Top = Activity.Height - b_regresar.Height - 5
|
||||||
|
b_geocercas.Top = Activity.Height - b_geocercas.Height - 130
|
||||||
l_periodoTitulo.Top = Activity.Height - (Activity.Height - p_mapa2.Height)
|
l_periodoTitulo.Top = Activity.Height - (Activity.Height - p_mapa2.Height)
|
||||||
l_periodo.Top = Activity.Height - (Activity.Height - p_mapa2.Height) + 10
|
l_periodo.Top = Activity.Height - (Activity.Height - p_mapa2.Height) + 10
|
||||||
s_rutas.Top = l_periodoTitulo.Top + l_periodoTitulo.Height
|
s_rutas.Top = l_periodoTitulo.Top + l_periodoTitulo.Height
|
||||||
@@ -787,8 +818,48 @@ End Sub
|
|||||||
|
|
||||||
Private Sub b_gc_ok_Click
|
Private Sub b_gc_ok_Click
|
||||||
p_addGeofence.Visible = False
|
p_addGeofence.Visible = False
|
||||||
|
db.ExecNonQuery($"insert into geocercas (nombre, lat, lon) values ('${et_gc_nombre.Text}', '${punto.Latitude}', '${punto.Longitude}')"$)
|
||||||
|
et_gc_nombre.Text = ""
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
Private Sub b_gc_cancelar_Click
|
Private Sub b_gc_cancelar_Click
|
||||||
p_addGeofence.Visible = False
|
p_addGeofence.Visible = False
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
Private Sub b_geocercas_Click
|
||||||
|
Private c As Cursor = db.ExecQuery("select * from geocercas")
|
||||||
|
Dim nombre As Label = lv_geocercas.SingleLineLayout.Label
|
||||||
|
nombre.TextColor = Colors.Black
|
||||||
|
nombre.TextSize = 14
|
||||||
|
lv_geocercas.SingleLineLayout.ItemHeight = 30dip
|
||||||
|
lv_geocercas.Clear
|
||||||
|
If c.RowCount > 1 Then
|
||||||
|
For i = 0 To c.RowCount - 1
|
||||||
|
c.Position = i
|
||||||
|
lv_geocercas.AddSingleLine($"${c.GetString("nombre")}"$)
|
||||||
|
Next
|
||||||
|
End If
|
||||||
|
c.Close
|
||||||
|
p_geocercas.BringToFront
|
||||||
|
p_geocercas.Visible = True
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub lv_geocercas_ItemClick (Position As Int, Value As Object)
|
||||||
|
ToastMessageShow("Clic largo para borrar", False)
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
|
||||||
|
Private Sub lv_geocercas_ItemLongClick (Position As Int, Value As Object)
|
||||||
|
If Msgbox2($"Seguro que desea borrar la geocerca "${Value}""$, "AVISO", "Aceptar", "Cancelar", "", Null) = DialogResponse.POSITIVE Then 'ignore
|
||||||
|
db.ExecNonQuery($"delete from geocercas where nombre = '${Value}'"$)
|
||||||
|
End If
|
||||||
|
p_geocercas.Visible = False
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub p_geocercas_Click
|
||||||
|
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
Private Sub b_cerrar_Click
|
||||||
|
p_geocercas.Visible = False
|
||||||
|
End Sub
|
||||||
25
subs.bas
25
subs.bas
@@ -138,6 +138,31 @@ Sub centraPanel(elemento As Panel, anchoElementoSuperior As Int) 'ignore
|
|||||||
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
|
elemento.Left = Round(anchoElementoSuperior/2)-(elemento.Width/2)
|
||||||
End Sub
|
End Sub
|
||||||
|
|
||||||
|
'Inicializa la BD con "kmt.db" en File.DirInternal, si el archivo no existe, lo copia desde File.DirAssets.
|
||||||
|
'Dispara el evento "dbOk" cuando termina.
|
||||||
|
Sub dbInit As SQL
|
||||||
|
Private db As SQL
|
||||||
|
' If File.Exists(File.DirInternal, "push.db") = False Then File.Copy(File.DirAssets, "push.db", File.DirInternal, "kmt.db")
|
||||||
|
db.Initialize(File.DirInternal,"push.db", True)
|
||||||
|
db.ExecNonQuery("CREATE TABLE IF NOT EXISTS geocercas (nombre TEXT, lat TEXT, lon TEXT)")
|
||||||
|
Return db
|
||||||
|
End Sub
|
||||||
|
|
||||||
|
'Genera una notificacion con importancia alta
|
||||||
|
Sub notiHigh(title As String, body As String, id As String, activity As Object) 'ignore
|
||||||
|
activity = Main
|
||||||
|
Private notif As Notification
|
||||||
|
notif.Initialize2(notif.IMPORTANCE_HIGH)
|
||||||
|
notif.Icon = "icon"
|
||||||
|
notif.Vibrate = False
|
||||||
|
notif.Sound = False
|
||||||
|
notif.AutoCancel = True
|
||||||
|
' If logger Then Log("notiHigh: "&title)
|
||||||
|
notif.SetInfo(title, body, activity)
|
||||||
|
' Log("notiHigh SetInfo")
|
||||||
|
notif.Notify(id)
|
||||||
|
End Sub
|
||||||
|
|
||||||
'Geo-Zone Determination (Point in Polygon)
|
'Geo-Zone Determination (Point in Polygon)
|
||||||
'Use this to determine If a vehicle is within a defined zone made of 5 or more lat/lon coordinates.
|
'Use this to determine If a vehicle is within a defined zone made of 5 or more lat/lon coordinates.
|
||||||
'Point 1 Is also Point 5 (first point And last point are same value).
|
'Point 1 Is also Point 5 (first point And last point are same value).
|
||||||
|
|||||||
Reference in New Issue
Block a user