react-native-pdf417-scanner 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
package com.pdf417scanner;
|
|
2
2
|
|
|
3
|
+
import android.Manifest;
|
|
3
4
|
import android.content.Context;
|
|
5
|
+
import android.content.pm.PackageManager;
|
|
4
6
|
import android.graphics.SurfaceTexture;
|
|
5
7
|
import android.hardware.camera2.CameraAccessException;
|
|
6
8
|
import android.hardware.camera2.CameraCaptureSession;
|
|
@@ -18,6 +20,7 @@ import android.view.Surface;
|
|
|
18
20
|
import android.view.TextureView;
|
|
19
21
|
|
|
20
22
|
import androidx.annotation.NonNull;
|
|
23
|
+
import androidx.core.app.ActivityCompat;
|
|
21
24
|
|
|
22
25
|
import java.util.Arrays;
|
|
23
26
|
import java.util.concurrent.Semaphore;
|
|
@@ -70,6 +73,9 @@ public class PDF417CameraView extends TextureView implements TextureView.Surface
|
|
|
70
73
|
startBackgroundThread();
|
|
71
74
|
if (isAvailable()) {
|
|
72
75
|
openCamera(getWidth(), getHeight());
|
|
76
|
+
} else {
|
|
77
|
+
// Surface not ready yet, will be called from onSurfaceTextureAvailable
|
|
78
|
+
Log.d(TAG, "Surface texture not available yet, waiting...");
|
|
73
79
|
}
|
|
74
80
|
}
|
|
75
81
|
|
|
@@ -118,6 +124,15 @@ public class PDF417CameraView extends TextureView implements TextureView.Surface
|
|
|
118
124
|
|
|
119
125
|
private void openCamera(int width, int height) {
|
|
120
126
|
try {
|
|
127
|
+
// Check camera permission first
|
|
128
|
+
if (ActivityCompat.checkSelfPermission(getContext(), Manifest.permission.CAMERA)
|
|
129
|
+
!= PackageManager.PERMISSION_GRANTED) {
|
|
130
|
+
if (cameraReadyListener != null) {
|
|
131
|
+
cameraReadyListener.onCameraError("Camera permission not granted");
|
|
132
|
+
}
|
|
133
|
+
return;
|
|
134
|
+
}
|
|
135
|
+
|
|
121
136
|
if (!cameraOpenCloseLock.tryAcquire(2500, TimeUnit.MILLISECONDS)) {
|
|
122
137
|
throw new RuntimeException("Time out waiting to lock camera opening.");
|
|
123
138
|
}
|
|
@@ -193,6 +208,13 @@ public class PDF417CameraView extends TextureView implements TextureView.Surface
|
|
|
193
208
|
private void createCameraPreviewSession() {
|
|
194
209
|
try {
|
|
195
210
|
SurfaceTexture texture = getSurfaceTexture();
|
|
211
|
+
if (texture == null) {
|
|
212
|
+
if (cameraReadyListener != null) {
|
|
213
|
+
cameraReadyListener.onCameraError("Surface texture not available");
|
|
214
|
+
}
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
|
|
196
218
|
texture.setDefaultBufferSize(previewSize.getWidth(), previewSize.getHeight());
|
|
197
219
|
Surface surface = new Surface(texture);
|
|
198
220
|
|
|
@@ -215,7 +237,7 @@ public class PDF417CameraView extends TextureView implements TextureView.Surface
|
|
|
215
237
|
} catch (CameraAccessException e) {
|
|
216
238
|
Log.e(TAG, "Error starting camera preview", e);
|
|
217
239
|
if (cameraReadyListener != null) {
|
|
218
|
-
cameraReadyListener.onCameraError("Failed to start preview");
|
|
240
|
+
cameraReadyListener.onCameraError("Failed to start preview: " + e.getMessage());
|
|
219
241
|
}
|
|
220
242
|
}
|
|
221
243
|
}
|
|
@@ -230,7 +252,7 @@ public class PDF417CameraView extends TextureView implements TextureView.Surface
|
|
|
230
252
|
} catch (CameraAccessException e) {
|
|
231
253
|
Log.e(TAG, "Error creating camera preview session", e);
|
|
232
254
|
if (cameraReadyListener != null) {
|
|
233
|
-
cameraReadyListener.onCameraError("Failed to create preview session");
|
|
255
|
+
cameraReadyListener.onCameraError("Failed to create preview session: " + e.getMessage());
|
|
234
256
|
}
|
|
235
257
|
}
|
|
236
258
|
}
|