Example usage for android.hardware Camera autoFocus

List of usage examples for android.hardware Camera autoFocus

Introduction

In this page you can find the example usage for android.hardware Camera autoFocus.

Prototype

public final void autoFocus(AutoFocusCallback cb) 

Source Link

Document

Starts camera auto-focus and registers a callback function to run when the camera is focused.

Usage

From source file:Main.java

public static void autoFocus(Camera camera) {
    try {//w  w w .jav  a2  s.  c o  m
        camera.autoFocus(null);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:Main.java

public static void setAutoFocusCallback(Camera camera, Camera.AutoFocusCallback autoFocusCallback) {
    camera.autoFocus(autoFocusCallback);

}

From source file:Main.java

/** */
public static void autoFocus(Camera camera, Camera.AutoFocusCallback autoFocusCallback)
        throws RuntimeException {
    if (camera == null)
        return;/*ww  w  .  j a v  a 2  s .  co m*/

    camera.cancelAutoFocus();
    camera.autoFocus(autoFocusCallback);
}

From source file:com.googlecode.android_scripting.facade.CameraFacade.java

private void autoFocus(final BooleanResult result, final Camera camera) throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    {//  w  w  w.j ava2s.  c  o m
        camera.autoFocus(new AutoFocusCallback() {
            @Override
            public void onAutoFocus(boolean success, Camera camera) {
                result.mmResult = success;
                latch.countDown();
            }
        });
        latch.await(10, TimeUnit.SECONDS);
    }
}

From source file:com.nekomeshi312.whiteboardcorrection.WhiteBoardCorrectionActivity.java

private void startAutoFocus() {
    if (!mCameraSetting.isCameraOpen()) {
        Log.w(LOG_TAG, "Camera is not open");
        return;//from  ww w .j  a v  a2  s  .c o m
    }
    //??????
    if (mFocusStatus != FOCUS_STATUS_IDLE) {
        Log.w(LOG_TAG, "Autofocus is Running");
        return;
    }
    mFocusStatus = FOCUS_STATUS_FOCUSING;
    Camera camera = mCameraSetting.getCamera();

    try {
        camera.autoFocus(new Camera.AutoFocusCallback() {//?AF???
            @Override
            public void onAutoFocus(boolean success, Camera c) {
                // TODO Auto-generated method stub
                Log.i(LOG_TAG, "Autofocus = " + success);
                if (success) {
                    mFocusStatus = FOCUS_STATUS_FOCUS_OK;
                    takePic(c);
                } else {
                    Toast.makeText(WhiteBoardCorrectionActivity.this, R.string.error_msg_cant_focus,
                            Toast.LENGTH_SHORT).show();
                    mFocusStatus = FOCUS_STATUS_IDLE;
                }
            }
        });
    } catch (Exception e) {//????????
        e.printStackTrace();
        try {
            mFocusStatus = FOCUS_STATUS_FOCUS_OK;
            takePic(camera);
        } catch (Exception e1) {
            e1.printStackTrace();
            mFocusStatus = FOCUS_STATUS_IDLE;
        }
    }
}

From source file:com.csusm.twinder.Fragment.QRScanFragment.java

@Nullable
@Override/*w  ww.  j  a  va2s. c o m*/
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
    View view = inflater.inflate(R.layout.fragment_scan, container, false);

    view.setOnTouchListener(new View.OnTouchListener() {
        public boolean onTouch(View v, MotionEvent event) {

            Camera camera = mCameraSource.getCamera();

            if (camera != null) {
                camera.cancelAutoFocus();
                Rect focusRect = calculateTapArea((int) event.getX(), (int) event.getY(), 1f);

                Camera.Parameters parameters = camera.getParameters();
                parameters.setFocusMode(Camera.Parameters.FOCUS_MODE_AUTO);
                if (parameters.getMaxNumFocusAreas() > 0) {
                    List<Camera.Area> mylist = new ArrayList<Camera.Area>();
                    mylist.add(new Camera.Area(focusRect, 1000));
                    parameters.setFocusAreas(mylist);
                }

                //camera.setParameters(parameters);
                camera.autoFocus(new Camera.AutoFocusCallback() {
                    @Override
                    public void onAutoFocus(boolean success, Camera camera) {
                        camera.cancelAutoFocus();
                        Camera.Parameters params = camera.getParameters();
                        if (params.getFocusMode() != Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE) {
                            params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
                            camera.setParameters(params);
                        }
                    }
                });
            }

            return true;
        }
    });

    return view;
}