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

[camera_platform_interface] Add platform interface methods for setting auto focus. #3369

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c9f7e21
Added platform interface methods for setting auto exposure.
BeMacized Dec 24, 2020
532b22f
Added platform interface methods for setting auto exposure.
BeMacized Dec 24, 2020
1844b24
Remove workspace files
BeMacized Dec 24, 2020
fd8dd40
Added auto exposure implementations for Android and iOS
BeMacized Dec 24, 2020
92966de
Added platform interface methods for managing auto focus.
BeMacized Dec 25, 2020
deea6a0
Formatted code
BeMacized Dec 25, 2020
42a4517
Export focus mode
BeMacized Dec 25, 2020
bdeed1d
Update platform interface for changes to autofocus methods
BeMacized Dec 25, 2020
798d458
Revert "Update platform interface for changes to autofocus methods"
BeMacized Dec 25, 2020
2b98bdd
iOS fix for setting the exposure point
BeMacized Dec 25, 2020
b886e55
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 25, 2020
06f436f
Removed unnecessary check
BeMacized Dec 25, 2020
e19c2a5
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 25, 2020
df1c09b
Updated changelog and pubspec.yaml
BeMacized Dec 25, 2020
95b4795
Merge branch 'master' into feature/camera_focus_auto_platform_interface
BeMacized Dec 25, 2020
70804a0
Merge branch 'master' into feature/camera_exposure_auto
BeMacized Dec 29, 2020
5f1a730
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 29, 2020
7b4445d
Merge branch 'master' into feature/camera_exposure_auto
BeMacized Dec 29, 2020
67b37f2
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 29, 2020
14c6ab6
Update platform interface dependency
BeMacized Dec 29, 2020
a52f690
Implement PR feedback
BeMacized Dec 29, 2020
1e6ed87
Merge branch 'master' into feature/camera_exposure_auto
BeMacized Dec 29, 2020
9a88bca
Restore test
BeMacized Dec 29, 2020
0b748ef
Merge branch 'feature/camera_exposure_auto' into feature/camera_focus…
BeMacized Dec 30, 2020
171fe0b
Revert test change
BeMacized Dec 30, 2020
930d901
Update camera pubspec
BeMacized Dec 30, 2020
60a1137
Update platform interface to prevent breaking changes with current ma…
BeMacized Dec 30, 2020
07c4339
Merged with master
mvanbeusekom Jan 6, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions packages/camera/camera_platform_interface/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 1.4.0

- Added interface methods to support auto focus.

## 1.3.0

- Introduces an option to set the image format when initializing.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

import 'package:camera_platform_interface/src/types/focus_mode.dart';

import '../../camera_platform_interface.dart';

/// Generic Event coming from the native side of Camera.
Expand Down Expand Up @@ -50,9 +52,15 @@ class CameraInitializedEvent extends CameraEvent {
/// The default exposure mode
final ExposureMode exposureMode;

/// The default focus mode
final FocusMode focusMode;

/// Whether setting exposure points is supported.
final bool exposurePointSupported;

/// Whether setting focus points is supported.
final bool focusPointSupported;

/// Build a CameraInitialized event triggered from the camera represented by
/// `cameraId`.
///
Expand All @@ -61,18 +69,22 @@ class CameraInitializedEvent extends CameraEvent {
CameraInitializedEvent(
int cameraId,
this.previewWidth,
this.previewHeight,
this.previewHeight, [
this.exposureMode,
this.exposurePointSupported,
) : super(cameraId);
this.exposurePointSupported = false,
this.focusMode,
this.focusPointSupported = false,
]) : super(cameraId);

/// Converts the supplied [Map] to an instance of the [CameraInitializedEvent]
/// class.
CameraInitializedEvent.fromJson(Map<String, dynamic> json)
: previewWidth = json['previewWidth'],
previewHeight = json['previewHeight'],
exposureMode = deserializeExposureMode(json['exposureMode']),
exposurePointSupported = json['exposurePointSupported'],
exposurePointSupported = json['exposurePointSupported'] ?? false,
focusMode = deserializeFocusMode(json['focusMode']),
focusPointSupported = json['focusPointSupported'] ?? false,
super(json['cameraId']);

/// Converts the [CameraInitializedEvent] instance into a [Map] instance that
Expand All @@ -83,6 +95,8 @@ class CameraInitializedEvent extends CameraEvent {
'previewHeight': previewHeight,
'exposureMode': serializeExposureMode(exposureMode),
'exposurePointSupported': exposurePointSupported,
'focusMode': serializeFocusMode(focusMode),
'focusPointSupported': focusPointSupported,
};

@override
Expand All @@ -94,15 +108,19 @@ class CameraInitializedEvent extends CameraEvent {
previewWidth == other.previewWidth &&
previewHeight == other.previewHeight &&
exposureMode == other.exposureMode &&
exposurePointSupported == other.exposurePointSupported;
exposurePointSupported == other.exposurePointSupported &&
focusMode == other.focusMode &&
focusPointSupported == other.focusPointSupported;

@override
int get hashCode =>
super.hashCode ^
previewWidth.hashCode ^
previewHeight.hashCode ^
exposureMode.hashCode ^
exposurePointSupported.hashCode;
exposurePointSupported.hashCode ^
focusMode.hashCode ^
focusPointSupported.hashCode;
}

/// An event fired when the resolution preset of the camera has changed.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'dart:async';
import 'dart:math';

import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:camera_platform_interface/src/types/focus_mode.dart';
import 'package:camera_platform_interface/src/types/image_format_group.dart';
import 'package:camera_platform_interface/src/utils/utils.dart';
import 'package:cross_file/cross_file.dart';
Expand Down Expand Up @@ -249,6 +250,31 @@ class MethodChannelCamera extends CameraPlatform {
},
);

@override
Future<void> setFocusMode(int cameraId, FocusMode mode) =>
_channel.invokeMethod<void>(
'setFocusMode',
<String, dynamic>{
'cameraId': cameraId,
'mode': serializeFocusMode(mode),
},
);

@override
Future<void> setFocusPoint(int cameraId, Point<double> point) {
assert(point == null || point.x >= 0 && point.x <= 1);
assert(point == null || point.y >= 0 && point.y <= 1);
return _channel.invokeMethod<void>(
'setFocusPoint',
<String, dynamic>{
'cameraId': cameraId,
'reset': point == null,
'x': point?.x,
'y': point?.y,
},
);
}

@override
Future<double> getMaxZoomLevel(int cameraId) => _channel.invokeMethod<double>(
'getMaxZoomLevel',
Expand Down Expand Up @@ -331,6 +357,8 @@ class MethodChannelCamera extends CameraPlatform {
call.arguments['previewHeight'],
deserializeExposureMode(call.arguments['exposureMode']),
call.arguments['exposurePointSupported'],
deserializeFocusMode(call.arguments['focusMode']),
call.arguments['focusPointSupported'],
));
break;
case 'resolution_changed':
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import 'dart:math';
import 'package:camera_platform_interface/camera_platform_interface.dart';
import 'package:camera_platform_interface/src/method_channel/method_channel_camera.dart';
import 'package:camera_platform_interface/src/types/exposure_mode.dart';
import 'package:camera_platform_interface/src/types/focus_mode.dart';
import 'package:camera_platform_interface/src/types/image_format_group.dart';
import 'package:cross_file/cross_file.dart';
import 'package:flutter/widgets.dart';
Expand Down Expand Up @@ -129,7 +130,7 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('setExposureMode() is not implemented.');
}

/// Sets the exposure point for automatically determining the exposure value.
/// Sets the exposure point for automatically determining the exposure values.
Future<void> setExposurePoint(int cameraId, Point<double> point) {
throw UnimplementedError('setExposurePoint() is not implemented.');
}
Expand Down Expand Up @@ -166,6 +167,16 @@ abstract class CameraPlatform extends PlatformInterface {
throw UnimplementedError('setExposureOffset() is not implemented.');
}

/// Sets the focus mode for taking pictures.
Future<void> setFocusMode(int cameraId, FocusMode mode) {
throw UnimplementedError('setFocusMode() is not implemented.');
}

/// Sets the focus point for automatically determining the focus values.
Future<void> setFocusPoint(int cameraId, Point<double> point) {
throw UnimplementedError('setFocusPoint() is not implemented.');
}

/// Gets the maximum supported zoom level for the selected camera.
Future<double> getMaxZoomLevel(int cameraId) {
throw UnimplementedError('getMaxZoomLevel() is not implemented.');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ enum ExposureMode {

/// Returns the exposure mode as a String.
String serializeExposureMode(ExposureMode exposureMode) {
if (exposureMode == null) return null;
switch (exposureMode) {
case ExposureMode.locked:
return 'locked';
Expand All @@ -25,6 +26,7 @@ String serializeExposureMode(ExposureMode exposureMode) {

/// Returns the exposure mode for a given String.
ExposureMode deserializeExposureMode(String str) {
if (str == null) return null;
switch (str) {
case "locked":
return ExposureMode.locked;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

/// The possible focus modes that can be set for a camera.
enum FocusMode {
/// Automatically determine focus settings.
auto,

/// Lock the currently determined focus settings.
locked,
}

/// Returns the focus mode as a String.
String serializeFocusMode(FocusMode focusMode) {
if (focusMode == null) return null;
switch (focusMode) {
case FocusMode.locked:
return 'locked';
case FocusMode.auto:
return 'auto';
default:
throw ArgumentError('Unknown FocusMode value');
}
}

/// Returns the focus mode for a given String.
FocusMode deserializeFocusMode(String str) {
if (str == null) return null;
switch (str) {
case "locked":
return FocusMode.locked;
case "auto":
return FocusMode.auto;
default:
throw ArgumentError('"$str" is not a valid FocusMode value');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@ export 'camera_exception.dart';
export 'flash_mode.dart';
export 'image_format_group.dart';
export 'exposure_mode.dart';
export 'focus_mode.dart';
2 changes: 1 addition & 1 deletion packages/camera/camera_platform_interface/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ description: A common platform interface for the camera plugin.
homepage: https://github.com/flutter/plugins/tree/master/packages/camera/camera_platform_interface
# NOTE: We strongly prefer non-breaking changes, even at the expense of a
# less-clean API. See https://flutter.dev/go/platform-interface-breaking-changes
version: 1.3.0
version: 1.4.0

dependencies:
flutter:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,32 @@ void main() {
);
});

test(
'Default implementation of setFocusMode() should throw unimplemented error',
() {
// Arrange
final cameraPlatform = ExtendsCameraPlatform();

// Act & Assert
expect(
() => cameraPlatform.setFocusMode(1, null),
throwsUnimplementedError,
);
});

test(
'Default implementation of setFocusPoint() should throw unimplemented error',
() {
// Arrange
final cameraPlatform = ExtendsCameraPlatform();

// Act & Assert
expect(
() => cameraPlatform.setFocusPoint(1, null),
throwsUnimplementedError,
);
});

test(
'Default implementation of startVideoRecording() should throw unimplemented error',
() {
Expand Down
Loading