capacitor-community-multilens-camerapreview 7.1.5 → 7.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.
@@ -2,12 +2,13 @@ package com.ahm.capacitor.camera.preview;
2
2
 
3
3
  import static android.Manifest.permission.CAMERA;
4
4
 
5
+ import android.annotation.SuppressLint;
5
6
  import android.app.FragmentManager;
6
7
  import android.app.FragmentTransaction;
7
8
  import android.content.pm.ActivityInfo;
8
9
  import android.graphics.Color;
9
10
  import android.graphics.Point;
10
- import android.hardware.Camera;
11
+
11
12
  import android.content.Context;
12
13
  import android.hardware.camera2.*;
13
14
  import android.hardware.camera2.params.OutputConfiguration;
@@ -86,7 +87,7 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
86
87
 
87
88
  @PluginMethod
88
89
  public void setOpacity(PluginCall call) {
89
- if (this.hasCamera(call) == false) {
90
+ if (this.hasView(call) == false) {
90
91
  //call.error("Camera is not running");
91
92
  return;
92
93
  }
@@ -98,7 +99,7 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
98
99
 
99
100
  @PluginMethod
100
101
  public void capture(PluginCall call) {
101
- if (this.hasCamera(call) == false) {
102
+ if (this.hasView(call) == false) {
102
103
  call.reject("Camera is not running");
103
104
  return;
104
105
  }
@@ -114,7 +115,7 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
114
115
 
115
116
  @PluginMethod
116
117
  public void captureSample(PluginCall call) {
117
- if (this.hasCamera(call) == false) {
118
+ if (this.hasView(call) == false) {
118
119
  call.reject("Camera is not running");
119
120
  return;
120
121
  }
@@ -131,6 +132,7 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
131
132
  .getActivity()
132
133
  .runOnUiThread(
133
134
  new Runnable() {
135
+ @SuppressLint("WrongConstant")
134
136
  @Override
135
137
  public void run() {
136
138
  FrameLayout containerView = getBridge().getActivity().findViewById(containerViewId);
@@ -158,61 +160,71 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
158
160
 
159
161
  @PluginMethod
160
162
  public void getSupportedFlashModes(PluginCall call) {
161
- if (this.hasCamera(call) == false) {
163
+ if (this.hasView(call) == false) {
162
164
  call.reject("Camera is not running");
163
165
  return;
164
166
  }
165
167
 
166
- Camera camera = fragment.getCamera();
167
- Camera.Parameters params = camera.getParameters();
168
- List<String> supportedFlashModes;
169
- supportedFlashModes = params.getSupportedFlashModes();
170
- JSONArray jsonFlashModes = new JSONArray();
171
-
172
- if (supportedFlashModes != null) {
173
- for (int i = 0; i < supportedFlashModes.size(); i++) {
174
- jsonFlashModes.put(new String(supportedFlashModes.get(i)));
168
+ try {
169
+ CameraManager cameraManager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
170
+ String cameraId = fragment.getCameraId();
171
+ CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
172
+ Boolean flashAvailable = characteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE);
173
+ JSONArray jsonFlashModes = new JSONArray();
174
+ if (flashAvailable) {
175
+ jsonFlashModes.put("on");
176
+ jsonFlashModes.put("off");
177
+ jsonFlashModes.put("auto");
175
178
  }
179
+ JSObject jsObject = new JSObject();
180
+ jsObject.put("result", jsonFlashModes);
181
+ call.resolve(jsObject);
182
+ } catch (CameraAccessException e) {
183
+ call.reject("Failed to get flash modes");
176
184
  }
177
-
178
- JSObject jsObject = new JSObject();
179
- jsObject.put("result", jsonFlashModes);
180
- call.resolve(jsObject);
181
185
  }
186
+
182
187
  @PluginMethod
183
188
  public void getSupportedZoomLevels(PluginCall call) {
189
+ if (this.hasView(call) == false) {
190
+ call.reject("Camera is not running");
191
+ return;
192
+ }
184
193
 
185
194
  try {
195
+ CameraManager cameraManager = (CameraManager) getContext().getSystemService(Context.CAMERA_SERVICE);
196
+ String cameraId = fragment.getCameraId();
197
+ CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
198
+ Float maxZoom = characteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM);
199
+
186
200
  JSONArray jsonZoomLevels = new JSONArray();
187
- Context context = getContext();
188
- CameraManager cameraManager = (CameraManager)context.getSystemService(Context.CAMERA_SERVICE);
189
- String[] cameraIdList = cameraManager.getCameraIdList(); // may be empty
190
- // iterate over available camera devices
191
- for (String cameraId : cameraIdList) {
192
- CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
193
- Set<String> physicalIds = characteristics.getPhysicalCameraIds();
194
- System.out.println(physicalIds);
195
- for(String id : physicalIds){
196
- jsonZoomLevels.put(id);
201
+ if (maxZoom != null) {
202
+ for (int i = 1; i <= (int) (maxZoom * 10); i++) {
203
+ jsonZoomLevels.put(i * 10);
197
204
  }
198
205
  }
199
206
  JSObject jsObject = new JSObject();
200
207
  jsObject.put("result", jsonZoomLevels);
201
208
  call.resolve(jsObject);
202
209
  } catch (CameraAccessException e) {
203
- call.reject("Can't get Camera Id's");
210
+ call.reject("Failed to get zoom levels");
204
211
  }
205
212
  }
213
+
206
214
  @PluginMethod
207
215
  public void setZoom(PluginCall call) {
216
+ if (this.hasView(call) == false) {
217
+ call.reject("Camera is not running");
218
+ return;
219
+ }
208
220
  int zoomFactor = call.getInt("zoomFactor", 0);
209
- //this does nothing in android
221
+ fragment.setZoom(zoomFactor);
210
222
  call.resolve();
211
223
  }
212
224
 
213
225
  @PluginMethod
214
226
  public void setFlashMode(PluginCall call) {
215
- if (this.hasCamera(call) == false) {
227
+ if (this.hasView(call) == false) {
216
228
  call.reject("Camera is not running");
217
229
  return;
218
230
  }
@@ -223,39 +235,24 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
223
235
  return;
224
236
  }
225
237
 
226
- Camera camera = fragment.getCamera();
227
- Camera.Parameters params = camera.getParameters();
228
-
229
- List<String> supportedFlashModes;
230
- supportedFlashModes = camera.getParameters().getSupportedFlashModes();
231
- if (supportedFlashModes.indexOf(flashMode) > -1) {
232
- params.setFlashMode(flashMode);
233
- } else {
234
- call.reject("Flash mode not recognised: " + flashMode);
235
- return;
236
- }
237
-
238
- fragment.setCameraParameters(params);
238
+ fragment.setFlashMode(flashMode);
239
239
 
240
240
  call.resolve();
241
241
  }
242
242
 
243
243
  @PluginMethod
244
244
  public void startRecordVideo(final PluginCall call) {
245
- if (this.hasCamera(call) == false) {
245
+ if (this.hasView(call) == false) {
246
246
  call.reject("Camera is not running");
247
247
  return;
248
248
  }
249
249
  final String filename = "videoTmp";
250
250
  VIDEO_FILE_PATH = getActivity().getCacheDir().toString() + "/";
251
251
 
252
- final String position = call.getString("position", "front");
253
- final Integer width = call.getInt("width", 0);
254
- final Integer height = call.getInt("height", 0);
252
+ final int quality = call.getInt("quality", 70);
255
253
  final Boolean withFlash = call.getBoolean("withFlash", false);
256
254
  final Integer maxDuration = call.getInt("maxDuration", 0);
257
- final String lens = call.getString("zoomFactor", "0");
258
- // final Integer quality = call.getInt("quality", 0);
255
+
259
256
  bridge.saveCall(call);
260
257
  recordCallbackId = call.getCallbackId();
261
258
 
@@ -265,8 +262,7 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
265
262
  new Runnable() {
266
263
  @Override
267
264
  public void run() {
268
- // fragment.startRecord(getFilePath(filename), position, width, height, quality, withFlash);
269
- fragment.startRecord(getFilePath(filename), position, width, height, 70, withFlash, maxDuration, lens);
265
+ fragment.startRecord(getFilePath(filename), quality, withFlash, maxDuration);
270
266
  }
271
267
  }
272
268
  );
@@ -276,7 +272,7 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
276
272
 
277
273
  @PluginMethod
278
274
  public void stopRecordVideo(PluginCall call) {
279
- if (this.hasCamera(call) == false) {
275
+ if (this.hasView(call) == false) {
280
276
  call.reject("Camera is not running");
281
277
  return;
282
278
  }
@@ -515,17 +511,7 @@ public class CameraPreviewMultiLens extends Plugin implements CameraActivity.Cam
515
511
  return true;
516
512
  }
517
513
 
518
- private boolean hasCamera(PluginCall call) {
519
- if (this.hasView(call) == false) {
520
- return false;
521
- }
522
-
523
- if (fragment.getCamera() == null) {
524
- return false;
525
- }
526
514
 
527
- return true;
528
- }
529
515
 
530
516
  private String getFilePath(String filename) {
531
517
  String fileName = filename;
@@ -383,4 +383,8 @@ class Preview extends RelativeLayout implements SurfaceHolder.Callback, TextureV
383
383
  mTextureView.setAlpha(opacity);
384
384
  }
385
385
  }
386
+
387
+ public Surface getSurface() {
388
+ return null;
389
+ }
386
390
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-community-multilens-camerapreview",
3
- "version": "7.1.5",
3
+ "version": "7.1.7",
4
4
  "description": "fork of capacitor community camera preview with support for switchting lenses",
5
5
  "main": "dist/plugin.cjs.js",
6
6
  "module": "dist/esm/index.js",