Skip to content

Commit bdeed1d

Browse files
committed
Update platform interface for changes to autofocus methods
1 parent 42a4517 commit bdeed1d

File tree

4 files changed

+43
-43
lines changed

4 files changed

+43
-43
lines changed

packages/camera/camera_platform_interface/lib/src/types/focus_mode.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,18 @@
44

55
/// The possible focus modes that can be set for a camera.
66
enum FocusMode {
7-
/// Automatically determine focus settings.
8-
auto,
7+
/// Continuously automatically adjust the focus settings.
8+
continuous,
99

10-
/// Lock the currently determined focus settings.
11-
locked,
10+
/// Automatically determine the focus settings once upon setting this mode or the focus point.
11+
auto,
1212
}
1313

1414
/// Returns the focus mode as a String.
1515
String serializeFocusMode(FocusMode focusMode) {
1616
switch (focusMode) {
17-
case FocusMode.locked:
18-
return 'locked';
17+
case FocusMode.continuous:
18+
return 'continuous';
1919
case FocusMode.auto:
2020
return 'auto';
2121
default:
@@ -26,8 +26,8 @@ String serializeFocusMode(FocusMode focusMode) {
2626
/// Returns the focus mode for a given String.
2727
FocusMode deserializeFocusMode(String str) {
2828
switch (str) {
29-
case "locked":
30-
return FocusMode.locked;
29+
case "continuous":
30+
return FocusMode.continuous;
3131
case "auto":
3232
return FocusMode.auto;
3333
default:

packages/camera/camera_platform_interface/test/events/camera_event_test.dart

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,13 @@ void main() {
1313
group('CameraInitializedEvent tests', () {
1414
test('Constructor should initialize all properties', () {
1515
final event = CameraInitializedEvent(
16-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
16+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
1717

1818
expect(event.cameraId, 1);
1919
expect(event.previewWidth, 1024);
2020
expect(event.previewHeight, 640);
2121
expect(event.exposureMode, ExposureMode.auto);
22-
expect(event.focusMode, FocusMode.auto);
22+
expect(event.focusMode, FocusMode.continuous);
2323
expect(event.exposurePointSupported, true);
2424
expect(event.focusPointSupported, true);
2525
});
@@ -30,7 +30,7 @@ void main() {
3030
'previewWidth': 1024.0,
3131
'previewHeight': 640.0,
3232
'exposureMode': 'auto',
33-
'focusMode': 'auto',
33+
'focusMode': 'continuous',
3434
'exposurePointSupported': true,
3535
'focusPointSupported': true
3636
});
@@ -39,14 +39,14 @@ void main() {
3939
expect(event.previewWidth, 1024);
4040
expect(event.previewHeight, 640);
4141
expect(event.exposureMode, ExposureMode.auto);
42-
expect(event.focusMode, FocusMode.auto);
42+
expect(event.focusMode, FocusMode.continuous);
4343
expect(event.exposurePointSupported, true);
4444
expect(event.focusPointSupported, true);
4545
});
4646

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

5151
final jsonMap = event.toJson();
5252

@@ -55,87 +55,87 @@ void main() {
5555
expect(jsonMap['previewWidth'], 1024);
5656
expect(jsonMap['previewHeight'], 640);
5757
expect(jsonMap['exposureMode'], 'auto');
58-
expect(jsonMap['focusMode'], 'auto');
58+
expect(jsonMap['focusMode'], 'continuous');
5959
expect(jsonMap['exposurePointSupported'], true);
6060
expect(jsonMap['focusPointSupported'], true);
6161
});
6262

6363
test('equals should return true if objects are the same', () {
6464
final firstEvent = CameraInitializedEvent(
65-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
65+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
6666
final secondEvent = CameraInitializedEvent(
67-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
67+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
6868

6969
expect(firstEvent == secondEvent, true);
7070
});
7171

7272
test('equals should return false if cameraId is different', () {
7373
final firstEvent = CameraInitializedEvent(
74-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
74+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
7575
final secondEvent = CameraInitializedEvent(
76-
2, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
76+
2, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
7777

7878
expect(firstEvent == secondEvent, false);
7979
});
8080

8181
test('equals should return false if previewWidth is different', () {
8282
final firstEvent = CameraInitializedEvent(
83-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
83+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
8484
final secondEvent = CameraInitializedEvent(
85-
1, 2048, 640, ExposureMode.auto, FocusMode.auto, true, true);
85+
1, 2048, 640, ExposureMode.auto, FocusMode.continuous, true, true);
8686

8787
expect(firstEvent == secondEvent, false);
8888
});
8989

9090
test('equals should return false if previewHeight is different', () {
9191
final firstEvent = CameraInitializedEvent(
92-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
92+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
9393
final secondEvent = CameraInitializedEvent(
94-
1, 1024, 980, ExposureMode.auto, FocusMode.auto, true, true);
94+
1, 1024, 980, ExposureMode.auto, FocusMode.continuous, true, true);
9595

9696
expect(firstEvent == secondEvent, false);
9797
});
9898

9999
test('equals should return false if exposureMode is different', () {
100100
final firstEvent = CameraInitializedEvent(
101-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
101+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
102102
final secondEvent = CameraInitializedEvent(
103-
1, 1024, 640, ExposureMode.locked, FocusMode.auto, true, true);
103+
1, 1024, 640, ExposureMode.locked, FocusMode.continuous, true, true);
104104

105105
expect(firstEvent == secondEvent, false);
106106
});
107107

108108
test('equals should return false if exposurePointSupported is different',
109109
() {
110110
final firstEvent = CameraInitializedEvent(
111-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
111+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
112112
final secondEvent = CameraInitializedEvent(
113-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, false, true);
113+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, false, true);
114114

115115
expect(firstEvent == secondEvent, false);
116116
});
117117

118118
test('equals should return false if focusMode is different', () {
119119
final firstEvent = CameraInitializedEvent(
120-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
120+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
121121
final secondEvent = CameraInitializedEvent(
122-
1, 1024, 640, ExposureMode.auto, FocusMode.locked, true, true);
122+
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
123123

124124
expect(firstEvent == secondEvent, false);
125125
});
126126

127127
test('equals should return false if focusPointSupported is different', () {
128128
final firstEvent = CameraInitializedEvent(
129-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
129+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
130130
final secondEvent = CameraInitializedEvent(
131-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, false);
131+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, false);
132132

133133
expect(firstEvent == secondEvent, false);
134134
});
135135

136136
test('hashCode should match hashCode of all properties', () {
137137
final event = CameraInitializedEvent(
138-
1, 1024, 640, ExposureMode.auto, FocusMode.auto, true, true);
138+
1, 1024, 640, ExposureMode.auto, FocusMode.continuous, true, true);
139139
final expectedHashCode = event.cameraId.hashCode ^
140140
event.previewWidth.hashCode ^
141141
event.previewHeight.hashCode ^

packages/camera/camera_platform_interface/test/method_channel/method_channel_camera_test.dart

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ void main() {
125125
1920,
126126
1080,
127127
ExposureMode.auto,
128-
FocusMode.auto,
128+
FocusMode.continuous,
129129
true,
130130
true,
131131
));
@@ -165,7 +165,7 @@ void main() {
165165
1920,
166166
1080,
167167
ExposureMode.auto,
168-
FocusMode.auto,
168+
FocusMode.continuous,
169169
true,
170170
true,
171171
));
@@ -209,7 +209,7 @@ void main() {
209209
1920,
210210
1080,
211211
ExposureMode.auto,
212-
FocusMode.auto,
212+
FocusMode.continuous,
213213
true,
214214
true,
215215
));
@@ -228,7 +228,7 @@ void main() {
228228
3840,
229229
2160,
230230
ExposureMode.auto,
231-
FocusMode.auto,
231+
FocusMode.continuous,
232232
true,
233233
true,
234234
);
@@ -341,7 +341,7 @@ void main() {
341341
1920,
342342
1080,
343343
ExposureMode.auto,
344-
FocusMode.auto,
344+
FocusMode.continuous,
345345
true,
346346
true,
347347
),
@@ -669,15 +669,15 @@ void main() {
669669
);
670670

671671
// Act
672+
await camera.setFocusMode(cameraId, FocusMode.continuous);
672673
await camera.setFocusMode(cameraId, FocusMode.auto);
673-
await camera.setFocusMode(cameraId, FocusMode.locked);
674674

675675
// Assert
676676
expect(channel.log, <Matcher>[
677677
isMethodCall('setFocusMode',
678-
arguments: {'cameraId': cameraId, 'mode': 'auto'}),
678+
arguments: {'cameraId': cameraId, 'mode': 'continuous'}),
679679
isMethodCall('setFocusMode',
680-
arguments: {'cameraId': cameraId, 'mode': 'locked'}),
680+
arguments: {'cameraId': cameraId, 'mode': 'auto'}),
681681
]);
682682
});
683683

packages/camera/camera_platform_interface/test/types/focus_mode_test.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,17 +15,17 @@ void main() {
1515
test("FocusMode enum should have items in correct index", () {
1616
final values = FocusMode.values;
1717

18-
expect(values[0], FocusMode.auto);
19-
expect(values[1], FocusMode.locked);
18+
expect(values[0], FocusMode.continuous);
19+
expect(values[1], FocusMode.auto);
2020
});
2121

2222
test("serializeFocusMode() should serialize correctly", () {
23+
expect(serializeFocusMode(FocusMode.continuous), "continuous");
2324
expect(serializeFocusMode(FocusMode.auto), "auto");
24-
expect(serializeFocusMode(FocusMode.locked), "locked");
2525
});
2626

2727
test("deserializeFocusMode() should deserialize correctly", () {
28+
expect(deserializeFocusMode('continuous'), FocusMode.continuous);
2829
expect(deserializeFocusMode('auto'), FocusMode.auto);
29-
expect(deserializeFocusMode('locked'), FocusMode.locked);
3030
});
3131
}

0 commit comments

Comments
 (0)