Example usage for android.hardware Camera cancelAutoFocus

List of usage examples for android.hardware Camera cancelAutoFocus

Introduction

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

Prototype

public final void cancelAutoFocus() 

Source Link

Document

Cancels any auto-focus function in progress.

Usage

From source file:Main.java

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

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

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

@Nullable
@Override//from  w  ww  . j  a  va2  s.  co  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;
}

From source file:com.personal.xiri.only.common.camera.Camera1.java

void takePictureInternal() {
    if (!isPictureCaptureInProgress.getAndSet(true)) {
        mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
            @Override//w w  w .  j  a  va2 s  .com
            public void onPictureTaken(byte[] data, Camera camera) {
                isPictureCaptureInProgress.set(false);
                mCallback.onPictureTaken(data);
                camera.cancelAutoFocus();
                camera.startPreview();
            }
        });
    }
}

From source file:io.mariachi.allianzvision.camera.api14.Camera1.java

public void takePictureInternal() {
    mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
        @Override// ww  w.  ja  v a2  s  .  c  om
        public void onPictureTaken(byte[] data, Camera camera) {
            mCallback.onPictureTaken(data);
            camera.cancelAutoFocus();
            camera.startPreview();
        }
    });
}

From source file:com.google.android.cameraview.Camera1.java

void takePictureInternal() {
    if (!isPictureCaptureInProgress.getAndSet(true)) {
        mCamera.takePicture(null, null, null, new Camera.PictureCallback() {
            @Override//from  w w  w .ja v a 2  s . com
            public void onPictureTaken(byte[] data, Camera camera) {
                isPictureCaptureInProgress.set(false);
                mCallback.onPictureTaken(data);
                if (!isCameraOpened())
                    return;
                camera.cancelAutoFocus();
                camera.startPreview();
            }
        });
    }
}

From source file:hr.abunicic.angular.CameraActivity.java

/**
 * Method that initializes the camera./*from ww  w . ja va 2  s  .co  m*/
 */
void initCamera() {
    try {
        mCamera = Camera.open();
    } catch (Exception e) {
        Log.d("ERROR", "Failed to get camera: " + e.getMessage());
    }

    if (mCamera != null) {
        //Creating a CameraView instance to show camera data
        mCameraView = new CameraView(this, mCamera);
        preview = (FrameLayout) findViewById(R.id.camera_view);
        //Adding the CameraView to the layout
        preview.addView(mCameraView);
        params = mCamera.getParameters();

        List<Camera.Size> ls = params.getSupportedPreviewSizes();
        Camera.Size size = ls.get(1);
        params.setPreviewSize(size.width, size.height);

        //Setting focus mode
        params.setFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
        mCamera.setParameters(params);
        mCamera.setDisplayOrientation(90);
    }

    mCameraView.setOnLongClickListener(new View.OnLongClickListener() {
        @Override
        public boolean onLongClick(View v) {
            Vibrator vib = (Vibrator) getApplicationContext().getSystemService(Context.VIBRATOR_SERVICE);
            vib.vibrate(60);

            //Determining which line is selected
            if (rp != null) {
                try {
                    selectedLine = getTouchedLine(touchX, touchY);
                    selectedLine.color = Color.BLUE;
                } catch (Exception e) {
                }
            } else {
            }

            //AlertDialog for changing the length of the line
            AlertDialog.Builder alert = new AlertDialog.Builder(CameraActivity.this);
            final EditText edittext = new EditText(CameraActivity.this);

            alert.setMessage("Duljina stranice: ");
            alert.setView(edittext);

            alert.setPositiveButton("U redu", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int whichButton) {
                    lineLength = edittext.getText().toString();
                    selectedLine.color = Color.CYAN;
                    Log.d("ocr", "Nova duljina linije: " + lineLength + " ");
                    selectedLine = getTouchedLine(numberX, numberY);
                    RecognitionMethods.refreshLines(rp.getLineSegments(), selectedLine, lineLength);
                    updateDescription();
                }
            });

            alert.show();

            return true;
        }
    });

    mCameraView.setOnTouchListener(new View.OnTouchListener() {
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            Camera camera = mCamera;
            camera.cancelAutoFocus();

            touchX = event.getX();
            touchY = event.getY();

            return false;
        }

    });

}