Skip to content

Fix Android focus not using correct focus point#958

Merged
mrousavy merged 1 commit intomrousavy:mainfrom
Menardi:fix-android-focus
Mar 31, 2022
Merged

Fix Android focus not using correct focus point#958
mrousavy merged 1 commit intomrousavy:mainfrom
Menardi:fix-android-focus

Conversation

@Menardi
Copy link
Copy Markdown
Contributor

@Menardi Menardi commented Mar 31, 2022

What

This PR fixes the focus function on Android not focusing on the given point (#758). The issue is that when calculating the focus point with SurfaceOrientedMeteringPointFactory, it does not factor in any scaling or cropping that has been done to the camera's view (thanks to this StackOverflow answer for pointing me in the right direction!). I think it's possible this issue is not obvious unless you're resizing the camera view significantly in some way.

Changes

Rather than manually calculate the focus point, we can get the PreviewView to do it for us. This fixes the issue because the PreviewView factors in any scaling or resizing of the view on the screen. The only potential issue is that this needs to run on the UI thread (which is what the withContext is doing), but I've tested it with frame processors enabled and disabled, and have found no issues in either case.

Tested on

Tested on Pixel 3a running Android 12

Related issues

Fixes #758

This commit fixes mrousavy#758. I was having the same issue and looked into it a bit. I found
[this StackOverflow answer](https://stackoverflow.com/a/60585382) which described a
solution to the same problem. Rather than manually calculate the focus point, we can
get the PreviewView to do it for us. This fixes the issue because the PreviewView
factors in any scaling or resizing of the view on the screen, which we weren't doing
before. The only potential issue is that this needs to run on the UI thread
(which is what the `withContext` is doing), but I've tested it with frame processors
enabled and disabled, and have found no issues in either case.
@Menardi Menardi mentioned this pull request Mar 31, 2022
4 tasks
@mrousavy
Copy link
Copy Markdown
Owner

Hey, thanks so much for your PR! I think everything looks good, LGTM!

@mrousavy mrousavy merged commit fe01295 into mrousavy:main Mar 31, 2022
@Menardi Menardi deleted the fix-android-focus branch March 31, 2022 16:39
@Menardi
Copy link
Copy Markdown
Contributor Author

Menardi commented Mar 31, 2022

Thanks for the quick review! 😄

isaaccolson pushed a commit to isaaccolson/deliveries-mobile that referenced this pull request Oct 30, 2024
This commit fixes mrousavy#758. I was having the same issue and looked into it a bit. I found
[this StackOverflow answer](https://stackoverflow.com/a/60585382) which described a
solution to the same problem. Rather than manually calculate the focus point, we can
get the PreviewView to do it for us. This fixes the issue because the PreviewView
factors in any scaling or resizing of the view on the screen, which we weren't doing
before. The only potential issue is that this needs to run on the UI thread
(which is what the `withContext` is doing), but I've tested it with frame processors
enabled and disabled, and have found no issues in either case.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

🐛 Focus on tap

2 participants