-
Notifications
You must be signed in to change notification settings - Fork 0
/
ClientBarcodeActivity.java
163 lines (139 loc) · 6.04 KB
/
ClientBarcodeActivity.java
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
package com.honeywell.barcodeexample;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import android.app.Activity;
import android.content.pm.ActivityInfo;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;
import android.widget.Toast;
import com.honeywell.aidc.*;
public class ClientBarcodeActivity extends Activity implements BarcodeReader.BarcodeListener,
BarcodeReader.TriggerListener {
private com.honeywell.aidc.BarcodeReader barcodeReader;
private ListView barcodeList;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_barcode);
// set lock the orientation
// otherwise, the onDestory will trigger when orientation changes
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
// get bar code instance from MainActivity
barcodeReader = MainActivity.getBarcodeObject();
if (barcodeReader != null) {
// register bar code event listener
barcodeReader.addBarcodeListener(this);
// set the trigger mode to client control
try {
barcodeReader.setProperty(BarcodeReader.PROPERTY_TRIGGER_CONTROL_MODE,
BarcodeReader.TRIGGER_CONTROL_MODE_CLIENT_CONTROL);
} catch (UnsupportedPropertyException e) {
Toast.makeText(this, "Failed to apply properties", Toast.LENGTH_SHORT).show();
}
// register trigger state change listener
barcodeReader.addTriggerListener(this);
Map<String, Object> properties = new HashMap<String, Object>();
// Set Symbologies On/Off
properties.put(BarcodeReader.PROPERTY_CODE_128_ENABLED, true);
properties.put(BarcodeReader.PROPERTY_GS1_128_ENABLED, true);
properties.put(BarcodeReader.PROPERTY_QR_CODE_ENABLED, true);
properties.put(BarcodeReader.PROPERTY_CODE_39_ENABLED, true);
properties.put(BarcodeReader.PROPERTY_DATAMATRIX_ENABLED, true);
properties.put(BarcodeReader.PROPERTY_UPC_A_ENABLE, true);
properties.put(BarcodeReader.PROPERTY_EAN_13_ENABLED, false);
properties.put(BarcodeReader.PROPERTY_AZTEC_ENABLED, false);
properties.put(BarcodeReader.PROPERTY_CODABAR_ENABLED, false);
properties.put(BarcodeReader.PROPERTY_INTERLEAVED_25_ENABLED, false);
properties.put(BarcodeReader.PROPERTY_PDF_417_ENABLED, false);
// Set Max Code 39 barcode length
properties.put(BarcodeReader.PROPERTY_CODE_39_MAXIMUM_LENGTH, 10);
// Turn on center decoding
properties.put(BarcodeReader.PROPERTY_CENTER_DECODE, true);
// Disable bad read response, handle in onFailureEvent
properties.put(BarcodeReader.PROPERTY_NOTIFICATION_BAD_READ_ENABLED, false);
// Apply the settings
barcodeReader.setProperties(properties);
}
// get initial list
barcodeList = (ListView) findViewById(R.id.listViewBarcodeData);
}
@Override
public void onBarcodeEvent(final BarcodeReadEvent event) {
runOnUiThread(new Runnable() {
@Override
public void run() {
// update UI to reflect the data
List<String> list = new ArrayList<String>();
list.add("Barcode data: " + event.getBarcodeData());
list.add("Character Set: " + event.getCharset());
list.add("Code ID: " + event.getCodeId());
list.add("AIM ID: " + event.getAimId());
list.add("Timestamp: " + event.getTimestamp());
final ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(
ClientBarcodeActivity.this, android.R.layout.simple_list_item_1, list);
barcodeList.setAdapter(dataAdapter);
}
});
}
// When using Automatic Trigger control do not need to implement the
// onTriggerEvent function
@Override
public void onTriggerEvent(TriggerStateChangeEvent event) {
try {
// only handle trigger presses
// turn on/off aimer, illumination and decoding
barcodeReader.aim(event.getState());
barcodeReader.light(event.getState());
barcodeReader.decode(event.getState());
} catch (ScannerNotClaimedException e) {
e.printStackTrace();
Toast.makeText(this, "Scanner is not claimed", Toast.LENGTH_SHORT).show();
} catch (ScannerUnavailableException e) {
e.printStackTrace();
Toast.makeText(this, "Scanner unavailable", Toast.LENGTH_SHORT).show();
}
}
@Override
public void onFailureEvent(BarcodeFailureEvent arg0) {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(ClientBarcodeActivity.this, "No data", Toast.LENGTH_SHORT).show();
}
});
}
@Override
public void onResume() {
super.onResume();
if (barcodeReader != null) {
try {
barcodeReader.claim();
} catch (ScannerUnavailableException e) {
e.printStackTrace();
Toast.makeText(this, "Scanner unavailable", Toast.LENGTH_SHORT).show();
}
}
}
@Override
public void onPause() {
super.onPause();
if (barcodeReader != null) {
// release the scanner claim so we don't get any scanner
// notifications while paused.
barcodeReader.release();
}
}
@Override
public void onDestroy() {
super.onDestroy();
if (barcodeReader != null) {
// unregister barcode event listener
barcodeReader.removeBarcodeListener(this);
// unregister trigger state change listener
barcodeReader.removeTriggerListener(this);
}
}
}