CONTOH LISTING PROGRAM ANDROID
LISTING
PROGRAM ANDROID
#Region Project Attributes
#ApplicationLabel:
Security Control
#VersionCode:
1
#VersionName:
'SupportedOrientations
possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: False
#End Region
#Region Activity Attributes
#FullScreen: True
#IncludeTitle: True
#End Region
Sub Process_Globals
'These global
variables will be declared once when the application starts.
'These variables
can be accessed from all modules.
DimSerial3AsSerial
DimTextReader1AsTextReader
DimTextWriter1AsTextWriter
DimconnectedAsBoolean
DimcurrentAsString
End Sub
Sub Globals
'These global
variables will be redeclared each time the activity is created.
'These variables
can only be accessed from this module.
DimPanel1, Panel2, Panel3AsPanel
DimbtnSTATERAsButton
DimbtnEXITAsButton
DimbtnPENULISAsButton
DimbtnDISCONNECTAsButton
DimbtnCONNECTAsButton
DimbtnMATIAsButton
DimbtnHIDUPAsButton
DimlblSTATUSAsLabel
DimbtnBACKAsButton
DimbtnONOFFAsButton
End Sub
Sub Activity_Create(FirstTime AsBoolean)
'Do not forget
to load the layout file created with the visual designer. For example:
If FirstTime Then
Serial3.Initialize("Serial3")
EndIf
Panel1.Initialize("") : Panel1.Visible = False
Panel2.Initialize("") : Panel2.Visible = False
Panel1.LoadLayout("gpstracker") 'Regular layouts
created with the designer
Panel2.LoadLayout("biografi")
Activity.AddView(Panel1, 0, 0, 100%x, 100%y)
Activity.AddView(Panel2, 0, 0, 100%x, 100%y)
Panel1.Visible = True
Panel2.Visible = False
btnDISCONNECT.Enabled = False
btnCONNECT.Enabled = True
End Sub
Sub Activity_Resume
IfSerial3.IsEnabled = FalseThen
Msgbox("Bluetooth
Anda Belum Aktif.", "Peringatan...!!!")
Else
Serial3.Listen 'listen for
incoming connections
EndIf
End Sub
Sub btnPENULIS_Click
Panel1.Visible = False
Panel2.Visible = True
End Sub
Sub btnONOFF_Click
Ifconnected = FalseThen
Else
TextWriter1.Write("a")
TextWriter1.Flush
EndIf
End Sub
Sub btnHIDUP_Click
Ifconnected = FalseThen
Msgbox("Bluetooth
Belum Terhubung dengan Alat.", "Peringatan...!!!")
Else
TextWriter1.Write("b")
TextWriter1.Flush
EndIf
End Sub
Sub btnHIDUP_Down
Ifconnected = FalseThen
Msgbox("Bluetooth
Belum Terhubung dengan Alat.", "Peringatan...!!!")
Else
TextWriter1.Write("B")
TextWriter1.Flush
EndIf
End Sub
Sub btnMATI_Click
Ifconnected = FalseThen
Msgbox("Bluetooth
Belum Terhubung dengan Alat.", "Peringatan...!!!")
Else
TextWriter1.Write("c")
TextWriter1.Flush
EndIf
End Sub
Sub btnDISCONNECT_Click
Serial3.Disconnect
lblSTATUS.Text = "Disconnected...!!!"
connected = False
ToastMessageShow("Bluetooth
dinonaktifkan...", True)
btnDISCONNECT.Enabled = False
btnCONNECT.Enabled = True
End Sub
Sub btnCONNECT_Click
IfSerial3.IsEnabled = FalseThen
Msgbox("Bluetooth
Anda Belum Aktif.", "Peringatan...!!!")
Else
Dim PairedDevices AsMap
PairedDevices
= Serial3.GetPairedDevices
Dim l AsList
l.Initialize
For i = 0To
PairedDevices.Size - 1
l.Add(PairedDevices.GetKeyAt(i))
Next
Dim res AsInt
res
= InputList(l, "Pilih
Perangkat...", -1) 'show list with paired devices
If res <>DialogResponse.CANCEL Then
Serial3.Connect(PairedDevices.Get(l.Get(res)))
'convert
the name to mac address
current =
PairedDevices.Get(l.Get(res))
EndIf
EndIf
End Sub
Sub Serial3_Connected (success AsBoolean)
If success Then
ToastMessageShow("Koneksi
Bluetooth dg Alat Berhasil...", False)
TextReader1.Initialize(Serial3.InputStream)
TextWriter1.Initialize(Serial3.OutputStream)
lblSTATUS.Text = "...Bluetooth
Terhubung..."
connected = True
btnDISCONNECT.Enabled = True
btnCONNECT.Enabled = False
Else
connected = False
btnDISCONNECT.Enabled = False
btnCONNECT.Enabled = True
lblSTATUS.Text = "Tekan
Tombol Connect..."
Msgbox(LastException.Message, "Error
connecting.")
EndIf
End Sub
Sub btnBACK_Click
Panel1.Visible = True
Panel2.Visible = False
End Sub
Sub btnEXIT_Click
Serial3.Disconnect
Activity.Finish
End Sub
No comments: