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

Commit

Permalink
Update version number
Browse files Browse the repository at this point in the history
  • Loading branch information
mvanbeusekom committed Jan 14, 2021
2 parents 00124f4 + 6d18db8 commit 7e152b8
Show file tree
Hide file tree
Showing 57 changed files with 2,030 additions and 242 deletions.
4 changes: 4 additions & 0 deletions packages/battery/battery/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.0.0-nullsafety

* Migrate to null safety.

## 1.0.11

* Update the example app: remove the deprecated `RaisedButton` and `FlatButton` widgets.
Expand Down
8 changes: 4 additions & 4 deletions packages/battery/battery/example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class MyApp extends StatelessWidget {
}

class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
MyHomePage({Key? key, required this.title}) : super(key: key);

final String title;

Expand All @@ -36,10 +36,10 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {
Battery _battery = Battery();
final Battery _battery = Battery();

BatteryState _batteryState;
StreamSubscription<BatteryState> _batteryStateSubscription;
BatteryState? _batteryState;
late StreamSubscription<BatteryState> _batteryStateSubscription;

@override
void initState() {
Expand Down
4 changes: 2 additions & 2 deletions packages/battery/battery/example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,11 @@ dev_dependencies:
sdk: flutter
integration_test:
path: ../../../integration_test
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety

flutter:
uses-material-design: true

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5 <2.0.0"
2 changes: 2 additions & 0 deletions packages/battery/battery/integration_test/battery_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

// @dart = 2.9

import 'package:flutter_test/flutter_test.dart';
import 'package:battery/battery.dart';
import 'package:integration_test/integration_test.dart';
Expand Down
16 changes: 7 additions & 9 deletions packages/battery/battery/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name: battery
description: Flutter plugin for accessing information about the battery state
(full, charging, discharging) on Android and iOS.
homepage: https://github.com/flutter/plugins/tree/master/packages/battery/battery
version: 1.0.11
version: 2.0.0-nullsafety

flutter:
plugin:
Expand All @@ -16,20 +16,18 @@ flutter:
dependencies:
flutter:
sdk: flutter
meta: ^1.0.5
battery_platform_interface: ^1.0.0
meta: ^1.3.0-nullsafety
battery_platform_interface: ^2.0.0-nullsafety

dev_dependencies:
async: ^2.0.8
test: ^1.3.0
mockito: ^4.1.1
mockito: ^5.0.0-nullsafety.0
flutter_test:
sdk: flutter
plugin_platform_interface: ^1.0.0
plugin_platform_interface: ^1.1.0-nullsafety
integration_test:
path: ../../integration_test
pedantic: ^1.8.0
pedantic: ^1.10.0-nullsafety

environment:
sdk: ">=2.1.0 <3.0.0"
sdk: ">=2.12.0-0 <3.0.0"
flutter: ">=1.12.13+hotfix.5"
4 changes: 2 additions & 2 deletions packages/battery/battery/test/battery_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@
import 'dart:async';

import 'package:battery_platform_interface/battery_platform_interface.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:plugin_platform_interface/plugin_platform_interface.dart';
import 'package:test/test.dart';
import 'package:battery/battery.dart';
import 'package:mockito/mockito.dart';

void main() {
group('battery', () {
Battery battery;
late Battery battery;
MockBatteryPlatform fakePlatform;
setUp(() async {
fakePlatform = MockBatteryPlatform();
Expand Down
16 changes: 14 additions & 2 deletions packages/camera/camera/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
## 0.6.6+1
## 0.7.0+2

* 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.

## 0.7.0+1

* Fixes picture captures causing a crash on some Huawei devices.

## 0.7.0

* Added support for capture orientation locking on Android and iOS.
* Fixed camera preview not rotating correctly on Android and iOS.
* Fixed camera preview sometimes appearing stretched on Android and iOS.
* Fixed videos & photos saving with the incorrect rotation on iOS.
* BREAKING CHANGE: `CameraValue.aspectRatio` now returns `width / height` rather than `height / width`.

## 0.6.6

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

## 0.6.4+2

* Set ImageStreamReader listener to null to prevent stale images when streaming images.
* Set ImageStreamReader listener to null to prevent stale images when streaming images.

## 0.6.4+1

Expand Down
2 changes: 1 addition & 1 deletion packages/camera/camera/android/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ project.getTasks().withType(JavaCompile){
apply plugin: 'com.android.library'

android {
compileSdkVersion 29
compileSdkVersion 30

defaultConfig {
minSdkVersion 21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

package io.flutter.plugins.camera;

import static android.view.OrientationEventListener.ORIENTATION_UNKNOWN;
import static io.flutter.plugins.camera.CameraUtils.computeBestPreviewSize;

import android.annotation.SuppressLint;
Expand Down Expand Up @@ -41,10 +40,10 @@
import android.util.Range;
import android.util.Rational;
import android.util.Size;
import android.view.OrientationEventListener;
import android.view.Surface;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
import io.flutter.plugin.common.EventChannel;
import io.flutter.plugin.common.MethodChannel.Result;
import io.flutter.plugins.camera.PictureCaptureRequest.State;
Expand Down Expand Up @@ -76,7 +75,7 @@ public class Camera {

private final SurfaceTextureEntry flutterTexture;
private final CameraManager cameraManager;
private final OrientationEventListener orientationEventListener;
private final DeviceOrientationManager deviceOrientationListener;
private final boolean isFrontFacing;
private final int sensorOrientation;
private final String cameraName;
Expand All @@ -97,7 +96,6 @@ public class Camera {
private MediaRecorder mediaRecorder;
private boolean recordingVideo;
private File videoRecordingFile;
private int currentOrientation = ORIENTATION_UNKNOWN;
private FlashMode flashMode;
private ExposureMode exposureMode;
private FocusMode focusMode;
Expand All @@ -106,6 +104,7 @@ public class Camera {
private int exposureOffset;
private boolean useAutoFocus = true;
private Range<Integer> fpsRange;
private PlatformChannel.DeviceOrientation lockedCaptureOrientation;

private static final HashMap<String, Integer> supportedImageFormats;
// Current supported outputs
Expand Down Expand Up @@ -136,18 +135,6 @@ public Camera(
this.exposureMode = ExposureMode.auto;
this.focusMode = FocusMode.auto;
this.exposureOffset = 0;
orientationEventListener =
new OrientationEventListener(activity.getApplicationContext()) {
@Override
public void onOrientationChanged(int i) {
if (i == ORIENTATION_UNKNOWN) {
return;
}
// Convert the raw deg angle to the nearest multiple of 90.
currentOrientation = (int) Math.round(i / 90.0) * 90;
}
};
orientationEventListener.enable();

cameraCharacteristics = cameraManager.getCameraCharacteristics(cameraName);
initFps(cameraCharacteristics);
Expand All @@ -164,6 +151,10 @@ public void onOrientationChanged(int i) {
new CameraZoom(
cameraCharacteristics.get(CameraCharacteristics.SENSOR_INFO_ACTIVE_ARRAY_SIZE),
cameraCharacteristics.get(CameraCharacteristics.SCALER_AVAILABLE_MAX_DIGITAL_ZOOM));

deviceOrientationListener =
new DeviceOrientationManager(activity, dartMessenger, isFrontFacing, sensorOrientation);
deviceOrientationListener.start();
}

private void initFps(CameraCharacteristics cameraCharacteristics) {
Expand Down Expand Up @@ -195,7 +186,10 @@ private void prepareMediaRecorder(String outputFilePath) throws IOException {
mediaRecorder =
new MediaRecorderBuilder(recordingProfile, outputFilePath)
.setEnableAudio(enableAudio)
.setMediaOrientation(getMediaOrientation())
.setMediaOrientation(
lockedCaptureOrientation == null
? deviceOrientationListener.getMediaOrientation()
: deviceOrientationListener.getMediaOrientation(lockedCaptureOrientation))
.build();
}

Expand Down Expand Up @@ -464,17 +458,20 @@ public void onCaptureFailed(
return;
}
String reason;
boolean fatalFailure = false;
switch (failure.getReason()) {
case CaptureFailure.REASON_ERROR:
reason = "An error happened in the framework";
break;
case CaptureFailure.REASON_FLUSHED:
reason = "The capture has failed due to an abortCaptures() call";
fatalFailure = true;
break;
default:
reason = "Unknown reason";
}
pictureCaptureRequest.error("captureFailure", reason, null);
Log.w("Camera", "pictureCaptureCallback.onCaptureFailed(): " + reason);
if (fatalFailure) pictureCaptureRequest.error("captureFailure", reason, null);
}

private void processCapture(CaptureResult result) {
Expand Down Expand Up @@ -548,7 +545,11 @@ private void runPictureCapture() {
captureBuilder.set(
CaptureRequest.SCALER_CROP_REGION,
captureRequestBuilder.get(CaptureRequest.SCALER_CROP_REGION));
captureBuilder.set(CaptureRequest.JPEG_ORIENTATION, getMediaOrientation());
captureBuilder.set(
CaptureRequest.JPEG_ORIENTATION,
lockedCaptureOrientation == null
? deviceOrientationListener.getMediaOrientation()
: deviceOrientationListener.getMediaOrientation(lockedCaptureOrientation));
switch (flashMode) {
case off:
captureBuilder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
Expand Down Expand Up @@ -971,6 +972,14 @@ public void setZoomLevel(@NonNull final Result result, float zoom) throws Camera
result.success(null);
}

public void lockCaptureOrientation(PlatformChannel.DeviceOrientation orientation) {
this.lockedCaptureOrientation = orientation;
}

public void unlockCaptureOrientation() {
this.lockedCaptureOrientation = null;
}

private void updateFpsRange() {
if (fpsRange == null) {
return;
Expand Down Expand Up @@ -1163,14 +1172,6 @@ public void close() {
public void dispose() {
close();
flutterTexture.release();
orientationEventListener.disable();
}

private int getMediaOrientation() {
final int sensorOrientationOffset =
(currentOrientation == ORIENTATION_UNKNOWN)
? 0
: (isFrontFacing) ? -currentOrientation : currentOrientation;
return (sensorOrientationOffset + sensorOrientation + 360) % 360;
deviceOrientationListener.stop();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.hardware.camera2.params.StreamConfigurationMap;
import android.media.CamcorderProfile;
import android.util.Size;
import io.flutter.embedding.engine.systemchannels.PlatformChannel;
import io.flutter.plugins.camera.types.ResolutionPreset;
import java.util.ArrayList;
import java.util.Arrays;
Expand All @@ -28,6 +29,59 @@ public final class CameraUtils {

private CameraUtils() {}

static PlatformChannel.DeviceOrientation getDeviceOrientationFromDegrees(int degrees) {
// Round to the nearest 90 degrees.
degrees = (int) (Math.round(degrees / 90.0) * 90) % 360;
// Determine the corresponding device orientation.
switch (degrees) {
case 90:
return PlatformChannel.DeviceOrientation.LANDSCAPE_LEFT;
case 180:
return PlatformChannel.DeviceOrientation.PORTRAIT_DOWN;
case 270:
return PlatformChannel.DeviceOrientation.LANDSCAPE_RIGHT;
case 0:
default:
return PlatformChannel.DeviceOrientation.PORTRAIT_UP;
}
}

static String serializeDeviceOrientation(PlatformChannel.DeviceOrientation orientation) {
if (orientation == null)
throw new UnsupportedOperationException("Could not serialize null device orientation.");
switch (orientation) {
case PORTRAIT_UP:
return "portraitUp";
case PORTRAIT_DOWN:
return "portraitDown";
case LANDSCAPE_LEFT:
return "landscapeLeft";
case LANDSCAPE_RIGHT:
return "landscapeRight";
default:
throw new UnsupportedOperationException(
"Could not serialize device orientation: " + orientation.toString());
}
}

static PlatformChannel.DeviceOrientation deserializeDeviceOrientation(String orientation) {
if (orientation == null)
throw new UnsupportedOperationException("Could not deserialize null device orientation.");
switch (orientation) {
case "portraitUp":
return PlatformChannel.DeviceOrientation.PORTRAIT_UP;
case "portraitDown":
return PlatformChannel.DeviceOrientation.PORTRAIT_DOWN;
case "landscapeLeft":
return PlatformChannel.DeviceOrientation.LANDSCAPE_LEFT;
case "landscapeRight":
return PlatformChannel.DeviceOrientation.LANDSCAPE_RIGHT;
default:
throw new UnsupportedOperationException(
"Could not deserialize device orientation: " + orientation);
}
}

static Size computeBestPreviewSize(String cameraName, ResolutionPreset preset) {
if (preset.ordinal() > ResolutionPreset.high.ordinal()) {
preset = ResolutionPreset.high;
Expand Down
Loading

0 comments on commit 7e152b8

Please sign in to comment.