Allow camera to rotate even when screen is locked

Fixes #8611
Closes #12247

Signed-off-by: Felix Nüsse <felix.nuesse@t-online.de>
This commit is contained in:
Felix Nüsse
2022-05-14 22:33:04 +02:00
committed by Greyson Parrelli
parent 796e5f6f86
commit 9c7c94b2d4
2 changed files with 10 additions and 2 deletions

View File

@@ -110,6 +110,7 @@ public class Camera1Fragment extends LoggingFragment implements CameraFragment,
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
super.onViewCreated(view, savedInstanceState);
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
cameraPreview = view.findViewById(R.id.camera_preview);
controlsContainer = view.findViewById(R.id.camera_controls_container);
@@ -162,7 +163,7 @@ public class Camera1Fragment extends LoggingFragment implements CameraFragment,
});
orderEnforcer.run(Stage.CAMERA_PROPERTIES_AVAILABLE, this::updatePreviewScale);
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
@Override
@@ -172,6 +173,11 @@ public class Camera1Fragment extends LoggingFragment implements CameraFragment,
orderEnforcer.reset();
}
@Override public void onDestroy() {
super.onDestroy();
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
@Override
public void fadeOutControls(@NonNull Runnable onEndAction) {
controlsContainer.setEnabled(false);

View File

@@ -118,6 +118,7 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
@Override
public void onViewCreated(@NonNull View view, @Nullable Bundle savedInstanceState) {
ViewGroup cameraParent = view.findViewById(R.id.camerax_camera_parent);
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
this.camera = view.findViewById(R.id.camerax_camera);
this.controlsContainer = view.findViewById(R.id.camerax_controls_container);
@@ -155,13 +156,14 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
camera.bindToLifecycle(getViewLifecycleOwner(), this::handleCameraInitializationError);
requireActivity().getWindow().addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN);
requireActivity().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_FORCE_NOT_FULLSCREEN);
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR);
}
@Override
public void onDestroyView() {
super.onDestroyView();
closeVideoFileDescriptor();
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
}
@Override