public interface

CameraFactory

 androidx.camera.core.impl.CameraFactory

Subclasses:

Camera2CameraFactory

Gradle dependencies

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

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

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

Overview

The factory class that creates CameraInternal instances.

Summary

Methods
public java.util.Set<java.lang.String>getAvailableCameraIds()

Gets the ids of all available cameras.

public CameraInternalgetCamera(java.lang.String cameraId)

Gets the camera with the associated id.

public java.lang.ObjectgetCameraManager()

Gets the camera manager instance that is used to access the camera API.

Methods

public CameraInternal getCamera(java.lang.String cameraId)

Gets the camera with the associated id.

Parameters:

cameraId: the camera id to get camera with

Returns:

the camera object with given camera id

public java.util.Set<java.lang.String> getAvailableCameraIds()

Gets the ids of all available cameras.

Returns:

the list of available cameras

public java.lang.Object getCameraManager()

Gets the camera manager instance that is used to access the camera API.

Notes that actual type of this camera manager depends on the implementation. While it is CameraManagerCompat in camera2 implementation, it could be some other type in other implementation.

Source

/*
 * Copyright 2019 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 android.content.Context;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RequiresApi;
import androidx.camera.core.CameraSelector;
import androidx.camera.core.CameraUnavailableException;
import androidx.camera.core.InitializationException;

import java.util.Set;

/**
 * The factory class that creates {@link CameraInternal} instances.
 */
@RequiresApi(21) // TODO(b/200306659): Remove and replace with annotation on package-info.java
public interface CameraFactory {

    /**
     * Interface for deferring creation of a CameraFactory.
     */
    interface Provider {
        /**
         * Creates a new, initialized instance of a CameraFactory.
         *
         * @param context the android context
         * @param threadConfig the thread config to run the camera operations
         * @param availableCamerasLimiter a CameraSelector used to specify which cameras will be
         *                                 loaded and available to CameraX.
         * @return the factory instance
         * @throws InitializationException if it fails to create the factory.
         */
        @NonNull CameraFactory newInstance(@NonNull Context context,
                @NonNull CameraThreadConfig threadConfig,
                @Nullable CameraSelector availableCamerasLimiter) throws InitializationException;
    }

    /**
     * Gets the camera with the associated id.
     *
     * @param cameraId the camera id to get camera with
     * @return the camera object with given camera id
     * @throws CameraUnavailableException if unable to access cameras, perhaps due
     *                                    to insufficient permissions.
     * @throws IllegalArgumentException   if the given camera id is not on the available
     *                                    camera id list.
     */
    @NonNull
    CameraInternal getCamera(@NonNull String cameraId) throws CameraUnavailableException;

    /**
     * Gets the ids of all available cameras.
     *
     * @return the list of available cameras
     */
    @NonNull
    Set<String> getAvailableCameraIds();

    /**
     * Gets the camera manager instance that is used to access the camera API.
     *
     * <p>Notes that actual type of this camera manager depends on the implementation. While it
     * is CameraManagerCompat in camera2 implementation, it could be some other type in
     * other implementation.
     */
    @Nullable
    Object getCameraManager();
}