Example usage for android.hardware.camera2 CaptureRequest CONTROL_AF_TRIGGER

List of usage examples for android.hardware.camera2 CaptureRequest CONTROL_AF_TRIGGER

Introduction

In this page you can find the example usage for android.hardware.camera2 CaptureRequest CONTROL_AF_TRIGGER.

Prototype

Key CONTROL_AF_TRIGGER

To view the source code for android.hardware.camera2 CaptureRequest CONTROL_AF_TRIGGER.

Click Source Link

Document

Whether the camera device will trigger autofocus for this request.

This entry is normally set to IDLE, or is not included at all in the request settings.

When included and set to START, the camera device will trigger the autofocus algorithm.

Usage

From source file:com.oddsix.nutripro.fragments.Camera2Fragment.java

/**
 * Lock the focus as the first step for a still image capture.
 *///from   w ww  .j av  a  2  s .  c  om
private void lockFocus() {
    // This is how to tell the camera to lock focus.
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
    // Tell #mCaptureCallback to wait for the lock.
    mState = STATE_WAITING_LOCK;
    captureStillPicture();
}

From source file:camera2basic.Camera2BasicFragment.java

/**
 * Lock the focus as the first step for a still image capture.
 *///from  w ww.j a va 2s  .c  om
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.example.android.learnmore.Camera2BasicFragment.java

private void resetAutoFocusTrigger() {
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
}

From source file:com.obviousengine.android.focus.ZslFocusCamera.java

/**
 * Request a stream of images./* www.ja v a 2  s  .c o  m*/
 *
 * @return true if successful, false if there was an error submitting the
 *         capture request.
 */
private boolean sendRepeatingCaptureRequest() {
    Timber.v("sendRepeatingCaptureRequest()");
    try {
        CaptureRequest.Builder builder;
        if (ZSL_ENABLED) {
            builder = device.createCaptureRequest(CameraDevice.TEMPLATE_ZERO_SHUTTER_LAG);
        } else {
            builder = device.createCaptureRequest(CameraDevice.TEMPLATE_PREVIEW);
        }

        builder.addTarget(previewSurface);

        if (ZSL_ENABLED) {
            builder.addTarget(captureImageReader.getSurface());
        }

        builder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);

        builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_CONTINUOUS_PICTURE);
        builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_IDLE);

        builder.set(CaptureRequest.CONTROL_AE_MODE, CaptureRequest.CONTROL_AE_MODE_ON);
        builder.set(CaptureRequest.FLASH_MODE, CaptureRequest.FLASH_MODE_OFF);

        addRegionsToCaptureRequestBuilder(builder);

        captureSession.setRepeatingRequest(builder.build(), captureManager, cameraHandler);
        return true;
    } catch (CameraAccessException e) {
        if (ZSL_ENABLED) {
            Timber.w(e, "Could not execute zero-shutter-lag repeating request.");
        } else {
            Timber.w(e, "Could not execute preview request.");
        }
        return false;
    }
}

From source file:mobello.amtrust.com.fragment.Camera2BasicFragment.java

/**
 * Lock the focus as the first step for a still image capture.
 *//*w w  w  .jav  a 2s.c o m*/
private void lockFocus() {
    //        try {
    // This is how to tell the camera to lock focus.
    mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
    // Tell #mCaptureCallback to wait for the lock.
    mState = STATE_WAITING_LOCK;
    /*mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback,
            mBackgroundHandler);*/
    captureStillPicture();
    /*}catch (CameraAccessException e) {
    e.printStackTrace();
    }*/
}

From source file:com.visualnavigate.CameraFragment.java

/**
 * Lock the focus as the first step for a still image capture.
 *///  w w  w.  j a v  a2 s. c  o m
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);

        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;

        List<CaptureRequest> list = new ArrayList<CaptureRequest>();
        list.add(mPreviewRequestBuilder.build());

        mCaptureSession.captureBurst(list, mCaptureCallback, mBackgroundHandler);

    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:cliq.com.cliqgram.fragments.CameraFragment.java

/**
 * Unlock the focus. This method should be called when still image capture sequence is
 * finished.//from  w  w w  . j  a v a2  s .c o m
 */
private void unlockFocus() {
    try {
        // Reset the auto-focus trigger
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_CANCEL);
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AE_MODE,
                CaptureRequest.CONTROL_AE_MODE_ON_AUTO_FLASH);
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
        // After this, the camera will go back to the normal state of preview.
        mState = STATE_PREVIEW;
        mCaptureSession.setRepeatingRequest(mPreviewRequest, mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.obviousengine.android.focus.ZslFocusCamera.java

/**
 * Request a single image./*w  ww .j a v  a  2s .  c o m*/
 *
 * @return true if successful, false if there was an error submitting the
 *         capture request.
 */
private boolean sendSingleRequest(FocusCamera.PhotoCaptureParameters params) {
    Timber.v("sendSingleRequest()");
    try {
        CaptureRequest.Builder builder;
        builder = device.createCaptureRequest(CameraDevice.TEMPLATE_STILL_CAPTURE);

        builder.addTarget(previewSurface);

        // Always add this surface for single image capture requests.
        builder.addTarget(captureImageReader.getSurface());

        builder.set(CaptureRequest.CONTROL_MODE, CaptureRequest.CONTROL_MODE_AUTO);

        addFlashToCaptureRequestBuilder(builder, params.flashMode);
        addRegionsToCaptureRequestBuilder(builder);

        builder.set(CaptureRequest.CONTROL_AF_MODE, CaptureRequest.CONTROL_AF_MODE_AUTO);
        builder.set(CaptureRequest.CONTROL_AF_TRIGGER, CaptureRequest.CONTROL_AF_TRIGGER_IDLE);

        // Tag this as a special request which should be saved.
        builder.setTag(RequestTag.EXPLICIT_CAPTURE);

        if (CAPTURE_IMAGE_FORMAT == ImageFormat.JPEG) {
            builder.set(CaptureRequest.JPEG_QUALITY, (byte) (JPEG_QUALITY));
            builder.set(CaptureRequest.JPEG_ORIENTATION,
                    Utils.getJpegRotation(params.orientation, characteristics));
        }

        captureSession.capture(builder.build(), captureManager, cameraHandler);
        return true;
    } catch (CameraAccessException e) {
        Timber.w(e, "Could not execute single still capture request.");
        return false;
    }
}

From source file:com.mgtv.qxx.ttsdemo.Camera2BasicFragment.java

/**
 * Lock the focus as the first step for a still image capture.
 *///from  www.j  a  v  a2s .c  o  m
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        Log.v(LOG_TAG, "lockFocus");
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        e.printStackTrace();
    }
}

From source file:com.vest.album.fragment.CameraBasicFragment.java

/**
 * Lock the focus as the first step for a still image capture.
 *///from   w ww.  ja v a2  s .  c o  m
private void lockFocus() {
    try {
        // This is how to tell the camera to lock focus.
        mPreviewRequestBuilder.set(CaptureRequest.CONTROL_AF_TRIGGER, CameraMetadata.CONTROL_AF_TRIGGER_START);
        // Tell #mCaptureCallback to wait for the lock.
        mState = STATE_WAITING_LOCK;
        mCaptureSession.capture(mPreviewRequestBuilder.build(), mCaptureCallback, mBackgroundHandler);
    } catch (CameraAccessException e) {
        callback.onPhotoError("?");
        e.printStackTrace();
    }
}