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 17 package com.android.camera.one.v2.photo; 18 19 import android.hardware.camera2.CameraAccessException; 20 21 import com.android.camera.async.Updatable; 22 import com.android.camera.debug.Log; 23 import com.android.camera.debug.Logger; 24 import com.android.camera.one.OneCamera; 25 import com.android.camera.one.v2.camera2proxy.CameraCaptureSessionClosedException; 26 import com.android.camera.one.v2.core.ResourceAcquisitionFailedException; 27 import com.android.camera.one.v2.imagesaver.ImageSaver; 28 import com.google.common.base.Supplier; 29 30 import javax.annotation.ParametersAreNonnullByDefault; 31 32 @ParametersAreNonnullByDefault 33 final 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 FlashBasedPhotoCommand(Logger.Factory logFactory, Supplier<OneCamera.PhotoCaptureParameters.Flash> flashMode, ImageCaptureCommand flashOnCommand, ImageCaptureCommand flashAutoCommand, ImageCaptureCommand flashOffCommand)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 run(Updatable<Void> imageExposeCallback, ImageSaver imageSaver)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