1 /* 2 * Copyright (C) 2014 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.initialization; 18 19 import com.android.camera.one.OneCamera; 20 import com.android.camera.one.v2.photo.PictureTaker; 21 import com.android.camera.session.CaptureSession; 22 23 import java.util.concurrent.CancellationException; 24 import java.util.concurrent.ExecutionException; 25 import java.util.concurrent.Future; 26 27 /** 28 * A {@link PictureTaker} on which {@link #takePicture} may be called even if 29 * the underlying camera is not yet ready. 30 */ 31 class DeferredPictureTaker implements PictureTaker { 32 private final Future<PictureTaker> mPictureTakerFuture; 33 DeferredPictureTaker(Future<PictureTaker> pictureTakerFuture)34 public DeferredPictureTaker(Future<PictureTaker> pictureTakerFuture) { 35 mPictureTakerFuture = pictureTakerFuture; 36 } 37 38 @Override takePicture(OneCamera.PhotoCaptureParameters params, CaptureSession session)39 public void takePicture(OneCamera.PhotoCaptureParameters params, CaptureSession session) { 40 if (mPictureTakerFuture.isDone()) { 41 try { 42 PictureTaker taker = mPictureTakerFuture.get(); 43 taker.takePicture(params, session); 44 } catch (InterruptedException | ExecutionException | CancellationException e) { 45 return; 46 } 47 } 48 } 49 } 50