mirror of
https://github.com/KeymonSoft/Monitor-Keymon.git
synced 2026-04-17 21:06:19 +00:00
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.
208 lines
7.0 KiB
QBasic
208 lines
7.0 KiB
QBasic
B4A=true
|
|
Group=Default Group
|
|
ModulesStructureVersion=1
|
|
Type=Class
|
|
Version=9.85
|
|
@EndOfDesignText@
|
|
#Region Shared Files
|
|
#CustomBuildAction: folders ready, %WINDIR%\System32\Robocopy.exe,"..\..\Shared Files" "..\Files"
|
|
'Ctrl + click to sync files: ide://run?file=%WINDIR%\System32\Robocopy.exe&args=..\..\Shared+Files&args=..\Files&FilesSync=True
|
|
'Ctrl + click to export as zip: ide://run?File=%B4X%\Zipper.jar&Args=Project.zip
|
|
'###########################################################################################################
|
|
'###################### PULL #############################################################
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=..\..\gitpull.bat
|
|
'###########################################################################################################
|
|
'###################### PUSH #############################################################
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=github&Args=..\..\
|
|
'###########################################################################################################
|
|
#End Region
|
|
|
|
Sub Class_Globals
|
|
Private Root As B4XView
|
|
Private xui As XUI
|
|
Public login As B4XMainPage
|
|
Dim s As C_Subs
|
|
Private b_monitorActivo As Button
|
|
Private p_bMonitor As Panel
|
|
Private l_version As Label
|
|
Dim l_status As Label
|
|
Private p_estatus As Panel
|
|
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
|
|
' B4XPages.GetManager.LogEvents = True
|
|
End Sub
|
|
|
|
'This event will be called once, before the page becomes visible.
|
|
Private Sub B4XPage_Created (Root1 As B4XView)
|
|
Root = Root1
|
|
Root.LoadLayout("login")
|
|
B4XPages.SetTitle(Me, "Monitor Keymon")
|
|
B4XPages.AddPage("Login", login)
|
|
s.Initialize
|
|
l_version.Text = Application.VersionName
|
|
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.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)
|
|
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
|
|
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)
|
|
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
|
|
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
|
|
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"
|
|
CallSubDelayed(Monitor, "Timer1_Tick")
|
|
Starter.monitorActivo = False
|
|
Starter.monitorActivo = True
|
|
End If
|
|
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
|