Java Code Examples for android.hardware.Camera.Parameters#getSupportedFocusModes()

The following examples show how to use android.hardware.Camera.Parameters#getSupportedFocusModes() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Utils.java    From code-scanner with MIT License 6 votes vote down vote up
public static void disableAutoFocus(@NonNull final Parameters parameters) {
    final List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes == null || focusModes.isEmpty()) {
        return;
    }
    final String focusMode = parameters.getFocusMode();
    if (focusModes.contains(Parameters.FOCUS_MODE_FIXED)) {
        if (Parameters.FOCUS_MODE_FIXED.equals(focusMode)) {
            return;
        } else {
            parameters.setFocusMode(Parameters.FOCUS_MODE_FIXED);
            return;
        }
    }
    if (focusModes.contains(Parameters.FOCUS_MODE_AUTO)) {
        if (!Parameters.FOCUS_MODE_AUTO.equals(focusMode)) {
            parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
        }
    }
}
 
Example 2
Source File: Utils.java    From code-scanner with MIT License 6 votes vote down vote up
public static void setAutoFocusMode(@NonNull final Parameters parameters,
        final AutoFocusMode autoFocusMode) {
    final List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes == null || focusModes.isEmpty()) {
        return;
    }
    if (autoFocusMode == AutoFocusMode.CONTINUOUS) {
        if (Parameters.FOCUS_MODE_CONTINUOUS_PICTURE.equals(parameters.getFocusMode())) {
            return;
        }
        if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
            parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
            return;
        }
    }
    if (Parameters.FOCUS_MODE_AUTO.equals(parameters.getFocusMode())) {
        return;
    }
    if (focusModes.contains(Parameters.FOCUS_MODE_AUTO)) {
        parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
    }
}
 
Example 3
Source File: CameraView.java    From mollyim-android with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(14)
private void onCameraReady(final @NonNull Camera camera) {
  final Parameters parameters = camera.getParameters();

  if (VERSION.SDK_INT >= 14) {
    parameters.setRecordingHint(true);
    final List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
      parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    } else if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
      parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }
  }

  displayOrientation = CameraUtils.getCameraDisplayOrientation(getActivity(), getCameraInfo());
  camera.setDisplayOrientation(displayOrientation);
  camera.setParameters(parameters);
  enqueueTask(new PostInitializationTask<Void>() {
    @Override
    protected Void onRunBackground() {
      try {
        camera.setPreviewDisplay(surface.getHolder());
        startPreview(parameters);
      } catch (Exception e) {
        Log.w(TAG, "couldn't set preview display", e);
      }
      return null;
    }
  });
}
 
Example 4
Source File: Camera1Controller.java    From pixelvisualcorecamera with Apache License 2.0 5 votes vote down vote up
/**
 * Configures camera parameters common to all configurations.
 * Must be called before preview started.
 */
public void setDefaultParameters(int displayRotation) {
  Log.i(TAG, "setDefaultParameters");
  assertState(STATE_ACQUIRED,
        "Default parameters may only be set before a preview is started");

  CameraInfo info = new CameraInfo();
  Camera.getCameraInfo(cameraId, info);
  boolean lensFacingFront = (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT);

  int previewOrientationDegrees =
      Orientation.getPreviewOrientation(lensFacingFront, displayRotation, info.orientation);
  camera.setDisplayOrientation(previewOrientationDegrees);
  Parameters params = camera.getParameters();

  // We happen to know the preview sizes available for Pixel 2.
  params.setPreviewSize(Utils.MAX_PREVIEW_WIDTH, Utils.MAX_PREVIEW_HEIGHT);
  params.setRotation(
      Orientation.getOutputOrientation(lensFacingFront, displayRotation, info.orientation));

  // Continuous picture is not supported Pixel 2's front camera.
  List<String> supportFocusModes = params.getSupportedFocusModes();
  if (supportFocusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
    Log.i(TAG, "setting continuous picture focus mode");
    params.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
  }

  // HDR+: Flash mode must be off.
  params.setFlashMode(Parameters.FLASH_MODE_OFF);

  // HDR+: Color effect must be none.
  params.setColorEffect(Parameters.EFFECT_NONE);

  // HDR+: White balance must be auto.
  params.setWhiteBalance(Parameters.WHITE_BALANCE_AUTO);

  camera.setParameters(params);
}
 
Example 5
Source File: Utils.java    From code-scanner with MIT License 5 votes vote down vote up
public static void configureFocusModeForTouch(@NonNull final Parameters parameters) {
    if (Parameters.FOCUS_MODE_AUTO.equals(parameters.getFocusMode())) {
        return;
    }
    final List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes != null && focusModes.contains(Parameters.FOCUS_MODE_AUTO)) {
        parameters.setFocusMode(Parameters.FOCUS_MODE_AUTO);
    }
}
 
Example 6
Source File: CameraView.java    From deltachat-android with GNU General Public License v3.0 5 votes vote down vote up
@TargetApi(14)
private void onCameraReady(final @NonNull Camera camera) {
  final Parameters parameters = camera.getParameters();

  if (VERSION.SDK_INT >= 14) {
    parameters.setRecordingHint(true);
    final List<String> focusModes = parameters.getSupportedFocusModes();
    if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
      parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
    } else if (focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO)) {
      parameters.setFocusMode(Parameters.FOCUS_MODE_CONTINUOUS_VIDEO);
    }
  }

  displayOrientation = CameraUtils.getCameraDisplayOrientation(getActivity(), getCameraInfo());
  camera.setDisplayOrientation(displayOrientation);
  camera.setParameters(parameters);
  enqueueTask(new PostInitializationTask<Void>() {
    @Override
    protected Void onRunBackground() {
      try {
        camera.setPreviewDisplay(surface.getHolder());
        startPreview(parameters);
      } catch (Exception e) {
        Log.w(TAG, "couldn't set preview display", e);
      }
      return null;
    }
  });
}
 
Example 7
Source File: CodeScanner.java    From code-scanner with MIT License 4 votes vote down vote up
private void initialize() {
    Camera camera = null;
    final CameraInfo cameraInfo = new CameraInfo();
    final int cameraId = mCameraId;
    if (cameraId == CAMERA_BACK || cameraId == CAMERA_FRONT) {
        final int numberOfCameras = Camera.getNumberOfCameras();
        final int facing = cameraId == CAMERA_BACK ? CameraInfo.CAMERA_FACING_BACK :
                CameraInfo.CAMERA_FACING_FRONT;
        for (int i = 0; i < numberOfCameras; i++) {
            Camera.getCameraInfo(i, cameraInfo);
            if (cameraInfo.facing == facing) {
                camera = Camera.open(i);
                mCameraId = i;
                break;
            }
        }
    } else {
        camera = Camera.open(cameraId);
        Camera.getCameraInfo(cameraId, cameraInfo);
    }
    if (camera == null) {
        throw new CodeScannerException("Unable to access camera");
    }
    final Parameters parameters = camera.getParameters();
    if (parameters == null) {
        throw new CodeScannerException("Unable to configure camera");
    }
    final int orientation = Utils.getDisplayOrientation(mContext, cameraInfo);
    final boolean portrait = Utils.isPortrait(orientation);
    final Point imageSize =
            Utils.findSuitableImageSize(parameters, portrait ? mHeight : mWidth,
                    portrait ? mWidth : mHeight);
    final int imageWidth = imageSize.getX();
    final int imageHeight = imageSize.getY();
    parameters.setPreviewSize(imageWidth, imageHeight);
    parameters.setPreviewFormat(ImageFormat.NV21);
    final Point previewSize = Utils.getPreviewSize(portrait ? imageHeight : imageWidth,
            portrait ? imageWidth : imageHeight, mWidth, mHeight);
    final List<String> focusModes = parameters.getSupportedFocusModes();
    final boolean autoFocusSupported = focusModes != null &&
            (focusModes.contains(Parameters.FOCUS_MODE_AUTO) ||
                    focusModes.contains(Parameters.FOCUS_MODE_CONTINUOUS_PICTURE));
    if (!autoFocusSupported) {
        mAutoFocusEnabled = false;
    }
    final Point viewSize = new Point(mWidth, mHeight);
    if (autoFocusSupported && mAutoFocusEnabled) {
        Utils.setAutoFocusMode(parameters, mAutoFocusMode);
        final Rect frameRect = mScannerView.getFrameRect();
        if (frameRect != null) {
            Utils.configureDefaultFocusArea(parameters, frameRect, previewSize, viewSize,
                    imageWidth, imageHeight, orientation);
        }
    }
    final List<String> flashModes = parameters.getSupportedFlashModes();
    final boolean flashSupported =
            flashModes != null && flashModes.contains(Parameters.FLASH_MODE_TORCH);
    if (!flashSupported) {
        mFlashEnabled = false;
    }
    final int zoom = mZoom;
    if (zoom != 0) {
        Utils.setZoom(parameters, zoom);
    }
    Utils.configureFpsRange(parameters);
    Utils.configureSceneMode(parameters);
    Utils.configureVideoStabilization(parameters);
    camera.setParameters(parameters);
    camera.setDisplayOrientation(orientation);
    synchronized (mInitializeLock) {
        final Decoder decoder =
                new Decoder(mDecoderStateListener, mFormats, mDecodeCallback);
        mDecoderWrapper =
                new DecoderWrapper(camera, cameraInfo, decoder, imageSize, previewSize,
                        viewSize, orientation, autoFocusSupported, flashSupported);
        decoder.start();
        mInitialization = false;
        mInitialized = true;
    }
    mMainThreadHandler.post(new FinishInitializationTask(previewSize));
}