@capgo/camera-preview 6.1.5 → 6.1.7

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.
@@ -16,6 +16,7 @@ import android.view.MotionEvent;
16
16
  import android.view.View;
17
17
  import android.view.ViewGroup;
18
18
  import android.widget.FrameLayout;
19
+ import androidx.annotation.NonNull;
19
20
  import com.getcapacitor.JSObject;
20
21
  import com.getcapacitor.Logger;
21
22
  import com.getcapacitor.PermissionState;
@@ -27,6 +28,7 @@ import com.getcapacitor.annotation.Permission;
27
28
  import com.getcapacitor.annotation.PermissionCallback;
28
29
  import java.io.File;
29
30
  import java.util.List;
31
+ import java.util.Objects;
30
32
  import org.json.JSONArray;
31
33
 
32
34
  @CapacitorPlugin(
@@ -95,7 +97,7 @@ public class CameraPreview
95
97
  }
96
98
 
97
99
  bridge.saveCall(call);
98
- Float opacity = call.getFloat("opacity", 1F);
100
+ Float opacity = Objects.requireNonNull(call.getFloat("opacity", 1F));
99
101
  fragment.setOpacity(opacity);
100
102
  }
101
103
 
@@ -108,10 +110,10 @@ public class CameraPreview
108
110
  bridge.saveCall(call);
109
111
  captureCallbackId = call.getCallbackId();
110
112
 
111
- Integer quality = call.getInt("quality", 85);
113
+ Integer quality = Objects.requireNonNull(call.getInt("quality", 85));
112
114
  // Image Dimensions - Optional
113
- Integer width = call.getInt("width", 0);
114
- Integer height = call.getInt("height", 0);
115
+ Integer width = Objects.requireNonNull(call.getInt("width", 0));
116
+ Integer height = Objects.requireNonNull(call.getInt("height", 0));
115
117
  fragment.takePicture(width, height, quality);
116
118
  }
117
119
 
@@ -124,7 +126,7 @@ public class CameraPreview
124
126
  bridge.saveCall(call);
125
127
  snapshotCallbackId = call.getCallbackId();
126
128
 
127
- Integer quality = call.getInt("quality", 85);
129
+ Integer quality = Objects.requireNonNull(call.getInt("quality", 85));
128
130
  fragment.takeSnapshot(quality);
129
131
  }
130
132
 
@@ -182,7 +184,7 @@ public class CameraPreview
182
184
 
183
185
  if (supportedFlashModes != null) {
184
186
  for (int i = 0; i < supportedFlashModes.size(); i++) {
185
- jsonFlashModes.put(new String(supportedFlashModes.get(i)));
187
+ jsonFlashModes.put(supportedFlashModes.get(i));
186
188
  }
187
189
  }
188
190
 
@@ -216,7 +218,7 @@ public class CameraPreview
216
218
  }
217
219
 
218
220
  String flashMode = call.getString("flashMode");
219
- if (flashMode == null || flashMode.isEmpty() == true) {
221
+ if (flashMode == null || flashMode.isEmpty()) {
220
222
  call.reject("flashMode required parameter is missing");
221
223
  return;
222
224
  }
@@ -227,7 +229,7 @@ public class CameraPreview
227
229
  List<String> supportedFlashModes;
228
230
  supportedFlashModes = camera.getParameters().getSupportedFlashModes();
229
231
  if (
230
- supportedFlashModes != null && supportedFlashModes.indexOf(flashMode) > -1
232
+ supportedFlashModes != null && supportedFlashModes.contains(flashMode)
231
233
  ) {
232
234
  params.setFlashMode(flashMode);
233
235
  } else {
@@ -249,12 +251,18 @@ public class CameraPreview
249
251
  final String filename = "videoTmp";
250
252
  VIDEO_FILE_PATH = getActivity().getCacheDir().toString() + "/";
251
253
 
252
- final String position = call.getString("position", "front");
253
- final Integer width = call.getInt("width", 0);
254
- final Integer height = call.getInt("height", 0);
255
- final Boolean withFlash = call.getBoolean("withFlash", false);
256
- final Integer maxDuration = call.getInt("maxDuration", 0);
257
- // final Integer quality = call.getInt("quality", 0);
254
+ final String position = Objects.requireNonNull(
255
+ call.getString("position", "front")
256
+ );
257
+ final Integer width = Objects.requireNonNull(call.getInt("width", 0));
258
+ final Integer height = Objects.requireNonNull(call.getInt("height", 0));
259
+ final Boolean withFlash = Objects.requireNonNull(
260
+ call.getBoolean("withFlash", false)
261
+ );
262
+ final Integer maxDuration = Objects.requireNonNull(
263
+ call.getInt("maxDuration", 0)
264
+ );
265
+ // final Integer quality = Objects.requireNonNull(call.getInt("quality", 0));
258
266
  bridge.saveCall(call);
259
267
  recordCallbackId = call.getCallbackId();
260
268
 
@@ -264,9 +272,8 @@ public class CameraPreview
264
272
  new Runnable() {
265
273
  @Override
266
274
  public void run() {
267
- // fragment.startRecord(getFilePath(filename), position, width, height, quality, withFlash);
268
275
  fragment.startRecord(
269
- getFilePath(filename),
276
+ getFilePath(),
270
277
  position,
271
278
  width,
272
279
  height,
@@ -331,22 +338,35 @@ public class CameraPreview
331
338
  position = "front";
332
339
  }
333
340
 
334
- final Integer x = call.getInt("x", 0);
335
- final Integer y = call.getInt("y", 0);
336
- final Integer width = call.getInt("width", 0);
337
- final Integer height = call.getInt("height", 0);
338
- final Integer paddingBottom = call.getInt("paddingBottom", 0);
339
- final Boolean toBack = call.getBoolean("toBack", false);
340
- final Boolean storeToFile = call.getBoolean("storeToFile", false);
341
- final Boolean enableOpacity = call.getBoolean("enableOpacity", false);
342
- final Boolean enableZoom = call.getBoolean("enableZoom", false);
343
- final Boolean disableExifHeaderStripping = call.getBoolean(
344
- "disableExifHeaderStripping",
345
- true
341
+ @NonNull
342
+ final Integer x = Objects.requireNonNull(call.getInt("x", 0));
343
+ @NonNull
344
+ final Integer y = Objects.requireNonNull(call.getInt("y", 0));
345
+ @NonNull
346
+ final Integer width = Objects.requireNonNull(call.getInt("width", 0));
347
+ @NonNull
348
+ final Integer height = Objects.requireNonNull(call.getInt("height", 0));
349
+ @NonNull
350
+ final Integer paddingBottom = Objects.requireNonNull(
351
+ call.getInt("paddingBottom", 0)
352
+ );
353
+ final Boolean toBack = Objects.requireNonNull(
354
+ call.getBoolean("toBack", false)
355
+ );
356
+ final Boolean storeToFile = Objects.requireNonNull(
357
+ call.getBoolean("storeToFile", false)
358
+ );
359
+ final Boolean enableOpacity = Objects.requireNonNull(
360
+ call.getBoolean("enableOpacity", false)
361
+ );
362
+ final Boolean enableZoom = Objects.requireNonNull(
363
+ call.getBoolean("enableZoom", false)
364
+ );
365
+ final Boolean disableExifHeaderStripping = Objects.requireNonNull(
366
+ call.getBoolean("disableExifHeaderStripping", false)
346
367
  );
347
- final Boolean lockOrientation = call.getBoolean(
348
- "lockAndroidOrientation",
349
- false
368
+ final Boolean lockOrientation = Objects.requireNonNull(
369
+ call.getBoolean("lockAndroidOrientation", false)
350
370
  );
351
371
  previousOrientationRequest = getBridge()
352
372
  .getActivity()
@@ -474,7 +494,7 @@ public class CameraPreview
474
494
  ((ViewGroup) getBridge().getWebView().getParent()).addView(
475
495
  containerView
476
496
  );
477
- if (toBack == true) {
497
+ if (toBack) {
478
498
  getBridge()
479
499
  .getWebView()
480
500
  .getParent()
@@ -581,7 +601,7 @@ public class CameraPreview
581
601
  }
582
602
 
583
603
  private boolean hasCamera(PluginCall call) {
584
- if (this.hasView(call) == false) {
604
+ if (!this.hasView(call)) {
585
605
  return false;
586
606
  }
587
607
 
@@ -592,8 +612,8 @@ public class CameraPreview
592
612
  return true;
593
613
  }
594
614
 
595
- private String getFilePath(String filename) {
596
- String fileName = filename;
615
+ private String getFilePath() {
616
+ String fileName = "videoTmp";
597
617
 
598
618
  int i = 1;
599
619
 
@@ -601,7 +621,7 @@ public class CameraPreview
601
621
  new File(VIDEO_FILE_PATH + fileName + VIDEO_FILE_EXTENSION).exists()
602
622
  ) {
603
623
  // Add number suffix if file exists
604
- fileName = filename + '_' + i;
624
+ fileName = "videoTmp" + '_' + i;
605
625
  i++;
606
626
  }
607
627
 
@@ -3,6 +3,7 @@ package com.ahm.capacitor.camera.preview;
3
3
  import android.content.Context;
4
4
  import android.view.SurfaceHolder;
5
5
  import android.view.SurfaceView;
6
+ import androidx.annotation.NonNull;
6
7
 
7
8
  class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
8
9
 
@@ -13,16 +14,16 @@ class CustomSurfaceView extends SurfaceView implements SurfaceHolder.Callback {
13
14
  }
14
15
 
15
16
  @Override
16
- public void surfaceCreated(SurfaceHolder holder) {}
17
+ public void surfaceCreated(@NonNull SurfaceHolder holder) {}
17
18
 
18
19
  @Override
19
20
  public void surfaceChanged(
20
- SurfaceHolder holder,
21
+ @NonNull SurfaceHolder holder,
21
22
  int format,
22
23
  int width,
23
24
  int height
24
25
  ) {}
25
26
 
26
27
  @Override
27
- public void surfaceDestroyed(SurfaceHolder holder) {}
28
+ public void surfaceDestroyed(@NonNull SurfaceHolder holder) {}
28
29
  }
@@ -2,8 +2,8 @@ package com.ahm.capacitor.camera.preview;
2
2
 
3
3
  import android.content.Context;
4
4
  import android.graphics.SurfaceTexture;
5
- import android.view.SurfaceHolder;
6
5
  import android.view.TextureView;
6
+ import androidx.annotation.NonNull;
7
7
 
8
8
  class CustomTextureView
9
9
  extends TextureView
@@ -17,23 +17,23 @@ class CustomTextureView
17
17
 
18
18
  @Override
19
19
  public void onSurfaceTextureAvailable(
20
- SurfaceTexture surface,
20
+ @NonNull SurfaceTexture surface,
21
21
  int width,
22
22
  int height
23
23
  ) {}
24
24
 
25
25
  @Override
26
26
  public void onSurfaceTextureSizeChanged(
27
- SurfaceTexture surface,
27
+ @NonNull SurfaceTexture surface,
28
28
  int width,
29
29
  int height
30
30
  ) {}
31
31
 
32
32
  @Override
33
- public boolean onSurfaceTextureDestroyed(SurfaceTexture surface) {
33
+ public boolean onSurfaceTextureDestroyed(@NonNull SurfaceTexture surface) {
34
34
  return true;
35
35
  }
36
36
 
37
37
  @Override
38
- public void onSurfaceTextureUpdated(SurfaceTexture surface) {}
38
+ public void onSurfaceTextureUpdated(@NonNull SurfaceTexture surface) {}
39
39
  }
@@ -85,6 +85,12 @@ class Preview
85
85
  params.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
86
86
  }
87
87
  mCamera.setParameters(params);
88
+ } else {
89
+ // Release the camera and set it to null when the camera parameter is null
90
+ if (mCamera != null) {
91
+ mCamera.release();
92
+ mCamera = null;
93
+ }
88
94
  }
89
95
  }
90
96
 
@@ -358,6 +364,14 @@ class Preview
358
364
  }
359
365
 
360
366
  public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
367
+ Log.d(
368
+ TAG,
369
+ "Preview size in surfaceChanged: " +
370
+ mPreviewSize.width +
371
+ "x" +
372
+ mPreviewSize.height
373
+ );
374
+
361
375
  if (mCamera != null) {
362
376
  try {
363
377
  // Now that the size is known, set up the camera parameters and begin