From e4c0be848306f1403b9074196b8644461217b35a Mon Sep 17 00:00:00 2001 From: althafvly Date: Tue, 21 Mar 2023 12:20:37 +0530 Subject: [PATCH] camera: Avoid aux camera changes for non-aux device --- .../sourceforge/opencamera/MainActivity.java | 91 ++++++++++++------- app/src/main/res/values/config.xml | 2 +- 2 files changed, 58 insertions(+), 35 deletions(-) diff --git a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java index b40d0f96c..fea761ff8 100644 --- a/app/src/main/java/net/sourceforge/opencamera/MainActivity.java +++ b/app/src/main/java/net/sourceforge/opencamera/MainActivity.java @@ -403,12 +403,14 @@ public class MainActivity extends AppCompatActivity { getWindow().setAttributes(layout); } - cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); - camerafinder = new CameraFinder(cameraManager); - cameraModel = camerafinder.getCameraModels(); - cameraIdentifier = new CameraIdentifier(cameraModel); - camerafinder.init(); - cameraIdentifier.init(); + if (getResources().getBoolean(R.bool.zoom_level_switch_supported)) { + cameraManager = (CameraManager) getSystemService(Context.CAMERA_SERVICE); + camerafinder = new CameraFinder(cameraManager); + cameraModel = camerafinder.getCameraModels(); + cameraIdentifier = new CameraIdentifier(cameraModel); + camerafinder.init(); + cameraIdentifier.init(); + } // Setup multi-camera buttons (must be done after creating preview so we know which Camera API is being used, // and before initialising on-screen visibility). @@ -422,40 +424,61 @@ public class MainActivity extends AppCompatActivity { int n_cameras = preview.getCameraControllerManager().getNumberOfCameras(); if (getResources().getBoolean(R.bool.zoom_level_switch_supported)) { n_cameras = camerafinder.getAllCameraIdList().size(); - } - if( n_cameras > 2 ) { - this.back_camera_ids = new ArrayList<>(); - this.front_camera_ids = new ArrayList<>(); - this.other_camera_ids = new ArrayList<>(); - this.logical_camera_ids = new ArrayList<>(); - - if (!cameraModel.isEmpty()) { - for (CameraModel model : cameraModel) { - if (model.getCameraType() == CameraType.LOGICAL) { - logical_camera_ids.add(model.getId()); + if( n_cameras > 2 ) { + this.back_camera_ids = new ArrayList<>(); + this.front_camera_ids = new ArrayList<>(); + this.other_camera_ids = new ArrayList<>(); + this.logical_camera_ids = new ArrayList<>(); + + if (!cameraModel.isEmpty()) { + for (CameraModel model : cameraModel) { + if (model.getCameraType() == CameraType.LOGICAL) { + logical_camera_ids.add(model.getId()); + } } } - } - for(String cameraId: camerafinder.getAllCameraIdList()) { - int id = Integer.parseInt(cameraId); - cameraCharacteristics = camerafinder.getCameraCharacteristics(id); - Integer facing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING); - if (!logical_camera_ids.contains(id) - || getResources().getBoolean(R.bool.allow_logical_camera_ids)) { - switch(facing) { - case CameraMetadata.LENS_FACING_BACK: - back_camera_ids.add(id); - break; - case CameraMetadata.LENS_FACING_FRONT: - front_camera_ids.add(id); - break; - case CameraMetadata.LENS_FACING_EXTERNAL: - other_camera_ids.add(id); - break; + for(String cameraId: camerafinder.getAllCameraIdList()) { + int id = Integer.parseInt(cameraId); + cameraCharacteristics = camerafinder.getCameraCharacteristics(id); + Integer facing = cameraCharacteristics.get(CameraCharacteristics.LENS_FACING); + if (!logical_camera_ids.contains(id) + || getResources().getBoolean(R.bool.allow_logical_camera_ids)) { + switch(facing) { + case CameraMetadata.LENS_FACING_BACK: + back_camera_ids.add(id); + break; + case CameraMetadata.LENS_FACING_FRONT: + front_camera_ids.add(id); + break; + case CameraMetadata.LENS_FACING_EXTERNAL: + other_camera_ids.add(id); + break; + } } } } + } else if (n_cameras > 2) { + this.back_camera_ids = new ArrayList<>(); + this.front_camera_ids = new ArrayList<>(); + this.other_camera_ids = new ArrayList<>(); + for (int i = 0; i < n_cameras; i++) { + switch (preview.getCameraControllerManager().getFacing(i)) { + case FACING_BACK: + back_camera_ids.add(i); + break; + case FACING_FRONT: + front_camera_ids.add(i); + break; + default: + // we assume any unknown cameras are also external + other_camera_ids.add(i); + break; + } + } + } + + if (n_cameras > 2) { if( MyDebug.LOG ) { Log.d(TAG, "back_camera_ids: " + back_camera_ids); Log.d(TAG, "front_camera_ids: " + front_camera_ids); diff --git a/app/src/main/res/values/config.xml b/app/src/main/res/values/config.xml index 1ea0bb403..8a88dcd24 100644 --- a/app/src/main/res/values/config.xml +++ b/app/src/main/res/values/config.xml @@ -1,7 +1,7 @@ false - false + true