@@ -127,30 +127,38 @@ public void onFramePreview(CameraView cameraView, byte[] data, int width, int he
127127 int correctWidth = width ;
128128 int correctHeight = height ;
129129 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+
130138 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 );
134142 }
135- if (mShouldScanBarCodes && ! barCodeScannerTaskLock && cameraView instanceof BarCodeScannerAsyncTaskDelegate ) {
143+ if (willCallBarCodeTask ) {
136144 barCodeScannerTaskLock = true ;
137145 BarCodeScannerAsyncTaskDelegate delegate = (BarCodeScannerAsyncTaskDelegate ) cameraView ;
138146 new BarCodeScannerAsyncTask (delegate , mMultiFormatReader , correctData , correctWidth , correctHeight ).execute ();
139147 }
140148
141- if (mShouldDetectFaces && ! faceDetectorTaskLock && cameraView instanceof FaceDetectorAsyncTaskDelegate ) {
149+ if (willCallFaceTask ) {
142150 faceDetectorTaskLock = true ;
143151 FaceDetectorAsyncTaskDelegate delegate = (FaceDetectorAsyncTaskDelegate ) cameraView ;
144152 new FaceDetectorAsyncTask (delegate , mFaceDetector , correctData , correctWidth , correctHeight , correctRotation ).execute ();
145153 }
146154
147- if (mShouldGoogleDetectBarcodes && ! googleBarcodeDetectorTaskLock && cameraView instanceof BarcodeDetectorAsyncTaskDelegate ) {
155+ if (willCallGoogleBarcodeTask ) {
148156 googleBarcodeDetectorTaskLock = true ;
149157 BarcodeDetectorAsyncTaskDelegate delegate = (BarcodeDetectorAsyncTaskDelegate ) cameraView ;
150158 new BarcodeDetectorAsyncTask (delegate , mGoogleBarcodeDetector , correctData , correctWidth , correctHeight , correctRotation ).execute ();
151159 }
152160
153- if (mShouldRecognizeText && ! textRecognizerTaskLock && cameraView instanceof TextRecognizerAsyncTaskDelegate ) {
161+ if (willCallTextTask ) {
154162 textRecognizerTaskLock = true ;
155163 TextRecognizerAsyncTaskDelegate delegate = (TextRecognizerAsyncTaskDelegate ) cameraView ;
156164 new TextRecognizerAsyncTask (delegate , mTextRecognizer , correctData , correctWidth , correctHeight , correctRotation ).execute ();
0 commit comments