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.core; 18 19 import android.hardware.camera2.CaptureFailure; 20 import android.hardware.camera2.CaptureResult; 21 import android.hardware.camera2.TotalCaptureResult; 22 23 import com.google.common.collect.ImmutableList; 24 25 import java.util.Collection; 26 27 /** 28 * Combines multiple {@link ResponseListener}s into a single one which 29 * dispatches to all listeners for each callback. 30 */ 31 class ResponseListenerBroadcaster extends ResponseListener { 32 private final ImmutableList<ResponseListener> mListeners; 33 34 public ResponseListenerBroadcaster(ResponseListener[] listeners) { 35 mListeners = ImmutableList.copyOf(listeners); 36 } 37 38 public ResponseListenerBroadcaster(Collection<ResponseListener> listeners) { 39 mListeners = ImmutableList.copyOf(listeners); 40 } 41 42 @Override 43 public void onStarted(long timestamp) { 44 for (ResponseListener listener : mListeners) { 45 listener.onStarted(timestamp); 46 } 47 } 48 49 @Override 50 public void onProgressed(CaptureResult partialResult) { 51 for (ResponseListener listener : mListeners) { 52 listener.onProgressed(partialResult); 53 } 54 } 55 56 @Override 57 public void onCompleted(TotalCaptureResult result) { 58 for (ResponseListener listener : mListeners) { 59 listener.onCompleted(result); 60 } 61 } 62 63 @Override 64 public void onFailed(CaptureFailure failure) { 65 for (ResponseListener listener : mListeners) { 66 listener.onFailed(failure); 67 } 68 } 69 } 70