CameraXConfig

@RequiresApi(value = 21)
class CameraXConfig


A configuration for adding implementation and user-specific behavior to CameraX.

CameraXConfig provides customizable options for camera provider instances that persist for the lifetime of the provider.

An implementation of CameraXConfig can be provided by subclassing the Application object and implementing CameraXConfig.Provider. Alternatively, other methods configuration exist such as configureInstance. Examples of how this is used can be found in the androidx.camera.lifecycle package.

Applications can create and use the implementation of CameraXConfig provided in androidx.camera.camera2.

Summary

Nested types

A builder for generating CameraXConfig objects.

An interface which can be implemented to provide the configuration for CameraX.

Public functions

Boolean

Returns whether this configuration contains the supplied option.

Unit
findOptions(idSearchString: String, matcher: Config.OptionMatcher)

Search the configuration for Options whose id match the supplied search string.

CameraSelector?

Returns the CameraSelector used to determine the available cameras.

Executor?
getCameraExecutor(valueIfMissing: Executor?)

Returns the camera executor which CameraX will use to drive the camera stack.

Long

Returns the camera open retry maximum timeout in milliseconds when in active resuming mode.

Int

Returns the minimum logging level to be used for CameraX logs.

Config.OptionPriority

Returns the current priority of the value for the specified option.

(Mutable)Set<Config.OptionPriority!>

Returns a Set of all priorities set for the specified option.

Handler?
getSchedulerHandler(valueIfMissing: Handler?)

Returns the scheduling handler that CameraX will use internally for scheduling future tasks.

Class<T!>

Retrieves the class of the object being configured.

Class<T!>?
getTargetClass(valueIfMissing: Class<T!>?)

Retrieves the class of the object being configured.

String

Retrieves the name of the target object being configured.

String?
getTargetName(valueIfMissing: String?)

Retrieves the name of the target object being configured.

java-static Boolean
hasConflict(
    priority1: Config.OptionPriority,
    priority2: Config.OptionPriority
)

Returns if values with these OptionPriority conflict or not.

(Mutable)Set<Config.Option<Any!>!>

Lists all options contained within this configuration.

java-static Config
mergeConfigs(extendedConfig: Config?, baseConfig: Config?)

Merges two configs.

java-static Unit
mergeOptionValue(
    mergedConfig: MutableOptionsBundle,
    baseConfig: Config,
    extendedConfig: Config,
    opt: Config.Option<Any!>
)

Merges a specific option value from two configs.

ValueT?
<ValueT> retrieveOption(id: Config.Option<ValueT!>)

Retrieves the value for the specified option if it exists in the configuration.

abstract ValueT?
<ValueT> retrieveOption(id: Config.Option<ValueT!>, valueIfMissing: ValueT?)

Retrieves the value for the specified option if it exists in the configuration.

ValueT?
<ValueT> retrieveOption(id: Config.Option<ValueT!>, valueIfMissing: ValueT?)

Retrieves the value for the specified option if it exists in the configuration.

ValueT?
<ValueT> retrieveOptionWithPriority(
    id: Config.Option<ValueT!>,
    priority: Config.OptionPriority
)

Retrieves the value for the specified option and specified priority if it exists in the configuration.

Public functions

containsOption

fun containsOption(id: Config.Option<Any!>): Boolean

Returns whether this configuration contains the supplied option.

Parameters
id: Config.Option<Any!>

The Option to search for in this configuration.

Returns
Boolean

true if this configuration contains the supplied option; false otherwise.

findOptions

fun findOptions(idSearchString: String, matcher: Config.OptionMatcher): Unit

Search the configuration for Options whose id match the supplied search string.

Parameters
idSearchString: String

The id string to search for. This could be a fully qualified id such as \"camerax.core.example.option\" or the stem for an option such as \"camerax.core.example\".

matcher: Config.OptionMatcher

A callback used to receive results of the search. Results will be sent to onOptionMatched in the order in which they are found inside this configuration. Subsequent results will continue to be sent as long as onOptionMatched returns true.

getAvailableCamerasLimiter

Added in 1.1.0
fun getAvailableCamerasLimiter(valueIfMissing: CameraSelector?): CameraSelector?

Returns the CameraSelector used to determine the available cameras.

getCameraExecutor

Added in 1.1.0
fun getCameraExecutor(valueIfMissing: Executor?): Executor?

Returns the camera executor which CameraX will use to drive the camera stack.

getCameraOpenRetryMaxTimeoutInMillisWhileResuming

Added in 1.4.0-alpha04
fun getCameraOpenRetryMaxTimeoutInMillisWhileResuming(): Long

Returns the camera open retry maximum timeout in milliseconds when in active resuming mode.

If this value is not set, -1L will be returned by default.

getMinimumLoggingLevel

Added in 1.0.0
fun getMinimumLoggingLevel(): Int

Returns the minimum logging level to be used for CameraX logs.

getOptionPriority

fun getOptionPriority(opt: Config.Option<Any!>): Config.OptionPriority

Returns the current priority of the value for the specified option.

If there are multiple values of various priorities for the specified options, the highest priority will be returned. If the option does not exist, an IllegalArgumentException will be thrown.

getPriorities

fun getPriorities(option: Config.Option<Any!>): (Mutable)Set<Config.OptionPriority!>

Returns a Set of all priorities set for the specified option.

getSchedulerHandler

Added in 1.1.0
fun getSchedulerHandler(valueIfMissing: Handler?): Handler?

Returns the scheduling handler that CameraX will use internally for scheduling future tasks.

getTargetClass

fun getTargetClass(): Class<T!>

Retrieves the class of the object being configured.

Returns
Class<T!>

The stored value, if it exists in this configuration.

Throws
java.lang.IllegalArgumentException

if the option does not exist in this configuration.

getTargetClass

fun getTargetClass(valueIfMissing: Class<T!>?): Class<T!>?

Retrieves the class of the object being configured.

Parameters
valueIfMissing: Class<T!>?

The value to return if this configuration option has not been set.

Returns
Class<T!>?

The stored value or valueIfMissing if the value does not exist in this configuration.

getTargetName

fun getTargetName(): String

Retrieves 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.

Returns
String

The stored value, if it exists in this configuration.

Throws
java.lang.IllegalArgumentException

if the option does not exist in this configuration.

getTargetName

fun getTargetName(valueIfMissing: String?): String?

Retrieves 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
valueIfMissing: String?

The value to return if this configuration option has not been set.

Returns
String?

The stored value or valueIfMissing if the value does not exist in this configuration.

hasConflict

java-static fun hasConflict(
    priority1: Config.OptionPriority,
    priority2: Config.OptionPriority
): Boolean

Returns if values with these OptionPriority conflict or not.

Currently it is not allowed the same option to have different values with priority REQUIRED.

listOptions

fun listOptions(): (Mutable)Set<Config.Option<Any!>!>

Lists all options contained within this configuration.

Returns
(Mutable)Set<Config.Option<Any!>!>

A Set of Options contained within this configuration.

mergeConfigs

java-static fun mergeConfigs(extendedConfig: Config?, baseConfig: Config?): Config

Merges two configs.

Parameters
extendedConfig: Config?

the extended config. The options in the extendedConfig will be applied on top of the baseConfig based on the option priorities.

baseConfig: Config?

the base config.

Returns
Config

a MutableOptionsBundle of the merged config.

mergeOptionValue

java-static fun mergeOptionValue(
    mergedConfig: MutableOptionsBundle,
    baseConfig: Config,
    extendedConfig: Config,
    opt: Config.Option<Any!>
): Unit

Merges a specific option value from two configs.

Parameters
mergedConfig: MutableOptionsBundle

the final output config.

baseConfig: Config

the base config contains the option value which might be overridden by the corresponding option value in the extend config.

extendedConfig: Config

the extended config contains the option value which might override the corresponding option value in the base config.

opt: Config.Option<Any!>

the option to merge.

retrieveOption

fun <ValueT> retrieveOption(id: Config.Option<ValueT!>): ValueT?

Retrieves the value for the specified option if it exists in the configuration.

If the option does not exist, an exception will be thrown. If there are multiple values being set with multiple OptionPriority, it will return the value of highest priority.

Parameters
<ValueT>

The type for the value associated with the supplied Option.

id: Config.Option<ValueT!>

The Option to search for in this configuration.

Returns
ValueT?

The value stored in this configuration.

Throws
java.lang.IllegalArgumentException

if the given option does not exist in this configuration.

retrieveOption

abstract fun <ValueT> retrieveOption(id: Config.Option<ValueT!>, valueIfMissing: ValueT?): ValueT?

Retrieves the value for the specified option if it exists in the configuration.

If the option does not exist, valueIfMissing will be returned. If there are multiple values being set with multiple OptionPriority, it will return the value of highest priority.

Parameters
<ValueT>

The type for the value associated with the supplied Option.

id: Config.Option<ValueT!>

The Option to search for in this configuration.

valueIfMissing: ValueT?

The value to return if the specified Option does not exist in this configuration.

Returns
ValueT?

The value stored in this configuration, or valueIfMissing if it does not exist.

retrieveOption

fun <ValueT> retrieveOption(id: Config.Option<ValueT!>, valueIfMissing: ValueT?): ValueT?

Retrieves the value for the specified option if it exists in the configuration.

If the option does not exist, valueIfMissing will be returned. If there are multiple values being set with multiple OptionPriority, it will return the value of highest priority.

Parameters
<ValueT>

The type for the value associated with the supplied Option.

id: Config.Option<ValueT!>

The Option to search for in this configuration.

valueIfMissing: ValueT?

The value to return if the specified Option does not exist in this configuration.

Returns
ValueT?

The value stored in this configuration, or valueIfMissing if it does not exist.

retrieveOptionWithPriority

fun <ValueT> retrieveOptionWithPriority(
    id: Config.Option<ValueT!>,
    priority: Config.OptionPriority
): ValueT?

Retrieves the value for the specified option and specified priority if it exists in the configuration.

If the option does not exist, an exception will be thrown.

Parameters
<ValueT>

The type for the value associated with the supplied Option.

id: Config.Option<ValueT!>

The Option to search for in this configuration.

Throws
java.lang.IllegalArgumentException

if the given option with specified priority does not exist in this configuration.