check for newer exceptions inside of the error listener handling

pull/59/merge^2
Tim H 7 years ago
parent 910f4da42c
commit 1f748c36ae
  1. 4
      cameraview/src/main/java/com/otaliastudios/cameraview/Camera1.java
  2. 11
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java

@ -797,8 +797,8 @@ class Camera1 extends CameraController {
return true; return true;
} }
catch (Exception e) { catch (Exception e) {
// at least setParameters may fail. // at least getParameters and setParameters may fail.
// TODO why does it fail and is it possible to prevent such errors? // TODO why do they fail and is it possible to prevent such errors?
CameraException cameraException = new CameraConfigurationFailedException("Failed to " + CameraException cameraException = new CameraConfigurationFailedException("Failed to " +
"start auto focus.", e); "start auto focus.", e);
mCameraCallbacks.onError(cameraException); mCameraCallbacks.onError(cameraException);

@ -1579,15 +1579,24 @@ public class CameraView extends FrameLayout {
public void run() { public void run() {
// all error listeners will be called, but at most one of them should actually // all error listeners will be called, but at most one of them should actually
// throw the exception // throw an exception
int count = 0; int count = 0;
for (CameraListener listener : mListeners) { for (CameraListener listener : mListeners) {
try { try {
listener.onError(exception); listener.onError(exception);
} catch (CameraException ce) { } catch (CameraException ce) {
// if a custom error handler caused a new exception, we throw the new
// one instead of the original one
if (ce == exception) {
count++; count++;
} }
else {
throw ce;
} }
}
}
// the original exception is only thrown, if all existing listeners threw it
if (count == mListeners.size()) { if (count == mListeners.size()) {
throw exception; throw exception;
} }

Loading…
Cancel
Save