This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Enable image capture, equivalent to cameraView.setCaptureMode(IMAGE) | |
| // CameraController's enabled use cases: Preview + ImageCapture | |
| cameraController.setEnabledUseCases(IMAGE_CAPTURE) | |
| // Enable image capture and image analysis | |
| // CameraController's enabled use cases: Preview + ImageCapture + ImageAnalysis | |
| cameraController.setEnabledUseCases(IMAGE_CAPTURE|IMAGE_ANALYSIS) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CameraView | CameraController | |
|---|---|---|
| getCaptureMode() | isImageCaptureEnabled() | |
| - | isImageAnalysisEnabled() | |
| setCaptureMode(CaptureMode) | setEnabledUseCases(int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| fun toggleCamera() { | |
| if (cameraController.cameraSelector == CameraSelector.DEFAULT_BACK_CAMERA | |
| && cameraController.hasCamera(CameraSelector.DEFAULT_FRONT_CAMERA) { | |
| cameraController.cameraSelector = CameraSelector.DEFAULT_FRONT_CAMERA | |
| } else if (cameraController.cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA | |
| && cameraController.hasCamera(CameraSelector.DEFAULT_BACK_CAMERA) { | |
| cameraController.cameraSelector = CameraSelector.DEFAULT_BACK_CAMERA | |
| } | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CameraView | LifecycleCameraController | |
|---|---|---|
| hasCameraWithLensFacing(int) | hasCamera(CameraSelector) | |
| setCameraLensFacing(Integer) | setCameraSelector(CameraSelector) | |
| getCameraLensFacing() | getCameraSelector() | |
| toggleCamera() | - |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CameraView | CameraController | |
|---|---|---|
| - | isTapToFocusEnabled() | |
| - | setTapToFocusEnabled(boolean) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CameraView | CameraController | |
|---|---|---|
| enableTorch(boolean) | enableTorch(boolean) | |
| isTorchOn() | getTorchState() | |
| getFlash() | getImageCaptureFlashMode() | |
| setFlash(int) | setImageCaptureFlashMode(int) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| val isZoomSupported = getZoomState().getValue().getMaxZoomRatio() != 1 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CameraView | CameraController | |
|---|---|---|
| isZoomSupported() | - | |
| isPinchToZoomEnabled() | isPinchToZoomEnabled() | |
| setPinchToZoomEnabled(Boolean) | setPinchToZoomEnabled(Boolean) | |
| getZoomRatio() | getZoomState().getZoomRatio() | |
| getMinZoomRatio() | getZoomState().getMinZoomRatio() | |
| getMaxZoomRatio() | getZoomState().getMaxZoomRatio() | |
| - | getZoomState().getLinearZoom() | |
| setZoomRatio(float) | setZoomRatio(float) | |
| - | setLinearZoom(float) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| CameraView | LifecycleCameraController | |
|---|---|---|
| bindToLifecycle(LifecycleOwner) | bindToLifecycle(LifecycleOwner) | |
| - | unbind() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Set up the CameraController | |
| val cameraController = LifecycleCameraController(context) | |
| cameraController.bindToLifecycle(lifecycleOwner) | |
| // Attach the CameraController to PreviewView | |
| val previewView = findViewById(R.id.preview_view) | |
| previewView.setController(cameraController) | |
| // Use the CameraController | |
| cameraController.takePicture(…) |