-
Notifications
You must be signed in to change notification settings - Fork 0
/
ScanButton.java
76 lines (59 loc) · 2.18 KB
/
ScanButton.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
package com.example.customBarcodeScanner.barcodeScanner.customView;
import android.content.Context;
import android.util.AttributeSet;
import android.widget.Button;
import android.widget.LinearLayout;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;
import com.example.customBarcodeScanner.R;
import com.example.customBarcodeScanner.barcodeScanner.captureActivity.ScanCapture;
import com.example.customBarcodeScanner.barcodeScanner.shared.ScanConstants;
import com.google.zxing.integration.android.IntentIntegrator;
public class ScanButton extends LinearLayout {
private Scan scan;
public ScanButton(Context context) {
super(context);
init();
}
public ScanButton(Context context, @Nullable AttributeSet attrs) {
super(context, attrs);
init();
}
public ScanButton(Context context, @Nullable AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init();
}
public ScanButton(Context context, AttributeSet attrs, int defStyleAttr, int defStyleRes) {
super(context, attrs, defStyleAttr, defStyleRes);
init();
}
public void init() {
inflate(getContext(), R.layout.scan_button, this);
}
@Override
protected void onFinishInflate() {
super.onFinishInflate();
Button scan = findViewById(R.id.scan_button);
scan.setOnClickListener(v -> onScanClick());
}
private void onScanClick() {
if (scan == null) {
throw new UnsupportedOperationException("Please implement Scan interface");
}
IntentIntegrator result = IntentIntegrator.forSupportFragment(scan.getFragment());
result.addExtra(ScanConstants.IS_SCAN_CONTINUOUS, scan.isScanContinuous());
result.setPrompt("Start scanning")
.setOrientationLocked(true)
.setBeepEnabled(false)
.setBarcodeImageEnabled(false)
.setCaptureActivity(ScanCapture.class)
.initiateScan();
}
public void setScan(Scan scan) {
this.scan = scan;
}
public interface Scan {
Fragment getFragment();
boolean isScanContinuous();
}
}