public final class

PreviewConfig.Builder

extends java.lang.Object

implements UseCaseConfig.Builder<Preview, PreviewConfig, PreviewConfig.Builder>, ImageOutputConfig.Builder<PreviewConfig.Builder>, CameraDeviceConfig.Builder<PreviewConfig.Builder>, androidx.camera.core.ThreadConfig.Builder<PreviewConfig.Builder>

 java.lang.Object

↳androidx.camera.core.PreviewConfig.Builder

Overview

Builder for a PreviewConfig.

Summary

Constructors
publicBuilder()

Creates a new Builder object.

Methods
public PreviewConfigbuild()

Builds an immutable PreviewConfig from the current state.

public static PreviewConfig.BuilderfromConfig(PreviewConfig configuration)

Generates a Builder from another Config object

public MutableConfiggetMutableConfig()

public PreviewConfig.BuildersetBackgroundExecutor(java.util.concurrent.Executor executor)

Sets the default executor that will be used for background tasks.

public PreviewConfig.BuildersetCameraIdFilter(CameraIdFilter cameraIdFilter)

Sets a CameraIdFilter that filter out the unavailable camera id.

public PreviewConfig.BuildersetCaptureOptionUnpacker(CaptureConfig.OptionUnpacker optionUnpacker)

public PreviewConfig.BuildersetCaptureProcessor(CaptureProcessor captureProcessor)

Sets the CaptureProcessor.

public PreviewConfig.BuildersetDefaultCaptureConfig(CaptureConfig captureConfig)

public PreviewConfig.BuildersetDefaultResolution(Size resolution)

Sets the default resolution of the intended target from this configuration.

public PreviewConfig.BuildersetDefaultSessionConfig(SessionConfig sessionConfig)

public PreviewConfig.BuildersetImageInfoProcessor(ImageInfoProcessor processor)

public PreviewConfig.BuildersetLensFacing(androidx.camera.core.CameraX.LensFacing lensFacing)

Sets the primary camera to be configured based on the direction the lens is facing.

public PreviewConfig.BuildersetMaxResolution(Size resolution)

public PreviewConfig.BuildersetSessionOptionUnpacker(SessionConfig.OptionUnpacker optionUnpacker)

public PreviewConfig.BuildersetSupportedResolutions(java.util.List<> resolutions)

public PreviewConfig.BuildersetSurfaceOccupancyPriority(int priority)

public PreviewConfig.BuildersetTargetAspectRatio(AspectRatio aspectRatio)

Sets the aspect ratio of the intended target for images from this configuration.

public PreviewConfig.BuildersetTargetAspectRatioCustom(Rational aspectRatio)

Sets the aspect ratio of the intended target for images from this configuration.

public PreviewConfig.BuildersetTargetClass(java.lang.Class<Preview> targetClass)

public PreviewConfig.BuildersetTargetName(java.lang.String targetName)

Sets the name of the target object being configured.

public PreviewConfig.BuildersetTargetResolution(Size resolution)

Sets the resolution of the intended target from this configuration.

public PreviewConfig.BuildersetTargetRotation(int rotation)

Sets the rotation of the intended target for images from this configuration.

public PreviewConfig.BuildersetUseCaseEventListener(androidx.camera.core.UseCase.EventListener useCaseEventListener)

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public Builder()

Creates a new Builder object.

Methods

public static PreviewConfig.Builder fromConfig(PreviewConfig configuration)

Generates a Builder from another Config object

Parameters:

configuration: An immutable configuration to pre-populate this builder.

Returns:

The new Builder.

public MutableConfig getMutableConfig()

public PreviewConfig build()

Builds an immutable PreviewConfig from the current state.

Returns:

A PreviewConfig populated with the current state.

public PreviewConfig.Builder setTargetClass(java.lang.Class<Preview> targetClass)

public PreviewConfig.Builder setTargetName(java.lang.String targetName)

Sets the name of the target object being configured.

The name should be a value that can uniquely identify an instance of the object being configured.

Parameters:

targetName: A unique string identifier for the instance of the class being configured.

Returns:

the current Builder.

public PreviewConfig.Builder setLensFacing(androidx.camera.core.CameraX.LensFacing lensFacing)

Sets the primary camera to be configured based on the direction the lens is facing.

If multiple cameras exist with equivalent lens facing direction, the first ("primary") camera for that direction will be chosen.

Parameters:

lensFacing: The direction of the camera's lens.

Returns:

the current Builder.

public PreviewConfig.Builder setCameraIdFilter(CameraIdFilter cameraIdFilter)

Sets a CameraIdFilter that filter out the unavailable camera id.

The camera id filter will be used to filter those cameras with lens facing specified in the config.

Parameters:

cameraIdFilter: The CameraIdFilter.

Returns:

the current Builder.

public PreviewConfig.Builder setTargetAspectRatioCustom(Rational aspectRatio)

Sets the aspect ratio of the intended target for images from this configuration.

This is the ratio of the target's width to the image's height, where the numerator of the provided corresponds to the width, and the denominator corresponds to the height.

The target aspect ratio is used as a hint when determining the resulting output aspect ratio which may differ from the request, possibly due to device constraints. Application code should check the resulting output's resolution.

This method can be used to request an aspect ratio that is not from the standard set of aspect ratios defined in the AspectRatio.

This method will remove any value set by setTargetAspectRatio().

For Preview, the output is the SurfaceTexture of the .

Parameters:

aspectRatio: A representing the ratio of the target's width and height.

Returns:

The current Builder.

public PreviewConfig.Builder setTargetAspectRatio(AspectRatio aspectRatio)

Sets the aspect ratio of the intended target for images from this configuration.

It is not allowed to set both target aspect ratio and target resolution on the same use case.

The target aspect ratio is used as a hint when determining the resulting output aspect ratio which may differ from the request, possibly due to device constraints. Application code should check the resulting output's resolution.

For Preview, the output is the SurfaceTexture of the .

Parameters:

aspectRatio: A AspectRatio representing the ratio of the target's width and height.

Returns:

The current Builder.

public PreviewConfig.Builder setTargetRotation(int rotation)

Sets the rotation of the intended target for images from this configuration.

This is one of four valid values: , , , . Rotation values are relative to the "natural" rotation, .

Parameters:

rotation: The rotation of the intended target.

Returns:

The current Builder.

public PreviewConfig.Builder setTargetResolution(Size resolution)

Sets the resolution of the intended target from this configuration.

The target resolution attempts to establish a minimum bound for the preview resolution. The actual preview resolution will be the closest available resolution in size that is not smaller than the target resolution, as determined by the Camera implementation. However, if no resolution exists that is equal to or larger than the target resolution, the nearest available resolution smaller than the target resolution will be chosen.

It is not allowed to set both target aspect ratio and target resolution on the same use case.

The target aspect ratio will also be set the same as the aspect ratio of the provided . Make sure to set the target resolution with the correct orientation.

Parameters:

resolution: The target resolution to choose from supported output sizes list.

Returns:

The current Builder.

public PreviewConfig.Builder setDefaultResolution(Size resolution)

Sets the default resolution of the intended target from this configuration.

Parameters:

resolution: The default resolution to choose from supported output sizes list.

Returns:

The current Builder.

public PreviewConfig.Builder setMaxResolution(Size resolution)

public PreviewConfig.Builder setSupportedResolutions(java.util.List<> resolutions)

public PreviewConfig.Builder setBackgroundExecutor(java.util.concurrent.Executor executor)

Sets the default executor that will be used for background tasks.

Parameters:

executor: The executor which will be used for background tasks.

Returns:

the current Builder.

public PreviewConfig.Builder setDefaultSessionConfig(SessionConfig sessionConfig)

public PreviewConfig.Builder setDefaultCaptureConfig(CaptureConfig captureConfig)

public PreviewConfig.Builder setSessionOptionUnpacker(SessionConfig.OptionUnpacker optionUnpacker)

public PreviewConfig.Builder setCaptureOptionUnpacker(CaptureConfig.OptionUnpacker optionUnpacker)

public PreviewConfig.Builder setSurfaceOccupancyPriority(int priority)

public PreviewConfig.Builder setUseCaseEventListener(androidx.camera.core.UseCase.EventListener useCaseEventListener)

public PreviewConfig.Builder setImageInfoProcessor(ImageInfoProcessor processor)

public PreviewConfig.Builder setCaptureProcessor(CaptureProcessor captureProcessor)

Sets the CaptureProcessor.

Parameters:

captureProcessor: The requested capture processor for extension.

Returns:

The current Builder.