Skip to content

Commit

Permalink
Update platform interface for changes to autofocus methods
Browse files Browse the repository at this point in the history
  • Loading branch information
BeMacized committed Dec 25, 2020
1 parent 42a4517 commit bdeed1d
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,18 @@

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

/// Lock the currently determined focus settings.
locked,
/// Automatically determine the focus settings once upon setting this mode or the focus point.
auto,
}

/// Returns the focus mode as a String.
String serializeFocusMode(FocusMode focusMode) {
switch (focusMode) {
case FocusMode.locked:
return 'locked';
case FocusMode.continuous:
return 'continuous';
case FocusMode.auto:
return 'auto';
default:
Expand All @@ -26,8 +26,8 @@ String serializeFocusMode(FocusMode focusMode) {
/// Returns the focus mode for a given String.
FocusMode deserializeFocusMode(String str) {
switch (str) {
case "locked":
return FocusMode.locked;
case "continuous":
return FocusMode.continuous;
case "auto":
return FocusMode.auto;
default:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,13 @@ void main() {
group('CameraInitializedEvent tests', () {
test('Constructor should initialize all properties', () {
final event = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);

expect(event.cameraId, 1);
expect(event.previewWidth, 1024);
expect(event.previewHeight, 640);
expect(event.exposureMode, ExposureMode.auto);
expect(event.focusMode, FocusMode.auto);
expect(event.focusMode, FocusMode.continuous);
expect(event.exposurePointSupported, true);
expect(event.focusPointSupported, true);
});
Expand All @@ -30,7 +30,7 @@ void main() {
'previewWidth': 1024.0,
'previewHeight': 640.0,
'exposureMode': 'auto',
'focusMode': 'auto',
'focusMode': 'continuous',
'exposurePointSupported': true,
'focusPointSupported': true
});
Expand All @@ -39,14 +39,14 @@ void main() {
expect(event.previewWidth, 1024);
expect(event.previewHeight, 640);
expect(event.exposureMode, ExposureMode.auto);
expect(event.focusMode, FocusMode.auto);
expect(event.focusMode, FocusMode.continuous);
expect(event.exposurePointSupported, true);
expect(event.focusPointSupported, true);
});

test('toJson should return a map with all fields', () {
final event = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);

final jsonMap = event.toJson();

Expand All @@ -55,87 +55,87 @@ void main() {
expect(jsonMap['previewWidth'], 1024);
expect(jsonMap['previewHeight'], 640);
expect(jsonMap['exposureMode'], 'auto');
expect(jsonMap['focusMode'], 'auto');
expect(jsonMap['focusMode'], 'continuous');
expect(jsonMap['exposurePointSupported'], true);
expect(jsonMap['focusPointSupported'], true);
});

test('equals should return true if objects are the same', () {
final firstEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final secondEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);

expect(firstEvent == secondEvent, true);
});

test('equals should return false if cameraId is different', () {
final firstEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final secondEvent = CameraInitializedEvent(
2, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
2, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);

expect(firstEvent == secondEvent, false);
});

test('equals should return false if previewWidth is different', () {
final firstEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final secondEvent = CameraInitializedEvent(
1, 2048, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 2048, 640, ExposureMode.auto, FocusMode.continuous, true, true);

expect(firstEvent == secondEvent, false);
});

test('equals should return false if previewHeight is different', () {
final firstEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final secondEvent = CameraInitializedEvent(
1, 1024, 980, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 980, ExposureMode.auto, FocusMode.continuous, true, true);

expect(firstEvent == secondEvent, false);
});

test('equals should return false if exposureMode is different', () {
final firstEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final secondEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.locked, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.locked, FocusMode.continuous, true, true);

expect(firstEvent == secondEvent, false);
});

test('equals should return false if exposurePointSupported is different',
() {
final firstEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final secondEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, false, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, false, true);

expect(firstEvent == secondEvent, false);
});

test('equals should return false if focusMode is different', () {
final firstEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final secondEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.locked, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);

expect(firstEvent == secondEvent, false);
});

test('equals should return false if focusPointSupported is different', () {
final firstEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final secondEvent = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, false);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, false);

expect(firstEvent == secondEvent, false);
});

test('hashCode should match hashCode of all properties', () {
final event = CameraInitializedEvent(
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
final expectedHashCode = event.cameraId.hashCode ^
event.previewWidth.hashCode ^
event.previewHeight.hashCode ^
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ void main() {
1920,
1080,
ExposureMode.auto,
FocusMode.auto,
FocusMode.continuous,
true,
true,
));
Expand Down Expand Up @@ -165,7 +165,7 @@ void main() {
1920,
1080,
ExposureMode.auto,
FocusMode.auto,
FocusMode.continuous,
true,
true,
));
Expand Down Expand Up @@ -209,7 +209,7 @@ void main() {
1920,
1080,
ExposureMode.auto,
FocusMode.auto,
FocusMode.continuous,
true,
true,
));
Expand All @@ -228,7 +228,7 @@ void main() {
3840,
2160,
ExposureMode.auto,
FocusMode.auto,
FocusMode.continuous,
true,
true,
);
Expand Down Expand Up @@ -341,7 +341,7 @@ void main() {
1920,
1080,
ExposureMode.auto,
FocusMode.auto,
FocusMode.continuous,
true,
true,
),
Expand Down Expand Up @@ -669,15 +669,15 @@ void main() {
);

// Act
await camera.setFocusMode(cameraId, FocusMode.continuous);
await camera.setFocusMode(cameraId, FocusMode.auto);
await camera.setFocusMode(cameraId, FocusMode.locked);

// Assert
expect(channel.log, <Matcher>[
isMethodCall('setFocusMode',
arguments: {'cameraId': cameraId, 'mode': 'auto'}),
arguments: {'cameraId': cameraId, 'mode': 'continuous'}),
isMethodCall('setFocusMode',
arguments: {'cameraId': cameraId, 'mode': 'locked'}),
arguments: {'cameraId': cameraId, 'mode': 'auto'}),
]);
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,17 @@ void main() {
test("FocusMode enum should have items in correct index", () {
final values = FocusMode.values;

expect(values[0], FocusMode.auto);
expect(values[1], FocusMode.locked);
expect(values[0], FocusMode.continuous);
expect(values[1], FocusMode.auto);
});

test("serializeFocusMode() should serialize correctly", () {
expect(serializeFocusMode(FocusMode.continuous), "continuous");
expect(serializeFocusMode(FocusMode.auto), "auto");
expect(serializeFocusMode(FocusMode.locked), "locked");
});

test("deserializeFocusMode() should deserialize correctly", () {
expect(deserializeFocusMode('continuous'), FocusMode.continuous);
expect(deserializeFocusMode('auto'), FocusMode.auto);
expect(deserializeFocusMode('locked'), FocusMode.locked);
});
}

0 comments on commit bdeed1d

Please sign in to comment.