blob: f61a7b059b0ec94027769a743ebad2ad1bdcb46a (
plain)
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
|
package example.zxing;
import android.app.Activity;
import android.content.res.Configuration;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.TextView;
import com.google.zxing.Result;
import com.google.zxing.ResultPoint;
import com.journeyapps.barcodescanner.BarcodeCallback;
import com.journeyapps.barcodescanner.BarcodeView;
import com.journeyapps.barcodescanner.ViewfinderView;
import java.util.List;
/**
*
*/
public class CustomCaptureActivity extends Activity {
private static final String TAG = CustomCaptureActivity.class.getSimpleName();
private BarcodeView barcodeView;
private ViewfinderView viewFinder;
private BarcodeCallback callback = new BarcodeCallback() {
@Override
public void barcodeResult(Result result) {
TextView text = (TextView)findViewById(R.id.zxing_barcode_status);
if(result.getText() != null) {
text.setText(result.getText());
}
}
@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {
for (ResultPoint point : resultPoints) {
viewFinder.addPossibleResultPoint(point);
}
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.new_custom_layout);
barcodeView = (BarcodeView) findViewById(R.id.zxing_barcode_surface);
barcodeView.decodeContinuous(callback);
viewFinder = (ViewfinderView)findViewById(R.id.zxing_viewfinder_view);
viewFinder.setCameraPreview(barcodeView);
}
@Override
public void onConfigurationChanged(Configuration newConfig) {
super.onConfigurationChanged(newConfig);
Log.d(TAG, "Configuration changed");
}
private void orientationChanged() {
barcodeView.pause();
barcodeView.resume();
}
@Override
protected void onResume() {
super.onResume();
barcodeView.resume();
}
@Override
protected void onPause() {
super.onPause();
barcodeView.pause();
}
public void pause(View view) {
barcodeView.pause();
}
public void resume(View view) {
barcodeView.resume();
}
public void triggerScan(View view) {
barcodeView.decodeSingle(callback);
}
@Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch (keyCode) {
case KeyEvent.KEYCODE_FOCUS:
case KeyEvent.KEYCODE_CAMERA:
// Handle these events so they don't launch the Camera app
return true;
// Use volume up/down to turn on light
case KeyEvent.KEYCODE_VOLUME_DOWN:
barcodeView.setTorch(false);
return true;
case KeyEvent.KEYCODE_VOLUME_UP:
barcodeView.setTorch(true);
return true;
}
return super.onKeyDown(keyCode, event);
}
}
|