Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Commit 5bd292b

Browse files
committed
Added improvements after feedback on PR
1 parent 31e91cf commit 5bd292b

File tree

1 file changed

+16
-15
lines changed
  • packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/autofocus

1 file changed

+16
-15
lines changed

packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/features/autofocus/AutoFocusFeature.java

+16-15
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,21 @@
99
import io.flutter.plugins.camera.CameraProperties;
1010
import io.flutter.plugins.camera.features.CameraFeature;
1111

12+
/**
13+
* Controls the auto focus configuration on the {@see anddroid.hardware.camera2} API.
14+
*/
1215
public class AutoFocusFeature extends CameraFeature<FocusMode> {
1316
private FocusMode currentSetting = FocusMode.auto;
1417

15-
// When we switch recording modes we re-create this feature with
16-
// the appropriate setting here.
18+
// When switching recording modes this feature is re-created with the appropriate setting here.
1719
private final boolean recordingVideo;
1820

21+
/**
22+
* Creates a new instance of the {@see AutoFocusFeature}.
23+
*
24+
* @param cameraProperties Collection of the characteristics for the current camera device.
25+
* @param recordingVideo Indicates whether the camera is currently recording video.
26+
*/
1927
public AutoFocusFeature(CameraProperties cameraProperties, boolean recordingVideo) {
2028
super(cameraProperties);
2129
this.recordingVideo = recordingVideo;
@@ -40,19 +48,11 @@ public void setValue(FocusMode value) {
4048
public boolean checkIsSupported() {
4149
int[] modes = cameraProperties.getControlAutoFocusAvailableModes();
4250

43-
// Check if fixed focal length lens. If LENS_INFO_MINIMUM_FOCUS_DISTANCE=0, then this is fixed.
44-
// Can be null on some devices.
4551
final Float minFocus = cameraProperties.getLensInfoMinimumFocusDistance();
46-
// final Float maxFocus = cameraCharacteristics.get(CameraCharacteristics.LENS_INFO_HYPERFOCAL_DISTANCE);
4752

48-
// Value can be null on some devices:
49-
// https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#LENS_INFO_MINIMUM_FOCUS_DISTANCE
50-
boolean isFixedLength;
51-
if (minFocus == null) {
52-
isFixedLength = true;
53-
} else {
54-
isFixedLength = minFocus == 0;
55-
}
53+
// Check if the focal length of the lens is fixed. If the minimum focus distance == 0, then the
54+
// focal length is fixed. The minimum focus distance can be null on some devices: https://developer.android.com/reference/android/hardware/camera2/CameraCharacteristics#LENS_INFO_MINIMUM_FOCUS_DISTANCE
55+
boolean isFixedLength= minFocus == null || minFocus == 0;
5656

5757
return !isFixedLength
5858
&& !(modes.length == 0
@@ -67,10 +67,11 @@ public void updateBuilder(CaptureRequest.Builder requestBuilder) {
6767

6868
switch (currentSetting) {
6969
case locked:
70-
/** If we're locking AF we should do a one-time focus, then set the AF to idle */
70+
// When locking the auto-focus the camera device should do a one-time focus and afterwards
71+
// set the auto-focus to idle. This is accomplished by setting the CONTROL_AF_MODE to
72+
// CONTROL_AF_MODE_AUTO.
7173
requestBuilder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
7274
break;
73-
7475
case auto:
7576
requestBuilder.set(
7677
CaptureRequest.CONTROL_AF_MODE,

0 commit comments

Comments
 (0)