Skip to content
Prev Previous commit
Next Next commit
remove unused code
  • Loading branch information
camsim99 committed Dec 11, 2024
commit afcd094d17d6b4d4d8b397d2567db3f9690b8209
Original file line number Diff line number Diff line change
Expand Up @@ -237,18 +237,6 @@ class AndroidCameraCameraX extends CameraPlatform {
@visibleForTesting
late bool cameraIsFrontFacing;

/// Whether or not the Surface used to create the camera preview is backed
/// by a SurfaceTexture.
@visibleForTesting
late bool isPreviewPreTransformed;

/// The initial orientation of the device.
///
/// The camera preview will use this orientation as the natural orientation
/// to correct its rotation with respect to, if necessary.
@visibleForTesting
DeviceOrientation? naturalOrientation;

/// The camera sensor orientation.
@visibleForTesting
late int sensorOrientation;
Expand Down Expand Up @@ -399,20 +387,7 @@ class AndroidCameraCameraX extends CameraPlatform {

final Camera2CameraInfo camera2CameraInfo =
await proxy.getCamera2CameraInfo(cameraInfo!);
await Future.wait(<Future<Object>>[
SystemServices.isPreviewPreTransformed()
.then((bool value) => isPreviewPreTransformed = value),
proxy
.getSensorOrientation(camera2CameraInfo)
.then((int value) => sensorOrientation = value),
proxy
.getUiOrientation()
.then((DeviceOrientation value) => naturalOrientation ??= value),
]);
_subscriptionForDeviceOrientationChanges = onDeviceOrientationChanged()
.listen((DeviceOrientationChangedEvent event) {
currentDeviceOrientation = event.orientation;
});
sensorOrientation = await proxy.getSensorOrientation(camera2CameraInfo);

return flutterSurfaceTextureId;
}
Expand Down Expand Up @@ -866,67 +841,6 @@ class AndroidCameraCameraX extends CameraPlatform {
}

return Texture(textureId: cameraId);
// final Map<DeviceOrientation, int> degreesForDeviceOrientation =
// <DeviceOrientation, int>{
// DeviceOrientation.portraitUp: 0,
// DeviceOrientation.landscapeRight: 90,
// DeviceOrientation.portraitDown: 180,
// DeviceOrientation.landscapeLeft: 270,
// };
// int naturalDeviceOrientationDegrees =
// degreesForDeviceOrientation[naturalOrientation]!;

// if (isPreviewPreTransformed) {
// // If the camera preview is backed by a SurfaceTexture, the transformation
// // needed to correctly rotate the preview has already been applied.
// // However, we may need to correct the camera preview rotation if the
// // device is naturally landscape-oriented.
// if (naturalOrientation == DeviceOrientation.landscapeLeft ||
// naturalOrientation == DeviceOrientation.landscapeRight) {
// final int quarterTurnsToCorrectForLandscape =
// (-naturalDeviceOrientationDegrees + 360) ~/ 4;
// return RotatedBox(
// quarterTurns: quarterTurnsToCorrectForLandscape,
// child: cameraPreview);
// }
// return cameraPreview;
// }

// // Fix for the rotation of the camera preview not backed by a SurfaceTexture
// // with respect to the naturalOrientation of the device:

// final int signForCameraDirection = cameraIsFrontFacing ? 1 : -1;

// if (signForCameraDirection == 1 &&
// (currentDeviceOrientation == DeviceOrientation.landscapeLeft ||
// currentDeviceOrientation == DeviceOrientation.landscapeRight)) {
// // For front-facing cameras, the image buffer is rotated counterclockwise,
// // so we determine the rotation needed to correct the camera preview with
// // respect to the naturalOrientation of the device based on the inverse of
// // naturalOrientation.
// naturalDeviceOrientationDegrees += 180;
// }

// // See https://developer.android.com/media/camera/camera2/camera-preview#orientation_calculation
// // for more context on this formula.
// final double rotation = (sensorOrientation +
// naturalDeviceOrientationDegrees * signForCameraDirection +
// 360) %
// 360;
// int quarterTurnsToCorrectPreview = rotation ~/ 90;

// if (naturalOrientation == DeviceOrientation.landscapeLeft ||
// naturalOrientation == DeviceOrientation.landscapeRight) {
// // We may need to correct the camera preview rotation if the device is
// // naturally landscape-oriented.
// quarterTurnsToCorrectPreview +=
// (-naturalDeviceOrientationDegrees + 360) ~/ 4;
// return RotatedBox(
// quarterTurns: quarterTurnsToCorrectPreview, child: cameraPreview);
// }

// return RotatedBox(
// quarterTurns: quarterTurnsToCorrectPreview, child: cameraPreview);
}

/// Captures an image and returns the file where it was saved.
Expand Down