public abstract class

LensFacingCameraIdFilter

extends java.lang.Object

implements CameraIdFilter

 java.lang.Object

↳androidx.camera.core.LensFacingCameraIdFilter

Subclasses:

Camera2LensFacingCameraIdFilter

Overview

A filter selects camera id with specified lens facing from a camera id set.

Summary

Constructors
publicLensFacingCameraIdFilter()

Methods
public static LensFacingCameraIdFiltercreateLensFacingCameraIdFilter(androidx.camera.core.CameraX.LensFacing lensFacing)

Creates a lens facing camera id filter.

public static LensFacingCameraIdFiltercreateLensFacingCameraIdFilterWithIdSet(androidx.camera.core.CameraX.LensFacing lensFacing, java.util.Set<java.lang.String> ids)

Creates a lens facing camera id filter with a given set of ids for a LensFacing.

public abstract androidx.camera.core.CameraX.LensFacinggetLensFacing()

Returns the lens facing associated with this lens facing camera id filter.

from java.lang.Objectclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

Constructors

public LensFacingCameraIdFilter()

Methods

public abstract androidx.camera.core.CameraX.LensFacing getLensFacing()

Returns the lens facing associated with this lens facing camera id filter.

public static LensFacingCameraIdFilter createLensFacingCameraIdFilterWithIdSet(androidx.camera.core.CameraX.LensFacing lensFacing, java.util.Set<java.lang.String> ids)

Creates a lens facing camera id filter with a given set of ids for a LensFacing.

public static LensFacingCameraIdFilter createLensFacingCameraIdFilter(androidx.camera.core.CameraX.LensFacing lensFacing)

Creates a lens facing camera id filter.

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;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.RestrictTo;

import java.util.Set;
import java.util.TreeSet;

/**
 * A filter selects camera id with specified lens facing from a camera id set.
 *
 * @hide
 */
@RestrictTo(RestrictTo.Scope.LIBRARY_GROUP)
public abstract class LensFacingCameraIdFilter implements CameraIdFilter {
    /** Returns the lens facing associated with this lens facing camera id filter. */
    @NonNull
    public abstract CameraX.LensFacing getLensFacing();

    /** Creates a lens facing camera id filter with a given set of ids for a LensFacing. */
    @NonNull
    public static LensFacingCameraIdFilter createLensFacingCameraIdFilterWithIdSet(
            @NonNull CameraX.LensFacing lensFacing, @Nullable Set<String> ids) {
        return new SettableLensFacingCameraIdFilter(lensFacing, ids);
    }

    /** Creates a lens facing camera id filter. */
    @NonNull
    public static LensFacingCameraIdFilter createLensFacingCameraIdFilter(
            @NonNull CameraX.LensFacing lensFacing) {
        if (CameraX.isInitialized()) {
            return CameraX.getCameraFactory().getLensFacingCameraIdFilter(lensFacing);
        }
        // Returns a no ops camera id filter if CameraX hasn't been initialized.
        return createLensFacingCameraIdFilterWithIdSet(lensFacing, null);
    }

    private static final class SettableLensFacingCameraIdFilter extends LensFacingCameraIdFilter {
        private final CameraX.LensFacing mLensFacing;
        @Nullable
        private final Set<String> mIds;

        SettableLensFacingCameraIdFilter(CameraX.LensFacing lensFacing, @Nullable Set<String> ids) {
            mLensFacing = lensFacing;
            mIds = ids;
        }

        @Override
        @NonNull
        public Set<String> filter(@NonNull Set<String> cameraIds) {
            if (mIds == null) {
                return cameraIds;
            }

            // Use a TreeSet to maintain lexical order of ids
            Set<String> resultCameraIdSet = new TreeSet<>(cameraIds);
            resultCameraIdSet.retainAll(mIds);
            return resultCameraIdSet;
        }

        @Override
        @NonNull
        public CameraX.LensFacing getLensFacing() {
            return mLensFacing;
        }
    }
}