Home | History | Annotate | Download | only in photo
      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.CaptureFailure;
     20 import android.hardware.camera2.TotalCaptureResult;
     21 
     22 import com.android.camera.one.v2.camera2proxy.AndroidTotalCaptureResultProxy;
     23 import com.android.camera.one.v2.camera2proxy.TotalCaptureResultProxy;
     24 import com.android.camera.one.v2.core.ResponseListener;
     25 import com.google.common.util.concurrent.ListenableFuture;
     26 import com.google.common.util.concurrent.SettableFuture;
     27 
     28 /**
     29  * A ResponseListener which puts the result in a Future. Each instance is only
     30  * good for a single (non-repeating) request.
     31  */
     32 public final class MetadataFuture extends ResponseListener {
     33     private final SettableFuture<TotalCaptureResultProxy> mMetadata;
     34 
     35     public MetadataFuture() {
     36         mMetadata = SettableFuture.create();
     37     }
     38 
     39     @Override
     40     public void onCompleted(TotalCaptureResult result) {
     41         super.onCompleted(result);
     42         mMetadata.set(new AndroidTotalCaptureResultProxy(result));
     43     }
     44 
     45     @Override
     46     public void onFailed(CaptureFailure failure) {
     47         super.onFailed(failure);
     48         if (failure.getReason() == CaptureFailure.REASON_FLUSHED) {
     49             mMetadata.cancel(true);
     50         } else if (failure.getReason() == CaptureFailure.REASON_ERROR) {
     51             mMetadata.setException(new IllegalStateException("CaptureFailure.REASON_ERROR!"));
     52         }
     53     }
     54 
     55     public ListenableFuture<TotalCaptureResultProxy> getMetadata() {
     56         return mMetadata;
     57     }
     58 }
     59