public class

RestrictedCameraControl

extends ForwardingCameraControl

 java.lang.Object

androidx.camera.core.impl.ForwardingCameraControl

↳androidx.camera.core.impl.RestrictedCameraControl

Gradle dependencies

compile group: 'androidx.camera', name: 'camera-core', version: '1.5.0-alpha01'

  • groupId: androidx.camera
  • artifactId: camera-core
  • version: 1.5.0-alpha01

Artifact androidx.camera:camera-core:1.5.0-alpha01 it located at Google repository (https://maven.google.com/)

Overview

A CameraControlInternal whose capabilities can be restricted by the associated SessionProcessor. Only the camera operations that can be retrieved from SessionProcessor.getSupportedCameraOperations() can be supported by the RestrictedCameraControl.

Summary

Constructors
publicRestrictedCameraControl(CameraControlInternal cameraControl, SessionProcessor sessionProcessor)

Creates the restricted version of the given CameraControlInternal.

Methods
public <any>cancelFocusAndMetering()

public <any>enableTorch(boolean torch)

public CameraControlInternalgetImplementation()

Returns implementation instance.

public SessionProcessorgetSessionProcessor()

Returns the SessionProcessor associated with the RestrictedCameraControl.

public <any>setExposureCompensationIndex(int value)

public <any>setLinearZoom(float linearZoom)

public <any>setZoomRatio(float ratio)

public <any>startFocusAndMetering(FocusMeteringAction action)

from ForwardingCameraControladdInteropConfig, addZslConfig, clearInteropConfig, decrementVideoUsage, getFlashMode, getInteropConfig, getSensorRect, getSessionConfig, incrementVideoUsage, isInVideoUsage, isZslDisabledByByUserCaseConfig, setFlashMode, setScreenFlash, setZslDisabledByUserCaseConfig, submitStillCaptureRequests
from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public RestrictedCameraControl(CameraControlInternal cameraControl, SessionProcessor sessionProcessor)

Creates the restricted version of the given CameraControlInternal.

Methods

public CameraControlInternal getImplementation()

Returns implementation instance.

public SessionProcessor getSessionProcessor()

Returns the SessionProcessor associated with the RestrictedCameraControl.

public <any> enableTorch(boolean torch)

public <any> startFocusAndMetering(FocusMeteringAction action)

public <any> cancelFocusAndMetering()

public <any> setZoomRatio(float ratio)

public <any> setLinearZoom(float linearZoom)

public <any> setExposureCompensationIndex(int value)

Source

/*
 * Copyright 2023 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package androidx.camera.core.impl;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.camera.core.FocusMeteringAction;
import androidx.camera.core.FocusMeteringResult;
import androidx.camera.core.impl.utils.SessionProcessorUtil;
import androidx.camera.core.impl.utils.futures.Futures;

import com.google.common.util.concurrent.ListenableFuture;

/**
 * A {@link CameraControlInternal} whose capabilities can be restricted by the associated
 * {@link SessionProcessor}. Only the camera operations that can be retrieved from
 * {@link SessionProcessor#getSupportedCameraOperations()} can be supported by the
 * RestrictedCameraControl.
 */
public class RestrictedCameraControl extends ForwardingCameraControl {
    private final CameraControlInternal mCameraControl;
    @Nullable
    private final SessionProcessor mSessionProcessor;

    /**
     * Creates the restricted version of the given {@link CameraControlInternal}.
     */
    public RestrictedCameraControl(@NonNull CameraControlInternal cameraControl,
            @Nullable SessionProcessor sessionProcessor) {
        super(cameraControl);
        mCameraControl = cameraControl;
        mSessionProcessor = sessionProcessor;
    }

    /**
     * Returns implementation instance.
     */
    @NonNull
    @Override
    public CameraControlInternal getImplementation() {
        return mCameraControl;
    }

    /**
     * Returns the {@link SessionProcessor} associated with the RestrictedCameraControl.
     */
    @Nullable
    public SessionProcessor getSessionProcessor() {
        return mSessionProcessor;
    }

    @NonNull
    @Override
    public ListenableFuture<Void> enableTorch(boolean torch) {
        if (!SessionProcessorUtil.isOperationSupported(mSessionProcessor,
                RestrictedCameraInfo.CAMERA_OPERATION_TORCH)) {
            return Futures.immediateFailedFuture(
                    new IllegalStateException("Torch is not supported"));
        }
        return mCameraControl.enableTorch(torch);
    }

    @NonNull
    @Override
    public ListenableFuture<FocusMeteringResult> startFocusAndMetering(
            @NonNull FocusMeteringAction action) {
        FocusMeteringAction modifiedAction =
                SessionProcessorUtil.getModifiedFocusMeteringAction(mSessionProcessor, action);
        if (modifiedAction == null) {
            return Futures.immediateFailedFuture(
                    new IllegalStateException("FocusMetering is not supported"));
        }

        return mCameraControl.startFocusAndMetering(modifiedAction);
    }

    @NonNull
    @Override
    public ListenableFuture<Void> cancelFocusAndMetering() {
        return mCameraControl.cancelFocusAndMetering();
    }

    @NonNull
    @Override
    public ListenableFuture<Void> setZoomRatio(float ratio) {
        if (!SessionProcessorUtil.isOperationSupported(mSessionProcessor,
                RestrictedCameraInfo.CAMERA_OPERATION_ZOOM)) {
            return Futures.immediateFailedFuture(
                    new IllegalStateException("Zoom is not supported"));
        }
        return mCameraControl.setZoomRatio(ratio);
    }

    @NonNull
    @Override
    public ListenableFuture<Void> setLinearZoom(float linearZoom) {
        if (!SessionProcessorUtil.isOperationSupported(mSessionProcessor,
                RestrictedCameraInfo.CAMERA_OPERATION_ZOOM)) {
            return Futures.immediateFailedFuture(
                    new IllegalStateException("Zoom is not supported"));
        }
        return mCameraControl.setLinearZoom(linearZoom);
    }

    @NonNull
    @Override
    public ListenableFuture<Integer> setExposureCompensationIndex(int value) {
        if (!SessionProcessorUtil.isOperationSupported(mSessionProcessor,
                RestrictedCameraInfo.CAMERA_OPERATION_EXPOSURE_COMPENSATION)) {
            return Futures.immediateFailedFuture(
                    new IllegalStateException("ExposureCompensation is not supported"));
        }
        return mCameraControl.setExposureCompensationIndex(value);
    }
}