Skip to content

Commit

Permalink
fix(android): focusAtPoint fix
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Jun 3, 2024
1 parent a82ef71 commit 5dea72f
Showing 1 changed file with 4 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -434,21 +434,11 @@ constructor(context: Context, attrs: AttributeSet? = null, defStyleAttr: Int = 0
}

fun focusAtPoint(x: Float, y: Float) {
val factory: MeteringPointFactory =
SurfaceOrientedMeteringPointFactory(
previewView.width.toFloat(),
previewView.height.toFloat()
)
val autoFocusPoint = factory.createPoint(x, y)
try {
camera?.cameraControl?.startFocusAndMetering(
FocusMeteringAction.Builder(autoFocusPoint, FocusMeteringAction.FLAG_AF)
.apply {
// focus only when the user tap the preview
disableAutoCancel()
}
.build()
)
val autoFocusPoint = previewView.meteringPointFactory.createPoint(x, y)
val focusBuilder = FocusMeteringAction.Builder(autoFocusPoint)
focusBuilder.disableAutoCancel()
camera?.cameraControl?.startFocusAndMetering(focusBuilder.build())
} catch (e: CameraInfoUnavailableException) {
Log.e("ERROR", "cannot access camera", e)
}
Expand Down

0 comments on commit 5dea72f

Please sign in to comment.