-
-
Notifications
You must be signed in to change notification settings - Fork 813
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
tapToFocus not working #1771
Comments
Hello, Which library version are you using? |
Hi. |
OK, I will check it |
Hello, I tested it with master branch using Camera2Source in rotation example and it is working as expected.
Video example: Code modifications to test in app example (used for video example): //In CameraFragment class, modify switch camera to disable and enable autofocus
bSwitchCamera.setOnClickListener {
when (val source = genericStream.videoSource) {
is Camera1Source -> source.switchCamera()
is Camera2Source -> {
if (source.isAutoFocusEnabled()) {
source.disableAutoFocus()
} else {
source.enableAutoFocus()
}
}
is CameraXSource -> source.switchCamera()
}
}
//In RotationActivity class call tap to focus
override fun onTouch(view: View, motionEvent: MotionEvent): Boolean {
(cameraFragment.genericStream.videoSource as? Camera2Source)?.let {
return it.tapToFocus(motionEvent)
}
if (filterMenu.spriteGestureController.spriteTouched(view, motionEvent)) {
filterMenu.spriteGestureController.moveSprite(view, motionEvent)
filterMenu.spriteGestureController.scaleSprite(motionEvent)
return true
}
return false
}
|
Hi. |
Hello, Are you using camera2? Because in my case the autofocus is not enabled after call tapToFocus. As you can see in the video, If you never tap the screen the focus is not set up. |
Hi. preview.setOnTouchListener { v, event ->
if (event.action == MotionEvent.ACTION_DOWN) {
(genericStream.videoSource as? Camera2Source)?.let { camera2Source ->
Loggers.e(
"preview setOnTouchListener",
"isAutoFocusEnabled A: ${camera2Source.isAutoFocusEnabled()}"
)
val tapToFocus = camera2Source.tapToFocus(event)
Handler(Looper.getMainLooper()).postDelayed({
Loggers.e(
"preview setOnTouchListener",
"isAutoFocusEnabled B: ${camera2Source.isAutoFocusEnabled()}, tapToFocus: $tapToFocus"
)
}, 500)
tapToFocus
}
}
false
} And logs: 11:39:55.902 Loggers vn.app.demolive E preview setOnTouchListener: isAutoFocusEnabled A: false
11:39:56.408 Loggers vn.app.demolive E preview setOnTouchListener: isAutoFocusEnabled B: true, tapToFocus: true I see in the |
Hello, I added a commit that fix the problem with autofocus to properly work. Anyway, the line that you commented is used to work with tap to focus in all examples. For example official example from Google: |
Hi.
I am using
OpenGlView
(preview) withGenericStream
.I use the following code to set focus when tapping on the screen but it does not get focus (even though it receives the tap event).
I tried setting
enableAutoFocus()
,disableAutoFocus()
but still no change.Tested on devices: Samsung S22 Ultra (Android 14), Samsung S20 Plus (Android 13)
The text was updated successfully, but these errors were encountered: