1/*
2 * Copyright (C) 2015 The Android Open Source Project
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16
17package com.android.camera.one.v2.photo;
18
19import android.hardware.camera2.CameraAccessException;
20
21import com.android.camera.async.Updatable;
22import com.android.camera.debug.Log;
23import com.android.camera.debug.Logger;
24import com.android.camera.one.OneCamera;
25import com.android.camera.one.v2.camera2proxy.CameraCaptureSessionClosedException;
26import com.android.camera.one.v2.core.ResourceAcquisitionFailedException;
27import com.android.camera.one.v2.imagesaver.ImageSaver;
28import com.google.common.base.Supplier;
29
30import javax.annotation.ParametersAreNonnullByDefault;
31
32@ParametersAreNonnullByDefault
33final class FlashBasedPhotoCommand implements ImageCaptureCommand {
34    private final Logger mLog;
35    private final Supplier<OneCamera.PhotoCaptureParameters.Flash> mFlashMode;
36    private final ImageCaptureCommand mFlashOnCommand;
37    private final ImageCaptureCommand mFlashAutoCommand;
38    private final ImageCaptureCommand mFlashOffCommand;
39
40    FlashBasedPhotoCommand(Logger.Factory logFactory,
41            Supplier<OneCamera.PhotoCaptureParameters.Flash> flashMode,
42            ImageCaptureCommand flashOnCommand,
43            ImageCaptureCommand flashAutoCommand,
44            ImageCaptureCommand flashOffCommand) {
45        mLog = logFactory.create(new Log.Tag("FlashBasedPhotoCmd"));
46        mFlashMode = flashMode;
47        mFlashOnCommand = flashOnCommand;
48        mFlashAutoCommand = flashAutoCommand;
49        mFlashOffCommand = flashOffCommand;
50    }
51
52    @Override
53    public void run(Updatable<Void> imageExposeCallback, ImageSaver imageSaver)
54            throws InterruptedException, CameraAccessException,
55            CameraCaptureSessionClosedException,
56            ResourceAcquisitionFailedException {
57        OneCamera.PhotoCaptureParameters.Flash flashMode = mFlashMode.get();
58        if (flashMode == OneCamera.PhotoCaptureParameters.Flash.ON) {
59            mLog.i("running flash-on command: " + mFlashOnCommand);
60            mFlashOnCommand.run(imageExposeCallback, imageSaver);
61        } else if (flashMode == OneCamera.PhotoCaptureParameters.Flash.AUTO) {
62            mLog.i("running flash-auto command: " + mFlashAutoCommand);
63            mFlashAutoCommand.run(imageExposeCallback, imageSaver);
64        } else {
65            mLog.i("running flash-off command: " + mFlashOffCommand);
66            mFlashOffCommand.run(imageExposeCallback, imageSaver);
67        }
68    }
69}
70