Android Dev Summit, October 23-24: two days of technical content, directly from the Android team. Sign-up for livestream updates.

FocusMeteringAction

open class FocusMeteringAction
kotlin.Any
   ↳ androidx.camera.core.FocusMeteringAction

A configuration used to trigger a focus and/or metering action.

To construct a FocusMeteringAction, apps have to create a Builder by Builder#from(MeteringPoint) or Builder#from(MeteringPoint, MeteringMode). MeteringPoint is a point used to specify the focus/metering areas. Apps can use various MeteringPointFactory to create the points. When the FocusMeteringAction is built, pass it to CameraControl#startFocusAndMetering(FocusMeteringAction) to initiate the focus and metering action.

The default MeteringMode is MeteringMode#AF_AE_AWB which means the point is used for all AF/AE/AWB regions. Apps can set the proper MeteringMode to optionally exclude some 3A regions. Multiple regions for specific 3A type are also supported via Builder#addPoint(MeteringPoint) or Builder#addPoint(MeteringPoint, MeteringMode). App can also this API to enable different region for AF and AE respectively.

If any AF points are specified, it will trigger AF to start a manual AF scan and cancel AF trigger when CameraControl#cancelFocusAndMetering() is called. When triggering AF is done, it will call the OnAutoFocusListener#onFocusCompleted(boolean) which is set via Builder#setAutoFocusCallback(OnAutoFocusListener). If AF point is not specified or the action is cancelled before AF is locked, CameraX will call the OnAutoFocusListener#onFocusCompleted(boolean) with isFocusLocked set to false.

App can set a auto-cancel duration to let CameraX call CameraControl#cancelFocusAndMetering() automatically in the specified duration. By default the auto-cancel duration is 5 seconds. Apps can call Builder#disableAutoCancel() to disable auto-cancel.

Summary

Nested classes

open

The builder used to create the FocusMeteringAction.

Focus/Metering mode used to specify which 3A regions is activated for corresponding MeteringPoint.

abstract

Listener for receiving auto-focus completion event.

Public methods

open Long

Returns auto-cancel duration.

open MutableList<MeteringPoint!>

Returns all MeteringPoints used for AE regions.

open MutableList<MeteringPoint!>

Returns all MeteringPoints used for AF regions.

open MutableList<MeteringPoint!>

Returns all MeteringPoints used for AWB regions.

open FocusMeteringAction.OnAutoFocusListener?

Returns current OnAutoFocusListener.

open Boolean

Returns if auto-cancel is enabled or not.

Public methods

getAutoCancelDurationInMs

open fun getAutoCancelDurationInMs(): Long

Returns auto-cancel duration. Returns 0 if auto-cancel is disabled.

getMeteringPointsAE

@NonNull open fun getMeteringPointsAE(): MutableList<MeteringPoint!>

Returns all MeteringPoints used for AE regions.

getMeteringPointsAF

@NonNull open fun getMeteringPointsAF(): MutableList<MeteringPoint!>

Returns all MeteringPoints used for AF regions.

getMeteringPointsAWB

@NonNull open fun getMeteringPointsAWB(): MutableList<MeteringPoint!>

Returns all MeteringPoints used for AWB regions.

getOnAutoFocusListener

@Nullable open fun getOnAutoFocusListener(): FocusMeteringAction.OnAutoFocusListener?

Returns current OnAutoFocusListener.

isAutoCancelEnabled

open fun isAutoCancelEnabled(): Boolean

Returns if auto-cancel is enabled or not.