forked from journeyapps/zxing-android-embedded
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ContinuousCaptureActivity.java
83 lines (66 loc) · 2.28 KB
/
ContinuousCaptureActivity.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
package example.zxing;
import android.app.Activity;
import android.content.res.Configuration;
import android.graphics.Color;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.View;
import android.widget.ImageView;
import com.google.zxing.ResultPoint;
import com.journeyapps.barcodescanner.BarcodeCallback;
import com.journeyapps.barcodescanner.BarcodeResult;
import com.journeyapps.barcodescanner.CompoundBarcodeView;
import java.util.List;
/**
* This sample performs continuous scanning, displaying the barcode and source image whenever
* a barcode is scanned.
*/
public class ContinuousCaptureActivity extends Activity {
private static final String TAG = ContinuousCaptureActivity.class.getSimpleName();
private CompoundBarcodeView barcodeView;
private BarcodeCallback callback = new BarcodeCallback() {
@Override
public void barcodeResult(BarcodeResult result) {
if (result.getText() != null) {
barcodeView.setStatusText(result.getText());
}
//Added preview of scanned barcode
ImageView imageView = (ImageView) findViewById(R.id.barcodePreview);
imageView.setImageBitmap(result.getBitmapWithResultPoints(Color.YELLOW));
}
@Override
public void possibleResultPoints(List<ResultPoint> resultPoints) {
}
};
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.continuous_scan);
barcodeView = (CompoundBarcodeView) findViewById(R.id.barcode_scanner);
barcodeView.decodeContinuous(callback);
}
@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) {
return barcodeView.onKeyDown(keyCode, event) || super.onKeyDown(keyCode, event);
}
}