-
Notifications
You must be signed in to change notification settings - Fork 0
/
scan.bas
201 lines (132 loc) · 3.49 KB
/
scan.bas
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
B4A=true
Group=Default Group
ModulesStructureVersion=1
Type=Activity
Version=12
@EndOfDesignText@
#Region Activity Attributes
#FullScreen: False
#IncludeTitle: True
'Ignore function value returns warning
#IgnoreWarnings: 2
#End Region
Sub Globals
'These global variables will be redeclared each time the activity is created.
'These variables can only be accessed from this module.
Private qrReaderView As NewQRCodeReaderView
Private btnSwitchCam As Button
Private btnToggleFlash As Button
Private btnBack As Button
Private isBackCamera As Boolean
Private isTorchOn As Boolean
End Sub
Sub Activity_Create(FirstTime As Boolean)
Activity.LoadLayout("ScanLayout")
InitializeQrCodeReader
StartQrCodeReader
End Sub
Sub Activity_KeyPress(KeyCode As Int) As Boolean
If KeyCode = KeyCodes.KEYCODE_BACK Then
ExitScanLayout
Return True
Else
'False means I can let default Android keypress handling do its work
Return False
End If
End Sub
'Useful to reset to turn off Flashlight when pressing Home key durign QR Scan
'
Sub Activity_Pause (UserClosed As Boolean)
StopQrCodeReader
isTorchOn = False
qrReaderView.TorchEnabled = isTorchOn
End Sub
Sub Activity_Resume
StartQrCodeReader
End Sub
'
'Helper code
'
Private Sub InitializeQrCodeReader As Void
isBackCamera = True
isTorchOn = False
'QR decoder settings
qrReaderView.TorchEnabled = isTorchOn
qrReaderView.QRDecodingEnabled = True
qrReaderView.AutofocusInterval = 1500
qrReaderView.ResultPointColor = Colors.Red
'Set the Camera IDs properly
qrReaderView.PreviewCameraId = 0
qrReaderView.setBackCamera()
qrReaderView.PreviewCameraId = 1
qrReaderView.setFrontCamera()
'Now always rear Camera first
qrReaderView.PreviewCameraId = 0
qrReaderView.setBackCamera()
End Sub
Private Sub StartQrCodeReader As Void
qrReaderView.Visible = True
qrReaderView.startCamera()
qrReaderView.ScanNow = True
End Sub
Private Sub StopQrCodeReader As Void
qrReaderView.stopCamera()
qrReaderView.ScanNow = False
qrReaderView.Visible = False
End Sub
Private Sub ExitScanLayout As Void
ExitScanLayoutInternal(False)
End Sub
Private Sub ExitScanLayoutInternal(NoActivityStart As Boolean) As Void
StopQrCodeReader
isBackCamera = True
isTorchOn = False
qrReaderView.TorchEnabled = isTorchOn
'Close this Activity once no longer needed
'
Activity.Finish()
'Return to the Main Android PIN Unblocker activity
'
If NoActivityStart == False Then
StartActivity(Main)
End If
End Sub
'
'UI event handlers
'
Private Sub qrReaderView_result_found(ReturnValue As String)
Dim shareIntent As Intent
shareIntent.Initialize(shareIntent.ACTION_SEND, "")
shareIntent.SetPackage("net.generic.smartcardpuk")
shareIntent.SetType("text/plain")
shareIntent.PutExtra("android.intent.extra.CHALLENGE_CODE", ReturnValue)
StartActivity(shareIntent)
ExitScanLayoutInternal(True)
End Sub
Private Sub btnToggleFlash_Click
isTorchOn = Not(isTorchOn)
qrReaderView.TorchEnabled = isTorchOn
End Sub
Private Sub btnSwitchCam_Click
'Disabling the Flashlight when changing camera
isTorchOn = False
qrReaderView.TorchEnabled = isTorchOn
isBackCamera = Not(isBackCamera)
StopQrCodeReader
If isBackCamera Then
qrReaderView.PreviewCameraId = 0
qrReaderView.setBackCamera()
Else
qrReaderView.PreviewCameraId = 1
qrReaderView.setFrontCamera()
End If
StartQrCodeReader
End Sub
Private Sub btnBack_Click
ExitScanLayout
End Sub
'
'Unused code
'
Sub Process_Globals
End Sub