Skip to content

Instantly share code, notes, and snippets.

View husaynhakeem's full-sized avatar

Husayn Hakeem husaynhakeem

View GitHub Profile
// 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)
CameraView CameraController
getCaptureMode() isImageCaptureEnabled()
- isImageAnalysisEnabled()
setCaptureMode(CaptureMode) setEnabledUseCases(int)
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
}
}
CameraView LifecycleCameraController
hasCameraWithLensFacing(int) hasCamera(CameraSelector)
setCameraLensFacing(Integer) setCameraSelector(CameraSelector)
getCameraLensFacing() getCameraSelector()
toggleCamera() -
CameraView CameraController
- isTapToFocusEnabled()
- setTapToFocusEnabled(boolean)
CameraView CameraController
enableTorch(boolean) enableTorch(boolean)
isTorchOn() getTorchState()
getFlash() getImageCaptureFlashMode()
setFlash(int) setImageCaptureFlashMode(int)
val isZoomSupported = getZoomState().getValue().getMaxZoomRatio() != 1
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)
CameraView LifecycleCameraController
bindToLifecycle(LifecycleOwner) bindToLifecycle(LifecycleOwner)
- unbind()
// 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(…)