CameraController

public abstract class CameraController
extends Object

java.lang.Object
   ↳ androidx.camera.view.CameraController


The abstract base camera controller class.

This a high level controller that provides most of the CameraX core features in a single class. It handles camera initialization, creates and configures UseCases. It also listens to device motion sensor and set the target rotation for the use cases.

The controller is required to be used with a PreviewView. PreviewView provides the UI elements to display camera preview. The layout of the PreviewView is used to set the crop rect so the output from other use cases matches the preview display in a WYSIWYG way. The controller also listens to PreviewView's touch events to handle tap-to-focus and pinch-to-zoom features.

This class provides features of 4 UseCases: Preview, ImageCapture, ImageAnalysis and an experimental video capture. Preview is required and always enabled. ImageCapture and ImageAnalysis are enabled by default. The video capture feature is experimental. It's disabled by default because it might conflict with other use cases, especially on lower end devices. It might be necessary to disable ImageCapture and/or ImageAnalysis before the video capture feature can be enabled. Disabling/enabling UseCases freezes the preview for a short period of time. To avoid the glitch, the UseCases need to be enabled/disabled before the controller is set on PreviewView.

Summary

Nested classes

class CameraController.OutputSize

Represents the output size of a UseCase

Constants

int IMAGE_ANALYSIS

Bitmask option to enable ImageAnalysis.

int IMAGE_CAPTURE

Bitmask option to enable ImageCapture.

int TAP_TO_FOCUS_FAILED

The previous tap-to-focus action was failed to complete.

int TAP_TO_FOCUS_FOCUSED

The previous tap-to-focus action was completed successfully and the camera is focused.

int TAP_TO_FOCUS_NOT_FOCUSED

The previous tap-to-focus action was completed successfully but the camera is still unfocused, similar to the CameraMetadata.CONTROL_AF_STATE_NOT_FOCUSED_LOCKED state.

int TAP_TO_FOCUS_NOT_STARTED

No tap-to-focus action has been started by the end user.

int TAP_TO_FOCUS_STARTED

A tap-to-focus action has started but not completed.

int VIDEO_CAPTURE

Bitmask option to enable video capture use case.

Public methods

void clearImageAnalysisAnalyzer()

Removes a previously set analyzer.

ListenableFuture<Void> enableTorch(boolean torchEnabled)

Enable the torch or disable the torch.

CameraControl getCameraControl()

Gets the CameraControl of the currently attached camera.

CameraInfo getCameraInfo()

Gets the CameraInfo of the currently attached camera.

CameraSelector getCameraSelector()

Gets the CameraSelector.

Executor getImageAnalysisBackgroundExecutor()

Gets the default executor for ImageAnalysis background tasks.

int getImageAnalysisBackpressureStrategy()

Returns the mode with which images are acquired.

int getImageAnalysisImageQueueDepth()

Gets the image queue depth of ImageAnalysis.

CameraController.OutputSize getImageAnalysisTargetSize()

Returns the intended output size for ImageAnalysis set by setImageAnalysisTargetSize(OutputSize), or null if not set.

int getImageCaptureFlashMode()

Gets the flash mode for ImageCapture.

Executor getImageCaptureIoExecutor()

Gets the default executor for ImageCapture IO tasks.

int getImageCaptureMode()

Returns the image capture mode.

CameraController.OutputSize getImageCaptureTargetSize()

Returns the intended output size for ImageCapture set by setImageCaptureTargetSize(OutputSize), or null if not set.

ListenableFuture<Void> getInitializationFuture()

Gets a ListenableFuture that completes when camera initialization completes.

CameraController.OutputSize getPreviewTargetSize()

Returns the intended output size for Preview set by setPreviewTargetSize(OutputSize), or null if not set.

LiveData<Integer> getTapToFocusState()

Returns a LiveData with the latest tap-to-focus state.

LiveData<Integer> getTorchState()

Returns a LiveData of current TorchState.

CameraController.OutputSize getVideoCaptureTargetSize()

Returns the intended output size for VideoCapture set by setVideoCaptureTargetSize(OutputSize), or null if not set.

LiveData<ZoomState> getZoomState()

Returns a LiveData of ZoomState.

boolean hasCamera(CameraSelector cameraSelector)

Checks if the given CameraSelector can be resolved