Make in-app camera compatible with multi-window.

This commit is contained in:
Nicholas Tinsley
2024-03-29 16:27:45 -04:00
parent b1944da58d
commit 16402e43a5
2 changed files with 6 additions and 24 deletions

View File

@@ -198,24 +198,6 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
}
});
}
view.addOnLayoutChangeListener((v, left, top, right, bottom, oldLeft, oldTop, oldRight, oldBottom) -> {
// Let's assume portrait for now, so 9:16
float aspectRatio = CameraFragment.getAspectRatioForOrientation(Configuration.ORIENTATION_PORTRAIT);
float width = right - left;
float height = Math.min((1f / aspectRatio) * width, bottom - top);
ViewGroup.LayoutParams params = cameraParent.getLayoutParams();
// If there's a mismatch...
if (params.height != (int) height) {
params.width = (int) width;
params.height = (int) height;
cameraParent.setLayoutParams(params);
cameraController.setPreviewTargetSize(new Size((int) width, (int) height));
}
});
}
@Override
@@ -234,10 +216,7 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
public void onResume() {
super.onResume();
if (FeatureFlags.customCameraXController()) {
cameraController.bindToLifecycle(getViewLifecycleOwner(), () -> Log.d(TAG, "Camera init complete from onResume"));
}
cameraController.bindToLifecycle(getViewLifecycleOwner(), () -> Log.d(TAG, "Camera init complete from onResume"));
requireActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
}

View File

@@ -8,10 +8,13 @@
<com.google.android.material.card.MaterialCardView
android:id="@+id/camerax_camera_parent"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_height="0dp"
app:cardCornerRadius="18dp"
app:cardElevation="0dp"
app:layout_constraintDimensionRatio="9:16"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent">
<androidx.camera.view.PreviewView