Android and androidadt

Source: Internet
Author: User

Android and androidadt

I have long wanted to find the focus for different clicks, but I haven't found the focus. Now the project needs this function again, and I ran it again. Finally, I found it ~~ Focus is more about auto focus.

Let's just talk about it. It's mainly implemented in the setFocusAreas method.

Each diagonal area is a rectangle with a specific weight. The direction is related to the direction of gravity sensing. This direction is not affected by the setDisplayOrientation (int) setting. The coordinates of the rectangle range from-1000 to 1000. (-1000,-1000) indicates that the top left vertex () is the bottom right vertex. The length or width of the focus area cannot be 0 or negative, and the weight value ranges from 1 to 1000. The weight is evenly distributed among pixels in the Rectangular range, this means that the size of the focus area with the same weight has little impact on the overall focus.

Code
private Rect calculateTapArea(float x, float y, float coefficient) {        float focusAreaSize = 300;        int areaSize = Float.valueOf(focusAreaSize * coefficient).intValue();        int centerX = (int) (x / getResolution().width - 1000);        int centerY = (int) (y / getResolution().height - 1000);        int left = clamp(centerX - areaSize / 2, -1000, 1000);        int top = clamp(centerY - areaSize / 2, -1000, 1000);        RectF rectF = new RectF(left, top, left + areaSize, top + areaSize);        return new Rect(Math.round(rectF.left), Math.round(rectF.top),                Math.round(rectF.right), Math.round(rectF.bottom));    }    private int clamp(int x, int min, int max) {        if (x > max) {            return max;        }        if (x < min) {            return min;        }        return x;    }    public Camera.Size getResolution() {        Camera.Parameters params = myCamera.getParameters();        Camera.Size s = params.getPreviewSize();        return s;    }

Call this method in the OnTouch event.

I am the dividing line of tiantiao

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.