mirror of
https://github.com/KeymonSoft/Monitor-Keymon.git
synced 2026-04-18 05:09:21 +00:00
282 lines
9.9 KiB
QBasic
282 lines
9.9 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=git&Args=pull
|
|
'###########################################################################################################
|
|
'###################### PUSH #############################################################
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=github&Args=..\..\
|
|
'###########################################################################################################
|
|
'###################### PUSH TORTOISE GIT #########################################################
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\WindowsPowerShell\v1.0\powershell.exe&Args=TortoiseGitProc&Args=/command:commit&Args=/path:"./../../"&Args=/closeonend:2
|
|
'###########################################################################################################
|
|
#End Region
|
|
|
|
'Ctrl + click ide://run?file=%WINDIR%\System32\cmd.exe&Args=/c&Args=github&Args=..\..\
|
|
|
|
Sub Class_Globals
|
|
Private Root As B4XView
|
|
Private xui As XUI
|
|
Dim ph As Phone
|
|
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_conexion As CheckBox
|
|
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
|
|
Private clv_server As CustomListView
|
|
Private p_listItemServer As Panel
|
|
Private l_server As Label
|
|
Private l_info As Label
|
|
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")
|
|
lv_server.AddSingleLine("http://40.123.36.38:1782")
|
|
|
|
clv_server.Add(CreateListItem("http://keymon.lat:1782", clv_server.AsView.Width, 35dip), "http://keymon.lat:1782")
|
|
clv_server.Add(CreateListItem("http://10.0.0.205:1782", clv_server.AsView.Width, 35dip), "http://10.0.0.205:1782")
|
|
clv_server.Add(CreateListItem("http://40.123.36.38:1782", clv_server.AsView.Width, 35dip), "http://40.123.36.38:1782")
|
|
et_server.Text = Starter.DBReqServer
|
|
#if not(DEBUG)
|
|
logger = False
|
|
#end if
|
|
s.centraEtiqueta(l_info, Root.Width)
|
|
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
|
|
Msgbox2Async($"Se necesita acceso a las notificaciones, haga clic en "Aceptar" y en la siguiente pantalla permita el acceso a la aplicación "${Application.LabelName}"."$, "Permisos necesarios", "Aceptar", "Cancelar", "", Null, True)
|
|
Wait For Msgbox_Result (resultado As Int)
|
|
If resultado = DialogResponse.POSITIVE Then
|
|
b_notifAccess_Click
|
|
End If
|
|
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
|
|
Return False
|
|
Else
|
|
Return True
|
|
End If
|
|
End Sub
|
|
|
|
'Revisa si la aplicación tiene permiso para acceder a las notificaciones.
|
|
Sub CheckNotificationAccess As Boolean
|
|
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 = 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 clv_server_ItemClick (Index 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")
|
|
CallSubDelayed(Monitor, "probamosConexion")
|
|
' Wait For (ph.ShellAsync("ping", Array As String("-c 1","-W 2", "8.8.8.8"))) Complete (Success As Boolean, ExitValue As Int, StdOut As String, StdErr As String)
|
|
' If Success Then
|
|
' Log("ExitValue:" & ExitValue)
|
|
' Log("StdError:" & StdErr)
|
|
' LogColor("StdOut: " & StdOut, Colors.Magenta)
|
|
' Else
|
|
' Log("Error: " & LastException)
|
|
' End If
|
|
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
|
|
|
|
Sub CreateListItem(Text As String, Width As Int, Height As Int) As Panel 'ignore
|
|
Dim p As B4XView = xui.CreatePanel("")
|
|
p.SetLayoutAnimated(0, 0, 0, Width, Height)
|
|
p.LoadLayout("listItem")
|
|
l_server.Height = Height
|
|
l_server.Text = Text
|
|
' i_prod.Bitmap = img
|
|
Return p
|
|
End Sub
|
|
|
|
Private Sub l_info_Click
|
|
l_info.Visible = False
|
|
End Sub
|
|
|
|
Private Sub l_db_Click
|
|
l_info.Visible = True
|
|
End Sub
|
|
|
|
Private Sub l_dbreqserver_Click
|
|
l_info.Visible = True
|
|
End Sub
|
|
|
|
Private Sub l_internet_Click
|
|
l_info.Visible = True
|
|
End Sub
|
|
|
|
Private Sub l_conexion_Click
|
|
l_info.Visible = True
|
|
End Sub
|
|
|
|
Private Sub p_Main_Click
|
|
l_info.Visible = False
|
|
End Sub |