Home | History | Annotate | Download | only in common
      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.common;
     18 
     19 import android.hardware.camera2.CaptureResult;
     20 import android.hardware.camera2.TotalCaptureResult;
     21 
     22 import com.android.camera.async.Updatable;
     23 import com.android.camera.one.v2.core.ResponseListener;
     24 
     25 /**
     26  * A {@link ResponseListener} which listens for a particular metadata key.
     27  */
     28 public class MetadataResponseListener<V> extends ResponseListener {
     29     private final Updatable<V> mUpdatable;
     30     private final CaptureResult.Key<V> mKey;
     31 
     32     /**
     33      * @param key The key associated with the value for which to listen to
     34      *            changes.
     35      */
     36     public MetadataResponseListener(CaptureResult.Key<V> key, Updatable<V> updatable) {
     37         mKey = key;
     38         mUpdatable = updatable;
     39     }
     40 
     41     @Override
     42     public void onProgressed(CaptureResult partialResult) {
     43         V newValue = partialResult.get(mKey);
     44         if (newValue != null) {
     45             mUpdatable.update(newValue);
     46         }
     47     }
     48 
     49     @Override
     50     public void onCompleted(TotalCaptureResult totalCaptureResult) {
     51         V newValue = totalCaptureResult.get(mKey);
     52         if (newValue != null) {
     53             mUpdatable.update(newValue);
     54         }
     55     }
     56 }
     57