forked from react-native-camera/react-native-camera
-
Notifications
You must be signed in to change notification settings - Fork 12
Expand file tree
/
Copy pathCameraViewManager.java
More file actions
248 lines (206 loc) · 8 KB
/
Copy pathCameraViewManager.java
File metadata and controls
248 lines (206 loc) · 8 KB
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
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
package org.reactnative.camera;
import androidx.annotation.Nullable;
import com.facebook.react.bridge.ReadableArray;
import com.facebook.react.bridge.ReadableMap;
import com.facebook.react.common.MapBuilder;
import com.facebook.react.uimanager.ThemedReactContext;
import com.facebook.react.uimanager.ViewGroupManager;
import com.facebook.react.uimanager.annotations.ReactProp;
import com.google.android.cameraview.AspectRatio;
import com.google.android.cameraview.Size;
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
public class CameraViewManager extends ViewGroupManager<RNCameraView> {
public enum Events {
EVENT_CAMERA_READY("onCameraReady"),
EVENT_ON_MOUNT_ERROR("onMountError"),
EVENT_ON_BAR_CODE_READ("onBarCodeRead"),
EVENT_ON_FACES_DETECTED("onFacesDetected"),
EVENT_ON_BARCODES_DETECTED("onGoogleVisionBarcodesDetected"),
EVENT_ON_LABELS_DETECTED("onLabelsDetected"),
EVENT_ON_FACE_DETECTION_ERROR("onFaceDetectionError"),
EVENT_ON_BARCODE_DETECTION_ERROR("onGoogleVisionBarcodeDetectionError"),
EVENT_ON_LABEL_DETECTION_ERROR("onLabelDetectionError"),
EVENT_ON_TEXT_RECOGNIZED("onTextRecognized"),
EVENT_ON_PICTURE_TAKEN("onPictureTaken"),
EVENT_ON_PICTURE_SAVED("onPictureSaved"),
EVENT_ON_RECORDING_START("onRecordingStart"),
EVENT_ON_RECORDING_END("onRecordingEnd"),
EVENT_ON_TOUCH("onTouch");
private final String mName;
Events(final String name) {
mName = name;
}
@Override
public String toString() {
return mName;
}
}
private static final String REACT_CLASS = "RNCamera";
@Override
public void onDropViewInstance(RNCameraView view) {
view.onHostDestroy();
super.onDropViewInstance(view);
}
@Override
public String getName() {
return REACT_CLASS;
}
@Override
protected RNCameraView createViewInstance(ThemedReactContext themedReactContext) {
return new RNCameraView(themedReactContext);
}
@Override
@Nullable
public Map<String, Object> getExportedCustomDirectEventTypeConstants() {
MapBuilder.Builder<String, Object> builder = MapBuilder.builder();
for (Events event : Events.values()) {
builder.put(event.toString(), MapBuilder.of("registrationName", event.toString()));
}
return builder.build();
}
@ReactProp(name = "type")
public void setType(RNCameraView view, int type) {
view.setFacing(type);
}
@ReactProp(name = "cameraId")
public void setCameraId(RNCameraView view, String id) {
view.setCameraId(id);
}
@ReactProp(name = "ratio")
public void setRatio(RNCameraView view, String ratio) {
view.setAspectRatio(AspectRatio.parse(ratio));
}
@ReactProp(name = "flashMode")
public void setFlashMode(RNCameraView view, int torchMode) {
view.setFlash(torchMode);
}
@ReactProp(name = "exposure")
public void setExposureCompensation(RNCameraView view, float exposure){
view.setExposureCompensation(exposure);
}
@ReactProp(name = "autoFocus")
public void setAutoFocus(RNCameraView view, boolean autoFocus) {
view.setAutoFocus(autoFocus);
}
@ReactProp(name = "focusDepth")
public void setFocusDepth(RNCameraView view, float depth) {
view.setFocusDepth(depth);
}
@ReactProp(name = "autoFocusPointOfInterest")
public void setAutoFocusPointOfInterest(RNCameraView view, ReadableMap coordinates) {
if(coordinates != null){
float x = (float) coordinates.getDouble("x");
float y = (float) coordinates.getDouble("y");
view.setAutoFocusPointOfInterest(x, y);
}
}
@ReactProp(name = "zoom")
public void setZoom(RNCameraView view, float zoom) {
view.setZoom(zoom);
}
@ReactProp(name = "useNativeZoom")
public void setUseNativeZoom(RNCameraView view, boolean useNativeZoom) {
view.setUseNativeZoom(useNativeZoom);
}
@ReactProp(name = "whiteBalance")
public void setWhiteBalance(RNCameraView view, int whiteBalance) {
view.setWhiteBalance(whiteBalance);
}
@ReactProp(name = "pictureSize")
public void setPictureSize(RNCameraView view, String size) {
view.setPictureSize(size.equals("None") ? null : Size.parse(size));
}
@ReactProp(name = "playSoundOnCapture")
public void setPlaySoundOnCapture(RNCameraView view, boolean playSoundOnCapture) {
view.setPlaySoundOnCapture(playSoundOnCapture);
}
@ReactProp(name = "barCodeTypes")
public void setBarCodeTypes(RNCameraView view, ReadableArray barCodeTypes) {
if (barCodeTypes == null) {
return;
}
List<String> result = new ArrayList<>(barCodeTypes.size());
for (int i = 0; i < barCodeTypes.size(); i++) {
result.add(barCodeTypes.getString(i));
}
view.setBarCodeTypes(result);
}
@ReactProp(name = "detectedImageInEvent")
public void setDetectedImageInEvent(RNCameraView view, boolean detectedImageInEvent) {
view.setDetectedImageInEvent(detectedImageInEvent);
}
@ReactProp(name = "barCodeScannerEnabled")
public void setBarCodeScanning(RNCameraView view, boolean barCodeScannerEnabled) {
view.setShouldScanBarCodes(barCodeScannerEnabled);
}
@ReactProp(name = "useCamera2Api")
public void setUseCamera2Api(RNCameraView view, boolean useCamera2Api) {
view.setUsingCamera2Api(useCamera2Api);
}
@ReactProp(name = "touchDetectorEnabled")
public void setTouchDetectorEnabled(RNCameraView view, boolean touchDetectorEnabled) {
view.setShouldDetectTouches(touchDetectorEnabled);
}
@ReactProp(name = "faceDetectorEnabled")
public void setFaceDetecting(RNCameraView view, boolean faceDetectorEnabled) {
view.setShouldDetectFaces(faceDetectorEnabled);
}
@ReactProp(name = "faceDetectionMode")
public void setFaceDetectionMode(RNCameraView view, int mode) {
view.setFaceDetectionMode(mode);
}
@ReactProp(name = "faceDetectionLandmarks")
public void setFaceDetectionLandmarks(RNCameraView view, int landmarks) {
view.setFaceDetectionLandmarks(landmarks);
}
@ReactProp(name = "faceDetectionClassifications")
public void setFaceDetectionClassifications(RNCameraView view, int classifications) {
view.setFaceDetectionClassifications(classifications);
}
@ReactProp(name = "trackingEnabled")
public void setTracking(RNCameraView view, boolean trackingEnabled) {
view.setTracking(trackingEnabled);
}
@ReactProp(name = "googleVisionBarcodeDetectorEnabled")
public void setGoogleVisionBarcodeDetecting(RNCameraView view, boolean googleBarcodeDetectorEnabled) {
view.setShouldGoogleDetectBarcodes(googleBarcodeDetectorEnabled);
}
@ReactProp(name = "googleVisionBarcodeType")
public void setGoogleVisionBarcodeType(RNCameraView view, int barcodeType) {
view.setGoogleVisionBarcodeType(barcodeType);
}
@ReactProp(name = "googleVisionBarcodeMode")
public void setGoogleVisionBarcodeMode(RNCameraView view, int barcodeMode) {
view.setGoogleVisionBarcodeMode(barcodeMode);
}
@ReactProp(name = "textRecognizerEnabled")
public void setTextRecognizing(RNCameraView view, boolean textRecognizerEnabled) {
view.setShouldRecognizeText(textRecognizerEnabled);
}
@ReactProp(name = "labelDetectorEnabled")
public void setLabelDetecting(RNCameraView view, boolean labelDetectorEnabled) {
view.setShouldDetectLabels(labelDetectorEnabled);
}
/**---limit scan area addition---**/
@ReactProp(name = "rectOfInterest")
public void setRectOfInterest(RNCameraView view, ReadableMap coordinates) {
if(coordinates != null){
float x = (float) coordinates.getDouble("x");
float y = (float) coordinates.getDouble("y");
float width = (float) coordinates.getDouble("width");
float height = (float) coordinates.getDouble("height");
view.setRectOfInterest(x, y, width, height);
}
}
@ReactProp(name = "cameraViewDimensions")
public void setCameraViewDimensions(RNCameraView view, ReadableMap dimensions) {
if(dimensions != null){
int cameraViewWidth = (int) dimensions.getDouble("width");
int cameraViewHeight = (int) dimensions.getDouble("height");
view.setCameraViewDimensions(cameraViewWidth, cameraViewHeight);
}
}
/**---limit scan area addition---**/
}