public final class

CameraCaptureCallbacks

extends java.lang.Object

 java.lang.Object

↳androidx.camera.core.impl.CameraCaptureCallbacks

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

Different implementations of CameraCaptureCallback.

Summary

Methods
public static CameraCaptureCallbackcreateComboCallback(CameraCaptureCallback callbacks[])

Returns a camera capture callback which calls a list of other callbacks.

public static CameraCaptureCallbackcreateNoOpCallback()

Returns a camera capture callback which does nothing.

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

Methods

public static CameraCaptureCallback createNoOpCallback()

Returns a camera capture callback which does nothing.

public static CameraCaptureCallback createComboCallback(CameraCaptureCallback callbacks[])

Returns a camera capture callback which calls a list of other callbacks.

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 androidx.annotation.NonNull;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * Different implementations of {@link CameraCaptureCallback}.
 */
public final class CameraCaptureCallbacks {
    private CameraCaptureCallbacks() {
    }

    /** Returns a camera capture callback which does nothing. */
    @NonNull
    public static CameraCaptureCallback createNoOpCallback() {
        return new NoOpCameraCaptureCallback();
    }

    /** Returns a camera capture callback which calls a list of other callbacks. */
    @NonNull
    static CameraCaptureCallback createComboCallback(
            @NonNull List<CameraCaptureCallback> callbacks) {
        if (callbacks.isEmpty()) {
            return createNoOpCallback();
        } else if (callbacks.size() == 1) {
            return callbacks.get(0);
        }
        return new ComboCameraCaptureCallback(callbacks);
    }

    /** Returns a camera capture callback which calls a list of other callbacks. */
    @NonNull
    public static CameraCaptureCallback createComboCallback(
            @NonNull CameraCaptureCallback... callbacks) {
        return createComboCallback(Arrays.asList(callbacks));
    }

    static final class NoOpCameraCaptureCallback extends CameraCaptureCallback {
        @Override
        public void onCaptureStarted(int captureConfigId) {
        }

        @Override
        public void onCaptureCompleted(int captureConfigId,
                @NonNull CameraCaptureResult cameraCaptureResult) {
        }

        @Override
        public void onCaptureFailed(int captureConfigId, @NonNull CameraCaptureFailure failure) {
        }
    }

    /**
     * A CameraCaptureCallback which contains a list of CameraCaptureCallback and will propagate
     * received callback to the list.
     */
    public static final class ComboCameraCaptureCallback extends CameraCaptureCallback {
        private final List<CameraCaptureCallback> mCallbacks = new ArrayList<>();

        ComboCameraCaptureCallback(@NonNull List<CameraCaptureCallback> callbacks) {
            for (CameraCaptureCallback callback : callbacks) {
                // A no-op callback doesn't do anything, so avoid adding it to the final list.
                if (!(callback instanceof NoOpCameraCaptureCallback)) {
                    mCallbacks.add(callback);
                }
            }
        }

        @Override
        public void onCaptureStarted(int captureConfigId) {
            for (CameraCaptureCallback callback : mCallbacks) {
                callback.onCaptureStarted(captureConfigId);
            }
        }

        @Override
        public void onCaptureCompleted(int captureConfigId,
                @NonNull CameraCaptureResult cameraCaptureResult) {
            for (CameraCaptureCallback callback : mCallbacks) {
                callback.onCaptureCompleted(captureConfigId, cameraCaptureResult);
            }
        }

        @Override
        public void onCaptureFailed(int captureConfigId, @NonNull CameraCaptureFailure failure) {
            for (CameraCaptureCallback callback : mCallbacks) {
                callback.onCaptureFailed(captureConfigId, failure);
            }
        }

        @Override
        public void onCaptureCancelled(int captureConfigId) {
            for (CameraCaptureCallback callback : mCallbacks) {
                callback.onCaptureCancelled(captureConfigId);
            }
        }

        @NonNull
        public List<CameraCaptureCallback> getCallbacks() {
            return mCallbacks;
        }

        @Override
        public void onCaptureProcessProgressed(int captureConfigId, int progress) {
            for (CameraCaptureCallback callback : mCallbacks) {
                callback.onCaptureProcessProgressed(captureConfigId, progress);
            }
        }
    }
}