-
Notifications
You must be signed in to change notification settings - Fork 3.5k
[camera_android] Fix camera android deprecation warning for CamcorderProfile.get() #3273
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
f584b49
ad16b36
a03ebbe
d109aab
f720424
caf0c38
fcee0e0
fce7935
95c3ce6
6d779be
1c2d40b
a9fd29a
f2bc33d
eae0d34
ff1c9bd
9e735a6
e89cb7b
cd1ffa4
b306ed8
0c6c156
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -57,7 +57,6 @@ | |
| import io.flutter.plugins.camera.features.resolution.ResolutionFeature; | ||
| import io.flutter.plugins.camera.features.resolution.ResolutionPreset; | ||
| import io.flutter.plugins.camera.features.sensororientation.DeviceOrientationManager; | ||
| import io.flutter.plugins.camera.features.sensororientation.SensorOrientationFeature; | ||
| import io.flutter.plugins.camera.features.zoomlevel.ZoomLevelFeature; | ||
| import io.flutter.plugins.camera.media.MediaRecorderBuilder; | ||
| import io.flutter.plugins.camera.types.CameraCaptureProperties; | ||
|
|
@@ -79,24 +78,6 @@ interface ErrorCallback { | |
| void onError(String errorCode, String errorMessage); | ||
| } | ||
|
|
||
| /** A mockable wrapper for CameraDevice calls. */ | ||
| interface CameraDeviceWrapper { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Had to move this interface to its own file because of a warning. |
||
| @NonNull | ||
| CaptureRequest.Builder createCaptureRequest(int templateType) throws CameraAccessException; | ||
|
|
||
| @TargetApi(VERSION_CODES.P) | ||
| void createCaptureSession(SessionConfiguration config) throws CameraAccessException; | ||
|
|
||
| @TargetApi(VERSION_CODES.LOLLIPOP) | ||
| void createCaptureSession( | ||
| @NonNull List<Surface> outputs, | ||
| @NonNull CameraCaptureSession.StateCallback callback, | ||
| @Nullable Handler handler) | ||
| throws CameraAccessException; | ||
|
|
||
| void close(); | ||
| } | ||
|
|
||
| class Camera | ||
| implements CameraCaptureCallback.CameraCaptureStateListener, | ||
| ImageReader.OnImageAvailableListener { | ||
|
|
@@ -239,7 +220,7 @@ public void onPrecapture() { | |
| * @param requestBuilder request builder to update. | ||
| */ | ||
| private void updateBuilderSettings(CaptureRequest.Builder requestBuilder) { | ||
| for (CameraFeature feature : cameraFeatures.getAllFeatures()) { | ||
| for (CameraFeature<?> feature : cameraFeatures.getAllFeatures()) { | ||
| Log.d(TAG, "Updating builder with feature: " + feature.getDebugName()); | ||
| feature.updateBuilder(requestBuilder); | ||
| } | ||
|
|
@@ -253,8 +234,7 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException { | |
| } | ||
|
|
||
| final PlatformChannel.DeviceOrientation lockedOrientation = | ||
| ((SensorOrientationFeature) cameraFeatures.getSensorOrientation()) | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .getLockedCaptureOrientation(); | ||
| cameraFeatures.getSensorOrientation().getLockedCaptureOrientation(); | ||
|
|
||
| MediaRecorderBuilder mediaRecorderBuilder; | ||
|
|
||
|
|
@@ -637,8 +617,7 @@ private void takePictureAfterPrecapture() { | |
|
|
||
| // Orientation. | ||
| final PlatformChannel.DeviceOrientation lockedOrientation = | ||
| ((SensorOrientationFeature) cameraFeatures.getSensorOrientation()) | ||
stuartmorgan-g marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| .getLockedCaptureOrientation(); | ||
| cameraFeatures.getSensorOrientation().getLockedCaptureOrientation(); | ||
| stillBuilder.set( | ||
| CaptureRequest.JPEG_ORIENTATION, | ||
| lockedOrientation == null | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package io.flutter.plugins.camera; | ||
|
|
||
| import android.annotation.TargetApi; | ||
| import android.hardware.camera2.CameraAccessException; | ||
| import android.hardware.camera2.CameraCaptureSession; | ||
| import android.hardware.camera2.CaptureRequest; | ||
| import android.hardware.camera2.params.SessionConfiguration; | ||
| import android.os.Build; | ||
| import android.os.Handler; | ||
| import android.view.Surface; | ||
| import androidx.annotation.NonNull; | ||
| import androidx.annotation.Nullable; | ||
| import java.util.List; | ||
|
|
||
| /** A mockable wrapper for CameraDevice calls. */ | ||
| interface CameraDeviceWrapper { | ||
| @NonNull | ||
| CaptureRequest.Builder createCaptureRequest(int templateType) throws CameraAccessException; | ||
|
|
||
| @TargetApi(Build.VERSION_CODES.P) | ||
| void createCaptureSession(SessionConfiguration config) throws CameraAccessException; | ||
|
|
||
| @TargetApi(Build.VERSION_CODES.LOLLIPOP) | ||
| void createCaptureSession( | ||
| @NonNull List<Surface> outputs, | ||
| @NonNull CameraCaptureSession.StateCallback callback, | ||
| @Nullable Handler handler) | ||
| throws CameraAccessException; | ||
|
|
||
| void close(); | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,139 @@ | ||
| // Copyright 2013 The Flutter Authors. All rights reserved. | ||
| // Use of this source code is governed by a BSD-style license that can be | ||
| // found in the LICENSE file. | ||
|
|
||
| package io.flutter.plugins.camera; | ||
|
|
||
| import android.graphics.Rect; | ||
| import android.hardware.camera2.CameraAccessException; | ||
| import android.hardware.camera2.CameraCharacteristics; | ||
| import android.hardware.camera2.CameraManager; | ||
| import android.os.Build.VERSION_CODES; | ||
| import android.util.Range; | ||
| import android.util.Rational; | ||
| import android.util.Size; | ||
| import androidx.annotation.RequiresApi; | ||
|
|
||
| /** | ||
| * Implementation of the @see CameraProperties interface using the @see | ||
| * android.hardware.camera2.CameraCharacteristics class to access the different characteristics. | ||
| */ | ||
| public class CameraPropertiesImpl implements CameraProperties { | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @camsim99 The javac warnings indicated that this class should have only been used from its own file. |
||
| private final CameraCharacteristics cameraCharacteristics; | ||
| private final String cameraName; | ||
|
|
||
| public CameraPropertiesImpl(String cameraName, CameraManager cameraManager) | ||
| throws CameraAccessException { | ||
| this.cameraName = cameraName; | ||
| this.cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName); | ||
| } | ||
|
|
||
| @Override | ||
| public String getCameraName() { | ||
| return cameraName; | ||
| } | ||
|
|
||
| @Override | ||
| public Range<Integer>[] getControlAutoExposureAvailableTargetFpsRanges() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_AVAILABLE_TARGET_FPS_RANGES); | ||
| } | ||
|
|
||
| @Override | ||
| public Range<Integer> getControlAutoExposureCompensationRange() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_RANGE); | ||
| } | ||
|
|
||
| @Override | ||
| public double getControlAutoExposureCompensationStep() { | ||
| Rational rational = | ||
| cameraCharacteristics.get(CameraCharacteristics.CONTROL_AE_COMPENSATION_STEP); | ||
|
|
||
| return rational == null ? 0.0 : rational.doubleValue(); | ||
| } | ||
|
|
||
| @Override | ||
| public int[] getControlAutoFocusAvailableModes() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.CONTROL_AF_AVAILABLE_MODES); | ||
| } | ||
|
|
||
| @Override | ||
| public Integer getControlMaxRegionsAutoExposure() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AE); | ||
| } | ||
|
|
||
| @Override | ||
| public Integer getControlMaxRegionsAutoFocus() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.CONTROL_MAX_REGIONS_AF); | ||
| } | ||
|
|
||
| @RequiresApi(api = VERSION_CODES.P) | ||
| @Override | ||
| public int[] getDistortionCorrectionAvailableModes() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.DISTORTION_CORRECTION_AVAILABLE_MODES); | ||
| } | ||
|
|
||
| @Override | ||
| public Boolean getFlashInfoAvailable() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.FLASH_INFO_AVAILABLE); | ||
| } | ||
|
|
||
| @Override | ||
| public int getLensFacing() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.LENS_FACING); | ||
| } | ||
|
|
||
| @Override | ||
| public Float getLensInfoMinimumFocusDistance() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_MINIMUM_FOCUS_DISTANCE); | ||
| } | ||
|
|
||
| @Override | ||
| public Float getScalerAvailableMaxDigitalZoom() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM); | ||
| } | ||
|
|
||
| @RequiresApi(api = VERSION_CODES.R) | ||
| @Override | ||
| public Float getScalerMaxZoomRatio() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getUpper(); | ||
| } | ||
|
|
||
| @RequiresApi(api = VERSION_CODES.R) | ||
| @Override | ||
| public Float getScalerMinZoomRatio() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.CONTROL_ZOOM_RATIO_RANGE).getLower(); | ||
| } | ||
|
|
||
| @Override | ||
| public Rect getSensorInfoActiveArraySize() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE); | ||
| } | ||
|
|
||
| @Override | ||
| public Size getSensorInfoPixelArraySize() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_PIXEL_ARRAY_SIZE); | ||
| } | ||
|
|
||
| @RequiresApi(api = VERSION_CODES.M) | ||
| @Override | ||
| public Rect getSensorInfoPreCorrectionActiveArraySize() { | ||
| return cameraCharacteristics.get( | ||
| CameraCharacteristics.SENSOR_INFO_PRE_CORRECTION_ACTIVE_ARRAY_SIZE); | ||
| } | ||
|
|
||
| @Override | ||
| public int getSensorOrientation() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.SENSOR_ORIENTATION); | ||
| } | ||
|
|
||
| @Override | ||
| public int getHardwareLevel() { | ||
| return cameraCharacteristics.get(CameraCharacteristics.INFO_SUPPORTED_HARDWARE_LEVEL); | ||
| } | ||
|
|
||
| @Override | ||
| public int[] getAvailableNoiseReductionModes() { | ||
| return cameraCharacteristics.get( | ||
| CameraCharacteristics.NOISE_REDUCTION_AVAILABLE_NOISE_REDUCTION_MODES); | ||
| } | ||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.