I'm trying to implement tap to focus using CameraX but I can't debug why it is not working, despite the focus result return true.
This is a snippet from inside of my Camera compose.
previewView.setOnTouchListener { view, motionEvent ->
when (motionEvent.action) {
MotionEvent.ACTION_UP -> {
view.performClick()
val meteringPoint =
previewView.meteringPointFactory
.createPoint(motionEvent.x, motionEvent.y)
val action = FocusMeteringAction.Builder(meteringPoint).setAutoCancelDuration(3, TimeUnit.SECONDS).build()
val result = camera.cameraControl.startFocusAndMetering(action)
result.addListener(
{
try {
val isFocusSuccessful = result.get().isFocusSuccessful
Timber.tag("CameraXApp").d("Focus result: $isFocusSuccessful and is focused on (x: ${motionEvent.x}, y: ${motionEvent.y})")
} catch (e: Exception) {
Timber.tag("CameraXApp").d(e, "Focus request was cancelled or failed")
}
},
ContextCompat.getMainExecutor(previewView.context),
)
}
}
true
}
It logs that the isFocusSuccessful is true and the correct x and y coordinate, but from my testing, I couldn't tell any changes at all to the quality. And there are no error or warning in logcat at all.
So, the question is quite vague but I'm just asking for any advice for how to approach this. I'm not sure how to debug this further since there is no error or whatsoever.