@@ -127,30 +127,38 @@ public void onFramePreview(CameraView cameraView, byte[] data, int width, int he
127
127
int correctWidth = width ;
128
128
int correctHeight = height ;
129
129
byte [] correctData = data ;
130
+ boolean willCallBarCodeTask = mShouldScanBarCodes && !barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate ;
131
+ boolean willCallFaceTask = mShouldDetectFaces && !faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate ;
132
+ boolean willCallGoogleBarcodeTask = mShouldGoogleDetectBarcodes && !googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate ;
133
+ boolean willCallTextTask = mShouldRecognizeText && !textRecognizerTaskLock && cameraView instanceof TextRecognizerAsyncTaskDelegate ;
134
+ if (!willCallBarCodeTask && !willCallFaceTask && !willCallGoogleBarcodeTask && !willCallTextTask ) {
135
+ return ;
136
+ }
137
+
130
138
if (correctRotation == 90 ) {
131
- correctWidth = height ;
132
- correctHeight = width ;
133
- correctData = rotateImage (data , correctHeight , correctWidth );
139
+ correctWidth = height ;
140
+ correctHeight = width ;
141
+ correctData = rotateImage (data , correctHeight , correctWidth );
134
142
}
135
- if (mShouldScanBarCodes && ! barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate ) {
143
+ if (willCallBarCodeTask ) {
136
144
barCodeScannerTaskLock = true ;
137
145
BarCodeScannerAsyncTaskDelegate delegate = (BarCodeScannerAsyncTaskDelegate ) cameraView ;
138
146
new BarCodeScannerAsyncTask (delegate , mMultiFormatReader , correctData , correctWidth , correctHeight ).execute ();
139
147
}
140
148
141
- if (mShouldDetectFaces && ! faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate ) {
149
+ if (willCallFaceTask ) {
142
150
faceDetectorTaskLock = true ;
143
151
FaceDetectorAsyncTaskDelegate delegate = (FaceDetectorAsyncTaskDelegate ) cameraView ;
144
152
new FaceDetectorAsyncTask (delegate , mFaceDetector , correctData , correctWidth , correctHeight , correctRotation ).execute ();
145
153
}
146
154
147
- if (mShouldGoogleDetectBarcodes && ! googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate ) {
155
+ if (willCallGoogleBarcodeTask ) {
148
156
googleBarcodeDetectorTaskLock = true ;
149
157
BarcodeDetectorAsyncTaskDelegate delegate = (BarcodeDetectorAsyncTaskDelegate ) cameraView ;
150
158
new BarcodeDetectorAsyncTask (delegate , mGoogleBarcodeDetector , correctData , correctWidth , correctHeight , correctRotation ).execute ();
151
159
}
152
160
153
- if (mShouldRecognizeText && ! textRecognizerTaskLock && cameraView instanceof TextRecognizerAsyncTaskDelegate ) {
161
+ if (willCallTextTask ) {
154
162
textRecognizerTaskLock = true ;
155
163
TextRecognizerAsyncTaskDelegate delegate = (TextRecognizerAsyncTaskDelegate ) cameraView ;
156
164
new TextRecognizerAsyncTask (delegate , mTextRecognizer , correctData , correctWidth , correctHeight , correctRotation ).execute ();
0 commit comments