I am building a custom camera with auto focus, and was merely wondering if there is a way to invoke the same auto-focus rectangular indicator that the native camera has or if i have to build that from scratch.. any examples or tutorial links would be greatly appreciated.
Share
It might be helpful to look at the way the most recent Jelly Bean 4.2 camera handles this. You can download the Camera source as follows:
Once you have the code, navigate to the
FocusOverlayManagerclass and thePieRendererclass. If you haven’t tried out this newest version before, the focus meter is a pie-like circle that rotates upon focus completion. You can make your own square in photoshop or use one of these two that I have used in the past (one is an iPhone ripoff I made and the other is a nine-patch used in some version of the android camera):The Jelly Bean example may be a little complicated for what you are looking for, so below are some guidelines for the way I implemented visual feedback for autofocus. The process can be somewhat complicated. I don’t pretend my way is the best way to do this, but here is some example code that gives you the general idea…
In my camera preview layout xml file:
This AutofocusCrosshair class is the following:
And when, in my activity, I want to start autofocus I do the following:
And make sure at the end of your animation to clear the image: