capacitor-community-multilens-camerapreview 0.0.2 → 0.0.3

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.graphics.YuvImage;
16
16
  import android.hardware.Camera;
17
17
  import android.hardware.Camera.PictureCallback;
18
18
  import android.hardware.Camera.ShutterCallback;
19
+ import android.hardware.camera2.CameraManager;
19
20
  import android.media.AudioManager;
20
21
  import android.media.CamcorderProfile;
21
22
  import android.media.MediaRecorder;
@@ -480,7 +481,6 @@ public class CameraActivity extends Fragment {
480
481
  }
481
482
  }
482
483
 
483
-
484
484
  public void setCameraParameters(Camera.Parameters params) {
485
485
  cameraParameters = params;
486
486
 
@@ -8,8 +8,9 @@ import android.content.pm.ActivityInfo;
8
8
  import android.graphics.Color;
9
9
  import android.graphics.Point;
10
10
  import android.hardware.Camera;
11
- import android.hardware.camera2.CameraAccessException;
12
- import android.hardware.camera2.CameraManager;
11
+ import android.content.Context;
12
+ import android.hardware.camera2.*;
13
+ import android.hardware.camera2.params.OutputConfiguration;
13
14
  import android.util.DisplayMetrics;
14
15
  import android.util.TypedValue;
15
16
  import android.view.Display;
@@ -28,6 +29,7 @@ import com.getcapacitor.annotation.Permission;
28
29
  import com.getcapacitor.annotation.PermissionCallback;
29
30
  import java.io.File;
30
31
  import java.util.List;
32
+ import java.util.Set;
31
33
  import org.json.JSONArray;
32
34
 
33
35
  @CapacitorPlugin(name = "CameraPreview", permissions = { @Permission(strings = { CAMERA }, alias = CameraPreview.CAMERA_PERMISSION_ALIAS) })
@@ -176,28 +178,33 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
176
178
  }
177
179
  @PluginMethod
178
180
  public void getSupportedZoomLevels(PluginCall call) {
179
- if (this.hasCamera(call) == false) {
180
- call.reject("Camera is not running");
181
- return;
182
- }
183
- Camera camera = fragment.getCamera();
184
- Camera.Parameters params = camera.getParameters();
185
- Boolean zoomSupported = params.isZoomSupported();
186
- List<Integer> ZoomLevels;
187
- JSONArray jsonZoomLevels = new JSONArray();
188
- if(zoomSupported){
189
- ZoomLevels = params.getZoomRatios();
190
- for (int i = 0; i < ZoomLevels.size(); i++) {
191
- if(i == 0){
192
- zoomLevel = ZoomLevels.get(i);
181
+
182
+ try {
183
+ JSONArray jsonZoomLevels = new JSONArray();
184
+ Context context = getContext();
185
+ CameraManager cameraManager = (CameraManager)context.getSystemService(Context.CAMERA_SERVICE);
186
+ String[] cameraIdList = cameraManager.getCameraIdList(); // may be empty
187
+ // iterate over available camera devices
188
+ for (String cameraId : cameraIdList) {
189
+ CameraCharacteristics characteristics = cameraManager.getCameraCharacteristics(cameraId);
190
+ Set<String> physicalIds = characteristics.getPhysicalCameraIds();
191
+ System.out.println(physicalIds);
192
+ for(String id : physicalIds){
193
+ jsonZoomLevels.put(id);
193
194
  }
194
- jsonZoomLevels.put(new String(String.valueOf(ZoomLevels.get(i))));
195
195
  }
196
+ JSObject jsObject = new JSObject();
197
+ jsObject.put("result", jsonZoomLevels);
198
+ call.resolve(jsObject);
199
+ } catch (CameraAccessException e) {
200
+ call.reject("Can't get Camera Id's");
196
201
  }
197
-
198
- JSObject jsObject = new JSObject();
199
- jsObject.put("result", jsonZoomLevels);
200
- call.resolve(jsObject);
202
+ }
203
+ @PluginMethod
204
+ public void setZoom(PluginCall call) {
205
+ int zoomFactor = call.getInt("zoomFactor", 0);
206
+ //this does nothing in android
207
+ call.resolve();
201
208
  }
202
209
 
203
210
  @PluginMethod
@@ -296,18 +303,11 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
296
303
  call.reject("Permission failed: user denied access to camera.");
297
304
  }
298
305
  }
299
-
300
- public static void setZoom(int zoomLevel) {
301
- Camera Cam = fragment.getCamera();
302
- Camera.Parameters params = Cam.getParameters();
303
- if(params.isZoomSupported()){
304
- params.setZoom(zoomLevel);
305
- }
306
- }
306
+
307
307
 
308
308
  private void startCamera(final PluginCall call) {
309
309
  String position = call.getString("position");
310
- int zoomFactor = call.getInt("zoomFactor", 100);
310
+ //int zoomFactor = call.getInt("zoomFactor", 0);
311
311
 
312
312
  if (position == null || position.isEmpty() || "rear".equals(position)) {
313
313
  position = "back";
@@ -339,7 +339,6 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
339
339
  fragment.toBack = toBack;
340
340
  fragment.enableOpacity = enableOpacity;
341
341
  fragment.enableZoom = enableZoom;
342
- zoomLevel = zoomFactor;
343
342
  bridge
344
343
  .getActivity()
345
344
  .runOnUiThread(
@@ -467,8 +466,6 @@ public class CameraPreview extends Plugin implements CameraActivity.CameraPrevie
467
466
  PluginCall pluginCall = bridge.getSavedCall(cameraStartCallbackId);
468
467
  pluginCall.resolve();
469
468
  bridge.releaseCall(pluginCall);
470
-
471
- setZoom(zoomLevel);
472
469
  }
473
470
 
474
471
  @Override
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "capacitor-community-multilens-camerapreview",
3
- "version": "0.0.2",
3
+ "version": "0.0.3",
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",