Returns one of 0, 90, 180 or 270. * - * @return The device's video orientation in degrees. + * @return The device's video orientation in clockwise degrees. */ public int getVideoOrientation() { return this.getVideoOrientation(this.lastOrientation); } /** - * Returns the device's video orientation in degrees based on the sensor orientation and the - * supplied {@link PlatformChannel.DeviceOrientation} value. + * Returns the device's video orientation in clockwise degrees based on the sensor orientation and + * the supplied {@link PlatformChannel.DeviceOrientation} value. * *
Returns one of 0, 90, 180 or 270. * + *
More details can be found in the official Android documentation: + * https://developer.android.com/reference/android/media/MediaRecorder#setOrientationHint(int) + * + *
See also:
+ * https://developer.android.com/training/camera2/camera-preview-large-screens#orientation_calculation
+ *
* @param orientation The {@link PlatformChannel.DeviceOrientation} value that is to be converted
* into degrees.
- * @return The device's video orientation in degrees.
+ * @return The device's video orientation in clockwise degrees.
*/
public int getVideoOrientation(PlatformChannel.DeviceOrientation orientation) {
int angle = 0;
@@ -179,10 +185,10 @@ public int getVideoOrientation(PlatformChannel.DeviceOrientation orientation) {
angle = 180;
break;
case LANDSCAPE_LEFT:
- angle = 90;
+ angle = 270;
break;
case LANDSCAPE_RIGHT:
- angle = 270;
+ angle = 90;
break;
}
diff --git a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java
index 82449a10188a..3762006f46d4 100644
--- a/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java
+++ b/packages/camera/camera/android/src/test/java/io/flutter/plugins/camera/features/sensororientation/DeviceOrientationManagerTest.java
@@ -62,9 +62,9 @@ public void getVideoOrientation_whenNaturalScreenOrientationEqualsPortraitUp() {
deviceOrientationManager.getVideoOrientation(DeviceOrientation.LANDSCAPE_RIGHT);
assertEquals(0, degreesPortraitUp);
- assertEquals(90, degreesLandscapeLeft);
+ assertEquals(270, degreesLandscapeLeft);
assertEquals(180, degreesPortraitDown);
- assertEquals(270, degreesLandscapeRight);
+ assertEquals(90, degreesLandscapeRight);
}
@Test
@@ -81,18 +81,30 @@ public void getVideoOrientation_whenNaturalScreenOrientationEqualsLandscapeLeft(
orientationManager.getVideoOrientation(DeviceOrientation.LANDSCAPE_RIGHT);
assertEquals(90, degreesPortraitUp);
- assertEquals(180, degreesLandscapeLeft);
+ assertEquals(0, degreesLandscapeLeft);
assertEquals(270, degreesPortraitDown);
- assertEquals(0, degreesLandscapeRight);
+ assertEquals(180, degreesLandscapeRight);
}
@Test
- public void getVideoOrientation_shouldFallbackToSensorOrientationWhenOrientationIsNull() {
- setUpUIOrientationMocks(Configuration.ORIENTATION_LANDSCAPE, Surface.ROTATION_0);
+ public void getVideoOrientation_fallbackToPortraitSensorOrientationWhenOrientationIsNull() {
+ setUpUIOrientationMocks(Configuration.ORIENTATION_PORTRAIT, Surface.ROTATION_0);
int degrees = deviceOrientationManager.getVideoOrientation(null);
- assertEquals(90, degrees);
+ assertEquals(0, degrees);
+ }
+
+ @Test
+ public void getVideoOrientation_fallbackToLandscapeSensorOrientationWhenOrientationIsNull() {
+ setUpUIOrientationMocks(Configuration.ORIENTATION_LANDSCAPE, Surface.ROTATION_0);
+
+ DeviceOrientationManager orientationManager =
+ DeviceOrientationManager.create(mockActivity, mockDartMessenger, false, 90);
+
+ int degrees = orientationManager.getVideoOrientation(null);
+
+ assertEquals(0, degrees);
}
@Test
diff --git a/packages/camera/camera/example/build.excerpt.yaml b/packages/camera/camera/example/build.excerpt.yaml
new file mode 100644
index 000000000000..e317efa11cb3
--- /dev/null
+++ b/packages/camera/camera/example/build.excerpt.yaml
@@ -0,0 +1,15 @@
+targets:
+ $default:
+ sources:
+ include:
+ - lib/**
+ # Some default includes that aren't really used here but will prevent
+ # false-negative warnings:
+ - $package$
+ - lib/$lib$
+ exclude:
+ - '**/.*/**'
+ - '**/build/**'
+ builders:
+ code_excerpter|code_excerpter:
+ enabled: true
diff --git a/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj b/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj
index 6c171505a8ca..37f56d0ed52e 100644
--- a/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj
+++ b/packages/camera/camera/example/ios/Runner.xcodeproj/project.pbxproj
@@ -15,6 +15,7 @@
25C3919135C3D981E6F800D0 /* libPods-RunnerTests.a in Frameworks */ = {isa = PBXBuildFile; fileRef = 1944D8072499F3B5E7653D44 /* libPods-RunnerTests.a */; };
334733EA2668111C00DCC49E /* CameraOrientationTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 03BB767226653ABE00CE5A93 /* CameraOrientationTests.m */; };
3B3967161E833CAA004F5970 /* AppFrameworkInfo.plist in Resources */ = {isa = PBXBuildFile; fileRef = 3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */; };
+ 788A065A27B0E02900533D74 /* StreamingTest.m in Sources */ = {isa = PBXBuildFile; fileRef = 788A065927B0E02900533D74 /* StreamingTest.m */; };
978B8F6F1D3862AE00F588F7 /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 7AFFD8EE1D35381100E5BB4D /* AppDelegate.m */; };
97C146F31CF9000F007C117D /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = 97C146F21CF9000F007C117D /* main.m */; };
97C146FC1CF9000F007C117D /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 97C146FA1CF9000F007C117D /* Main.storyboard */; };
@@ -70,6 +71,7 @@
1944D8072499F3B5E7653D44 /* libPods-RunnerTests.a */ = {isa = PBXFileReference; explicitFileType = archive.ar; includeInIndex = 0; path = "libPods-RunnerTests.a"; sourceTree = BUILT_PRODUCTS_DIR; };
3B3967151E833CAA004F5970 /* AppFrameworkInfo.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = AppFrameworkInfo.plist; path = Flutter/AppFrameworkInfo.plist; sourceTree = "