09/09/23 - Panel de configuración y servicio al arranque

Se agregó´un panel para cambiar algunos parametros de la aplicación y se agregó´un servicio para que el monitor arranque junto con el dispositivo, para esto es necesario darle permisos para accesar las notificaciones del sistema.
This commit is contained in:
2023-09-10 00:28:33 -06:00
parent afe26d8653
commit d342c85e15
11 changed files with 744 additions and 432 deletions

View File

@@ -22,13 +22,6 @@ Sub Class_Globals
Private xui As XUI
Public login As B4XMainPage
Dim s As C_Subs
Dim reqManager As DBRequestManager
Dim ruta As String
Dim batterystatus(11) As Int
Private bu As BatteryUtilities
Private tb_monitorActivo As ToggleButton
Private b_monitorActivo As Button
Private p_bMonitor As Panel
Private l_version As Label
@@ -37,6 +30,24 @@ Sub Class_Globals
Dim cb_internet As CheckBox
Dim cb_dbreqserver As CheckBox
Dim cb_db As CheckBox
Private b_intervalo As Button
Private b_server As Button
Private et_server As EditText
Private lv_server As ListView
Private i_engrane As ImageView
Private p_engrane As Panel
Dim b_ping As Button
Private cd1 As ColorDrawable
Dim l_ultimoPing As Label
Private p_intervalo As Panel
Private et_intervalo As EditText
Private p_timeout As Panel
Private et_timeout As EditText
Private l_timeout As Label
Private b_timeout As Button
Private Label1 As Label
Private b_notifAccess As Button
Dim logger As Boolean = False
End Sub
Public Sub Initialize
@@ -47,76 +58,150 @@ End Sub
Private Sub B4XPage_Created (Root1 As B4XView)
Root = Root1
Root.LoadLayout("login")
B4XPages.SetTitle(Me, "Tester")
B4XPages.SetTitle(Me, "Monitor Keymon")
B4XPages.AddPage("Login", login)
s.Initialize
l_version.Text = Application.VersionName
' ruta = Starter.ruta
' If File.Exists(ruta, "kmt.db") = False Then
' File.Copy(File.DirAssets, "kmt.db", ruta, "kmt.db")
' Log(File.DirAssets)
' LogColor("copiamos kmt.db de "&File.DirAssets & " a " & ruta,Colors.Green)
' End If
If Starter.logger Then Log(ruta)
' skmt.Initialize(ruta,"kmt.db", True)
' Subs.guardaAppInfo(skmt)
lv_server.AddSingleLine("http://keymon.lat:1782")
lv_server.AddSingleLine("http://10.0.0.205:1782")
et_server.Text = Starter.DBReqServer
#if not(DEBUG)
logger = False
#end if
End Sub
Sub B4XPage_Appear
reqManager.Initialize(Me, Starter.server)
bu.Initialize
batterystatus = bu.BatteryInformation
s.centraPanel(p_bMonitor, Root.Width)
' reqManager.Initialize(Me, Starter.DBReqServer)
cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
b_ping.Background = cd1
' bu.Initialize
' batterystatus = bu.BatteryInformation
b_monitorActivo.Left = (Root.Width / 2) - (b_monitorActivo.Width / 2)
b_ping.Left = (Root.Width / 2) - (b_ping.Width / 2)
s.centraPanel(p_estatus, Root.Width)
s.centraEtiqueta(l_status, Root.Width)
End Sub
Sub JobDone(Job As HttpJob)
If Starter.logger Then Log(Job.Success)
If Job.Success = False Then
' ToastMessageShow("Error: " & Job.ErrorMessage, True)
s.centraEtiqueta(l_ultimoPing, Root.Width)
s.centraPanel(p_intervalo, Root.Width)
s.centraEtiqueta(Label1, Root.Width)
If Not(CheckNotificationAccess) Then
Private cd1 As ColorDrawable
cd1.Initialize(Colors.red, 10dip)
b_notifAccess.Background = cd1
b_notifAccess.TextColor = Colors.White
b_notifAccess.Text = "Activar Permisos"
Else
If Starter.logger Then LogColor("JobDone: '" & reqManager.HandleJob(Job).tag & "' - Registros: " & reqManager.HandleJob(Job).Rows.Size, Colors.Green) 'Mod por CHV - 211027
If Job.JobName = "DBRequest" Then
Dim result As DBResult = reqManager.HandleJob(Job)
If result.Tag = "agencia" Then 'query tag
For Each records() As Object In result.Rows
Dim ID_ALMACEN As String = records(result.Columns.Get("ID_ALMACEN"))
Next
End If
End If
Job.Release
Private cd1 As ColorDrawable
cd1.Initialize(Colors.RGB(109, 221, 101), 10dip)
b_notifAccess.Background = cd1
b_notifAccess.TextColor = Colors.White
b_notifAccess.Text = "Permisos Activos"
End If
CallSubDelayed(Monitor, "Timer1_Tick")
End Sub
Private Sub B4XPage_CloseRequest As ResumableSub
If Starter.logger Then Log("closreq")
Sleep(0)
Return True
If p_engrane.Visible Then
p_engrane.Visible = False
End If
Return False
End Sub
'Revisa si la aplicación tiene permiso para acceder a las notificaciones.
Sub CheckNotificationAccess As Boolean
Dim ph As Phone
Dim nstr, pstr As String
Dim r As Reflector
pstr = r.GetStaticField("anywheresoftware.b4a.BA", "packageName")
nstr = ph.GetSettings("enabled_notification_listeners")
Return nstr.Contains(pstr)
End Sub
Private Sub tb_monitorActivo_CheckedChange(Checked As Boolean)
End Sub
Private Sub b_monitorActivo_Click
Private cd1 As ColorDrawable
If logger Then Log(Starter.DBReqServer)
If Starter.monitorActivo Then
cd1.Initialize(Colors.red, 10dip)
b_monitorActivo.Background = cd1
b_monitorActivo.Text = "Monitor Apagado"
l_status.Text = "Monitor Apagado"
Starter.monitorActivo = False
Starter.notiHigh("Con internet", $"Monitor apagado!!"$, Starter.nid, Main)
s.notiHigh("Con internet", $"Monitor apagado!!"$, Monitor.nid, Main)
Else
cd1.Initialize(Colors.RGB(16, 141, 0), 10dip)
b_monitorActivo.Background = cd1
b_monitorActivo.Text = "Monitor Activo"
l_status.Text = "Monitor Activo"
Starter.Timer1_Tick
CallSubDelayed(Monitor, "Timer1_Tick")
Starter.monitorActivo = False
Starter.monitorActivo = True
End If
End Sub
End Sub
Private Sub lv_server_ItemClick (Position As Int, Value As Object)
If logger Then Log(Value)
et_server.Text = Value
Starter.DBReqServer = Value
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'servidor'"$)
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("servidor", '${Value}')"$)
CallSubDelayed(Monitor, "reinicializaReqManager")
ToastMessageShow($"Servidor modificado"$, False)
End Sub
Private Sub b_server_Click
Starter.DBReqServer = et_server.text
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'servidor'"$)
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("servidor", '${et_server.text}')"$)
CallSubDelayed(Monitor, "reinicializaReqManager")
ToastMessageShow($"Servidor modificado"$, False)
p_engrane.Visible = False
CallSubDelayed(Monitor, "Timer1_Tick")
End Sub
Private Sub b_intervalo_Click
Monitor.Interval = et_intervalo.text
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'intervalo'"$)
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("intervalo", '${et_intervalo.text}')"$)
ToastMessageShow($"Intervalo modificado"$, False)
CallSubDelayed(Monitor, "Timer1_Tick")
p_engrane.Visible = False
End Sub
Private Sub i_engrane_Click
et_intervalo.Text = s.traeIntervaloDeBD
et_timeout.Text = s.traeTimeoutDeBD
p_engrane.Width = Root.Width
p_engrane.Height = Root.Height
s.panelVisible(p_engrane, 0, 0)
End Sub
Private Sub p_engrane_Click
End Sub
Private Sub b_ping_Click
cd1.Initialize(Colors.RGB(5, 104, 0), 10dip)
b_ping.Background = cd1
b_ping.Text = "Buscando ..."
CallSubDelayed(Monitor, "Timer1_Tick")
End Sub
Private Sub b_timeout_Click
Monitor.timeout = et_timeout.text
Starter.skmt.ExecNonQuery($"delete from cat_variables where nombre = 'timeout'"$)
Starter.skmt.ExecNonQuery($"insert into cat_variables (nombre, valor) values ("timeout", '${et_timeout.text}')"$)
ToastMessageShow($"Intervalo modificado"$, False)
CallSubDelayed(Monitor, "Timer1_Tick")
p_engrane.Visible = False
End Sub
'You can see the list of page related events in the B4XPagesManager object. The event name is B4XPage.
Sub b_notifAccess_Click
Dim In As Intent
In.Initialize("android.settings.ACTION_NOTIFICATION_LISTENER_SETTINGS", "")
StartActivity(In)
End Sub