#Region Project Attributes
#ApplicationLabel: Cassa
#VersionCode: 1
#VersionName: 1.0
'SupportedOrientations possible values: unspecified, landscape or portrait.
#SupportedOrientations: portrait
#CanInstallToExternalStorage: True
#BridgeLogger: True
#End Region
#Region Activity Attributes
#FullScreen: False
#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.
Dim Serial1 As Serial
Dim TextReader1 As TextReader
Dim Timer1 As Timer
Dim timer2 As Timer
Dim timer3 As Timer
Dim connected As Boolean
Dim mp1 As MediaPlayer
Dim BtAdmin As BluetoothAdmin
Dim BTConnection As Serial
Dim Printer As TextWriter
Dim p As Phone
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.
Dim txtLog As EditText
Dim txtSend As EditText
Private btnSend As Button
Private pnlbase As Panel
Private txttotaleeuro As EditText
Dim k As Int
Private txttavolo As EditText
Private txttavolozza As EditText
Private txtdisplay As EditText
End Sub
Sub Activity_KeyPress (KeyCode As Int) As Boolean
Dim answ As Int
If KeyCode = KeyCodes.KEYCODE_BACK Then
answ = Msgbox2("Sei sicuro di voler uscire dal programma?","AVVISO!!","SI","","NO",Null)
If answ = DialogResponse.POSITIVE Then
ExitApplication
Return False
Else
Return True
End If
End If
End Sub
Sub Activity_Create(FirstTime As Boolean)
'Do not forget to load the layout file created with the visual designer. For example:
If FirstTime Then
Serial1.Initialize("Serial1")
BtAdmin.Initialize("BlueTooth")
BTConnection.Initialize("Printer")
End If
Activity.LoadLayout("cassa")
Timer1.Initialize("Timer1", 200)
timer2.Initialize("timer2",8000)
timer3.Initialize("timer3",2000)
mp1.Initialize
p.SetScreenOrientation(1)
pnlbase.SetLayout(0%x,0%y,100%x,100%y)
txtLog.SetLayout(1%x,1%y,98%x,50%y)
txttavolozza.SetLayout(1%x,72%y,15%x,8%y)
txttavolo.SetLayout(55%x,72%y,15%x,8%y)
txttotaleeuro.SetLayout(73%x,72%y,25%x,8%y)
txtSend.SetLayout(1%x,90%y,70%x,8%y)
btnSend.SetLayout(73%x,90%y,25%x,8%y)
txtLog.Color=Colors.White
txtSend.Color=Colors.White
txttotaleeuro.Color=Colors.White
txttavolo.Color=Colors.White
txttavolozza.Color=Colors.White
End Sub
Sub Activity_Resume
If Serial1.IsEnabled = False Then
Dim i As Intent
i.Initialize("android.settings.BLUETOOTH_SETTINGS", "")
StartActivity(i)
Else
Serial1.Listen 'listen for incoming connections
End If
End Sub
Sub Activity_Pause (UserClosed As Boolean)
End Sub
Sub Serial1_Connected (Success As Boolean)
Dim TextWriter1 As TextWriter
If Success Then
ToastMessageShow("Connessione riuscita", False)
TextReader1.Initialize(Serial1.InputStream)
TextWriter1.Initialize(Serial1.OutputStream)
Timer1.Enabled = True
connected = True
Else
connected = False
Timer1.Enabled = False
Msgbox(LastException.Message, "Errore di connessione.")
End If
End Sub
Sub Timer1_Tick
If connected Then
If TextReader1.Ready Then 'check if there is any data waiting to be read
txtLog.Text = txtLog.Text & TextReader1.ReadLine & CRLF
txtLog.SelectionStart = txtLog.Text.Length
txtdisplay.Text=txtLog.Text
k = txtLog.Text.IndexOf("Tavolo:")' eseguo la ricerca di Tavolo: per poter estrapolare solo la cifra da inserire nella txteuro.text
If k >= 0 Then
txttavolo.Text = txtLog.Text.SubString2(k + 7, txtLog.Text.Length)' da qui estrapolo il tavolo
txttavolozza.Text=txttavolo.Text
End If
End If
End If
End Sub
Sub txtLog_TextChanged (Old As String, New As String)
If txtdisplay.Text = txtLog.Text Then
Else
timer2.Enabled=True
End If
End Sub
Sub timer2_Tick
timer2.Enabled=False
timer3.Enabled=True
End Sub
Sub timer3_Tick
Timer1.Enabled=False
btnSend_Click
timer3.Enabled=False
End Sub
Sub btnSend_Click
Dim PairedDevices As Map
PairedDevices = BTConnection.GetPairedDevices
Dim l As List
Dim DeviceName, MacAddress As String
l.Initialize
For i = 0 To PairedDevices.Size - 1 'Check all devices
l.Add(PairedDevices.GetKeyAt(i))
DeviceName=PairedDevices.Getkeyat(i)
MacAddress=PairedDevices.GetValueAt(i)
Log(DeviceName & " -> " & MacAddress)
If DeviceName.Contains("Thermal") Then 'Insert the BT-Name of the printer or use the MAC address
Exit
End If
Next
BTConnection.Connect(MacAddress)
conteggia
' If connected Then
'TextWriter1.WriteLine(txtSend.Text)
'TextWriter1.Flush
'txtSend.Text = ""
'Else
'Msgbox ("CONTROLLA SE: SEI CONNESSO, DEVI INSERIRE UN TESTO O REINSERIRE UN'IMMAGINE PRIMA DI INVIARE","CAMPO VUOTO")
'End If
End Sub
Sub conteggia
File.WriteString(File.DirRootExternal,txttavolo.Text & ".txt", txtLog.Text)
txtLog.Text=""
Timer1.Enabled=True
End Sub
Sub Printer_Connected (Success As Boolean)
If Success Then
Printer.Initialize2(BTConnection.OutputStream,"windows-1252") 'important to print f.e. German/French chars
' PrintBuffer=Chr(27)&"t"&Chr(16)&" !!!! " 'Set codepage 1252
Printer.WriteLine(txtdisplay.Text)
Printer.Flush
Msgbox("Printed!","")
Printer.Close
BTConnection.Disconnect 'disable this if you like
'btnDisconnetti_Click
timer3.Enabled=True
Else
Msgbox("No printer found...","Print error")
End If
End Sub
Sub txttavolo_TextChanged (Old As String, New As String)
End Sub