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

Commit 7e152b8

Browse files
committed
Update version number
2 parents 00124f4 + 6d18db8 commit 7e152b8

File tree

57 files changed

+2030
-242
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

57 files changed

+2030
-242
lines changed

packages/battery/battery/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.0-nullsafety
2+
3+
* Migrate to null safety.
4+
15
## 1.0.11
26

37
* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.

packages/battery/battery/example/lib/main.dart

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class MyApp extends StatelessWidget {
2727
}
2828

2929
class MyHomePage extends StatefulWidget {
30-
MyHomePage({Key key, this.title}) : super(key: key);
30+
MyHomePage({Key? key, required this.title}) : super(key: key);
3131

3232
final String title;
3333

@@ -36,10 +36,10 @@ class MyHomePage extends StatefulWidget {
3636
}
3737

3838
class _MyHomePageState extends State<MyHomePage> {
39-
Battery _battery = Battery();
39+
final Battery _battery = Battery();
4040

41-
BatteryState _batteryState;
42-
StreamSubscription<BatteryState> _batteryStateSubscription;
41+
BatteryState? _batteryState;
42+
late StreamSubscription<BatteryState> _batteryStateSubscription;
4343

4444
@override
4545
void initState() {

packages/battery/battery/example/pubspec.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,11 +12,11 @@ dev_dependencies:
1212
sdk: flutter
1313
integration_test:
1414
path: ../../../integration_test
15-
pedantic: ^1.8.0
15+
pedantic: ^1.10.0-nullsafety
1616

1717
flutter:
1818
uses-material-design: true
1919

2020
environment:
21-
sdk: ">=2.1.0 <3.0.0"
21+
sdk: ">=2.12.0-0 <3.0.0"
2222
flutter: ">=1.12.13+hotfix.5 <2.0.0"

packages/battery/battery/integration_test/battery_test.dart

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
// for details. All rights reserved. Use of this source code is governed by a
33
// BSD-style license that can be found in the LICENSE file.
44

5+
// @dart = 2.9
6+
57
import 'package:flutter_test/flutter_test.dart';
68
import 'package:battery/battery.dart';
79
import 'package:integration_test/integration_test.dart';

packages/battery/battery/pubspec.yaml

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ name: battery
22
description: Flutter plugin for accessing information about the battery state
33
(full, charging, discharging) on Android and iOS.
44
homepage: https://github.com/flutter/plugins/tree/master/packages/battery/battery
5-
version: 1.0.11
5+
version: 2.0.0-nullsafety
66

77
flutter:
88
plugin:
@@ -16,20 +16,18 @@ flutter:
1616
dependencies:
1717
flutter:
1818
sdk: flutter
19-
meta: ^1.0.5
20-
battery_platform_interface: ^1.0.0
19+
meta: ^1.3.0-nullsafety
20+
battery_platform_interface: ^2.0.0-nullsafety
2121

2222
dev_dependencies:
23-
async: ^2.0.8
24-
test: ^1.3.0
25-
mockito: ^4.1.1
23+
mockito: ^5.0.0-nullsafety.0
2624
flutter_test:
2725
sdk: flutter
28-
plugin_platform_interface: ^1.0.0
26+
plugin_platform_interface: ^1.1.0-nullsafety
2927
integration_test:
3028
path: ../../integration_test
31-
pedantic: ^1.8.0
29+
pedantic: ^1.10.0-nullsafety
3230

3331
environment:
34-
sdk: ">=2.1.0 <3.0.0"
32+
sdk: ">=2.12.0-0 <3.0.0"
3533
flutter: ">=1.12.13+hotfix.5"

packages/battery/battery/test/battery_test.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@
55
import 'dart:async';
66

77
import 'package:battery_platform_interface/battery_platform_interface.dart';
8+
import 'package:flutter_test/flutter_test.dart';
89
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
9-
import 'package:test/test.dart';
1010
import 'package:battery/battery.dart';
1111
import 'package:mockito/mockito.dart';
1212

1313
void main() {
1414
group('battery', () {
15-
Battery battery;
15+
late Battery battery;
1616
MockBatteryPlatform fakePlatform;
1717
setUp(() async {
1818
fakePlatform = MockBatteryPlatform();

packages/camera/camera/CHANGELOG.md

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
1-
## 0.6.6+1
1+
## 0.7.0+2
22

33
* Make sure the configured zoom scale is copied over to the final capture builder on Android. Fixes the issue where the preview is zoomed but the final picture is not.
44

5+
## 0.7.0+1
6+
7+
* Fixes picture captures causing a crash on some Huawei devices.
8+
9+
## 0.7.0
10+
11+
* Added support for capture orientation locking on Android and iOS.
12+
* Fixed camera preview not rotating correctly on Android and iOS.
13+
* Fixed camera preview sometimes appearing stretched on Android and iOS.
14+
* Fixed videos & photos saving with the incorrect rotation on iOS.
15+
* BREAKING CHANGE: `CameraValue.aspectRatio` now returns `width / height` rather than `height / width`.
16+
517
## 0.6.6
618

719
* Adds auto focus support for Android and iOS implementations.
@@ -24,7 +36,7 @@
2436

2537
## 0.6.4+2
2638

27-
* Set ImageStreamReader listener to null to prevent stale images when streaming images.
39+
* Set ImageStreamReader listener to null to prevent stale images when streaming images.
2840

2941
## 0.6.4+1
3042

packages/camera/camera/android/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ project.getTasks().withType(JavaCompile){
2727
apply plugin: 'com.android.library'
2828

2929
android {
30-
compileSdkVersion 29
30+
compileSdkVersion 30
3131

3232
defaultConfig {
3333
minSdkVersion 21

packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/Camera.java

Lines changed: 29 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
package io.flutter.plugins.camera;
66

7-
import static android.view.OrientationEventListener.ORIENTATION_UNKNOWN;
87
import static io.flutter.plugins.camera.CameraUtils.computeBestPreviewSize;
98

109
import android.annotation.SuppressLint;
@@ -41,10 +40,10 @@
4140
import android.util.Range;
4241
import android.util.Rational;
4342
import android.util.Size;
44-
import android.view.OrientationEventListener;
4543
import android.view.Surface;
4644
import androidx.annotation.NonNull;
4745
import androidx.annotation.Nullable;
46+
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
4847
import io.flutter.plugin.common.EventChannel;
4948
import io.flutter.plugin.common.MethodChannel.Result;
5049
import io.flutter.plugins.camera.PictureCaptureRequest.State;
@@ -76,7 +75,7 @@ public class Camera {
7675

7776
private final SurfaceTextureEntry flutterTexture;
7877
private final CameraManager cameraManager;
79-
private final OrientationEventListener orientationEventListener;
78+
private final DeviceOrientationManager deviceOrientationListener;
8079
private final boolean isFrontFacing;
8180
private final int sensorOrientation;
8281
private final String cameraName;
@@ -97,7 +96,6 @@ public class Camera {
9796
private MediaRecorder mediaRecorder;
9897
private boolean recordingVideo;
9998
private File videoRecordingFile;
100-
private int currentOrientation = ORIENTATION_UNKNOWN;
10199
private FlashMode flashMode;
102100
private ExposureMode exposureMode;
103101
private FocusMode focusMode;
@@ -106,6 +104,7 @@ public class Camera {
106104
private int exposureOffset;
107105
private boolean useAutoFocus = true;
108106
private Range<Integer> fpsRange;
107+
private PlatformChannel.DeviceOrientation lockedCaptureOrientation;
109108

110109
private static final HashMap<String, Integer> supportedImageFormats;
111110
// Current supported outputs
@@ -136,18 +135,6 @@ public Camera(
136135
this.exposureMode = ExposureMode.auto;
137136
this.focusMode = FocusMode.auto;
138137
this.exposureOffset = 0;
139-
orientationEventListener =
140-
new OrientationEventListener(activity.getApplicationContext()) {
141-
@Override
142-
public void onOrientationChanged(int i) {
143-
if (i == ORIENTATION_UNKNOWN) {
144-
return;
145-
}
146-
// Convert the raw deg angle to the nearest multiple of 90.
147-
currentOrientation = (int) Math.round(i / 90.0) * 90;
148-
}
149-
};
150-
orientationEventListener.enable();
151138

152139
cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
153140
initFps(cameraCharacteristics);
@@ -164,6 +151,10 @@ public void onOrientationChanged(int i) {
164151
new CameraZoom(
165152
cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE),
166153
cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM));
154+
155+
deviceOrientationListener =
156+
new DeviceOrientationManager(activity, dartMessenger, isFrontFacing, sensorOrientation);
157+
deviceOrientationListener.start();
167158
}
168159

169160
private void initFps(CameraCharacteristics cameraCharacteristics) {
@@ -195,7 +186,10 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
195186
mediaRecorder =
196187
new MediaRecorderBuilder(recordingProfile, outputFilePath)
197188
.setEnableAudio(enableAudio)
198-
.setMediaOrientation(getMediaOrientation())
189+
.setMediaOrientation(
190+
lockedCaptureOrientation == null
191+
? deviceOrientationListener.getMediaOrientation()
192+
: deviceOrientationListener.getMediaOrientation(lockedCaptureOrientation))
199193
.build();
200194
}
201195

@@ -464,17 +458,20 @@ public void onCaptureFailed(
464458
return;
465459
}
466460
String reason;
461+
boolean fatalFailure = false;
467462
switch (failure.getReason()) {
468463
case CaptureFailure.REASON_ERROR:
469464
reason = "An error happened in the framework";
470465
break;
471466
case CaptureFailure.REASON_FLUSHED:
472467
reason = "The capture has failed due to an abortCaptures() call";
468+
fatalFailure = true;
473469
break;
474470
default:
475471
reason = "Unknown reason";
476472
}
477-
pictureCaptureRequest.error("captureFailure", reason, null);
473+
Log.w("Camera", "pictureCaptureCallback.onCaptureFailed(): " + reason);
474+
if (fatalFailure) pictureCaptureRequest.error("captureFailure", reason, null);
478475
}
479476

480477
private void processCapture(CaptureResult result) {
@@ -548,7 +545,11 @@ private void runPictureCapture() {
548545
captureBuilder.set(
549546
CaptureRequest.SCALER_CROP_REGION,
550547
captureRequestBuilder.get(CaptureRequest.SCALER_CROP_REGION));
551-
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getMediaOrientation());
548+
captureBuilder.set(
549+
CaptureRequest.JPEG_ORIENTATION,
550+
lockedCaptureOrientation == null
551+
? deviceOrientationListener.getMediaOrientation()
552+
: deviceOrientationListener.getMediaOrientation(lockedCaptureOrientation));
552553
switch (flashMode) {
553554
case off:
554555
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
@@ -971,6 +972,14 @@ public void setZoomLevel(@NonNull final Result result, float zoom) throws Camera
971972
result.success(null);
972973
}
973974

975+
public void lockCaptureOrientation(PlatformChannel.DeviceOrientation orientation) {
976+
this.lockedCaptureOrientation = orientation;
977+
}
978+
979+
public void unlockCaptureOrientation() {
980+
this.lockedCaptureOrientation = null;
981+
}
982+
974983
private void updateFpsRange() {
975984
if (fpsRange == null) {
976985
return;
@@ -1163,14 +1172,6 @@ public void close() {
11631172
public void dispose() {
11641173
close();
11651174
flutterTexture.release();
1166-
orientationEventListener.disable();
1167-
}
1168-
1169-
private int getMediaOrientation() {
1170-
final int sensorOrientationOffset =
1171-
(currentOrientation == ORIENTATION_UNKNOWN)
1172-
? 0
1173-
: (isFrontFacing) ? -currentOrientation : currentOrientation;
1174-
return (sensorOrientationOffset + sensorOrientation + 360) % 360;
1175+
deviceOrientationListener.stop();
11751176
}
11761177
}

packages/camera/camera/android/src/main/java/io/flutter/plugins/camera/CameraUtils.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import android.hardware.camera2.params.StreamConfigurationMap;
1515
import android.media.CamcorderProfile;
1616
import android.util.Size;
17+
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
1718
import io.flutter.plugins.camera.types.ResolutionPreset;
1819
import java.util.ArrayList;
1920
import java.util.Arrays;
@@ -28,6 +29,59 @@ public final class CameraUtils {
2829

2930
private CameraUtils() {}
3031

32+
static PlatformChannel.DeviceOrientation getDeviceOrientationFromDegrees(int degrees) {
33+
// Round to the nearest 90 degrees.
34+
degrees = (int) (Math.round(degrees / 90.0) * 90) % 360;
35+
// Determine the corresponding device orientation.
36+
switch (degrees) {
37+
case 90:
38+
return PlatformChannel.DeviceOrientation.LANDSCAPE_LEFT;
39+
case 180:
40+
return PlatformChannel.DeviceOrientation.PORTRAIT_DOWN;
41+
case 270:
42+
return PlatformChannel.DeviceOrientation.LANDSCAPE_RIGHT;
43+
case 0:
44+
default:
45+
return PlatformChannel.DeviceOrientation.PORTRAIT_UP;
46+
}
47+
}
48+
49+
static String serializeDeviceOrientation(PlatformChannel.DeviceOrientation orientation) {
50+
if (orientation == null)
51+
throw new UnsupportedOperationException("Could not serialize null device orientation.");
52+
switch (orientation) {
53+
case PORTRAIT_UP:
54+
return "portraitUp";
55+
case PORTRAIT_DOWN:
56+
return "portraitDown";
57+
case LANDSCAPE_LEFT:
58+
return "landscapeLeft";
59+
case LANDSCAPE_RIGHT:
60+
return "landscapeRight";
61+
default:
62+
throw new UnsupportedOperationException(
63+
"Could not serialize device orientation: " + orientation.toString());
64+
}
65+
}
66+
67+
static PlatformChannel.DeviceOrientation deserializeDeviceOrientation(String orientation) {
68+
if (orientation == null)
69+
throw new UnsupportedOperationException("Could not deserialize null device orientation.");
70+
switch (orientation) {
71+
case "portraitUp":
72+
return PlatformChannel.DeviceOrientation.PORTRAIT_UP;
73+
case "portraitDown":
74+
return PlatformChannel.DeviceOrientation.PORTRAIT_DOWN;
75+
case "landscapeLeft":
76+
return PlatformChannel.DeviceOrientation.LANDSCAPE_LEFT;
77+
case "landscapeRight":
78+
return PlatformChannel.DeviceOrientation.LANDSCAPE_RIGHT;
79+
default:
80+
throw new UnsupportedOperationException(
81+
"Could not deserialize device orientation: " + orientation);
82+
}
83+
}
84+
3185
static Size computeBestPreviewSize(String cameraName, ResolutionPreset preset) {
3286
if (preset.ordinal() > ResolutionPreset.high.ordinal()) {
3387
preset = ResolutionPreset.high;

0 commit comments

Comments
 (0)