FocusMeteringAction
class FocusMeteringAction
A configuration used to trigger a focus and/or metering action.
A FocusMeteringAction must be created by the Builder. To construct a Builder, a MeteringPoint is required to specify the focus/metering area. Apps can use various MeteringPointFactory to create the points. After the FocusMeteringAction is built, apps can pass it to startFocusAndMetering to initiate the focus and metering action.
When specifying a MeteringPoint, a metering mode can also be specified. Metering mode is a combination of flags consisting of FLAG_AF, FLAG_AE, and FLAG_AWB. This combination indicates whether the MeteringPoint is used to set an AF(Auto Focus) region, AE(Auto Exposure) region or AWB(Auto White Balance) region. The default meteringMode is FLAG_AF | FLAG_AE | FLAG_AWB which means the point is used for all AF/AE/AWB regions. Apps can set the proper metering mode to optionally exclude some 3A regions. Multiple regions for specific 3A types are also supported via addPoint or addPoint. An app can also use this API to enable different regions for AF and AE respectively.
When the action is submitted via startFocusAndMetering, the following operations are performed:
- Region Updates: The camera's metering regions are updated based on the specified
MeteringPoints.- This update happens regardless of the locking modes set for AF, AE, and AWB.
- If a 3A component (AF/AE/AWB) does not support metering regions on the device, or if the maximum region count is 0, the points for that component are ignored.
- If more points are specified than supported, only the first supported points are used.
- Trigger and Lock: The camera then applies the locks specified in the locking mode (see
setLockingMode):- AF: If AF points are specified and
FLAG_AFis included in the locking mode (which is the default), it triggers an autofocus manual scan and locks focus. IfFLAG_AFis NOT in the locking mode, it updates the AF region without triggering a scan, allowing the camera to continue in its current AF mode (e.g., continuous autofocus). - AE/AWB: If AE/AWB points are specified and
FLAG_AE/FLAG_AWBare included in the locking mode, the camera locks the exposure and white balance respectively. If not included, the regions are updated but exposure and white balance continue to adjust automatically.
- AF: If AF points are specified and
- Completion: The returned
ListenableFuturecompletes when the regions are updated and the requested locks are acquired.isFocusSuccessfulwill betrueif an AF lock was requested and successfully acquired, or if AF is not supported on the device. It will befalseif the AF lock failed, if no AF points were specified, or ifFLAG_AFwas excluded from the locking mode.
App can set a auto-cancel duration to let CameraX call cancelFocusAndMetering automatically in the specified duration. By default, the auto-cancel duration is 5 seconds. Apps can call disableAutoCancel to disable auto-cancel.
If a focus-metering action is completed with isFocusSuccessfultrue, the focus distance will be locked and continuous auto-focus will be disabled. Continuous autofocus will be re-enabled when cancelFocusAndMetering is called or the auto-cancel duration is reached.
AE (Auto Exposure) and AWB (Auto White Balance) can also be locked if they are enabled in setLockingMode. Locking mode is a combination of flags consisting of FLAG_AF, FLAG_AE, and FLAG_AWB. For example, to lock both AF and AE, use FLAG_AF | FLAG_AE.
Summary
Nested types |
|---|
|
The builder used to create the |
Constants |
|
|---|---|
const Int |
FLAG_AE = 2A flag used in metering mode indicating the AE (Auto Exposure) region is enabled. |
const Int |
FLAG_AF = 1A flag used in metering mode indicating the AF (Auto Focus) region is enabled. |
const Int |
FLAG_AWB = 4A flag used in metering mode indicating the AWB (Auto White Balance) region is enabled. |
Public functions |
|
|---|---|
Long |
Returns auto-cancel duration. |
Int |
Returns the locking mode. |
(Mutable)List<MeteringPoint!> |
Returns all |
(Mutable)List<MeteringPoint!> |
Returns all |
(Mutable)List<MeteringPoint!> |
Returns all |
Boolean |
Returns if auto-cancel is enabled or not. |
Constants
FLAG_AE
const val FLAG_AE = 2: Int
A flag used in metering mode indicating the AE (Auto Exposure) region is enabled.
Public functions
getAutoCancelDurationInMillis
fun getAutoCancelDurationInMillis(): Long
Returns auto-cancel duration. Returns 0 if auto-cancel is disabled.
getLockingMode
fun getLockingMode(): Int
Returns the locking mode.
Locking mode is a combination of flags consisting of FLAG_AF, FLAG_AE, and FLAG_AWB. This combination indicates whether the AF (Auto Focus), AE (Auto Exposure) or AWB (Auto White Balance) should be locked after focus and metering action is completed.
getMeteringPointsAe
fun getMeteringPointsAe(): (Mutable)List<MeteringPoint!>
Returns all MeteringPoints used for AE regions.
getMeteringPointsAf
fun getMeteringPointsAf(): (Mutable)List<MeteringPoint!>
Returns all MeteringPoints used for AF regions.
getMeteringPointsAwb
fun getMeteringPointsAwb(): (Mutable)List<MeteringPoint!>
Returns all MeteringPoints used for AWB regions.
isAutoCancelEnabled
fun isAutoCancelEnabled(): Boolean
Returns if auto-cancel is enabled or not.