apply remaining suggestions

pull/59/merge^2
Tim H 8 years ago
parent 122a2cb174
commit 0778f97730
  1. 13
      README.md
  2. 12
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraController.java
  3. 12
      cameraview/src/main/java/com/otaliastudios/cameraview/CameraView.java

@ -216,6 +216,17 @@ camera.addCameraListener(new CameraListener() {
*/
@Override
public void onExposureCorrectionChanged(float newValue, float[] bounds, PointF[] fingers) {}
/**
* Notifies that an error occurred in any of the previously called methods.
* The default implementation will just throw the original exception again to prevent missing
* error handling. Override this method without calling the super method in order to implement
* custom error handling.
*/
@Override
public void onError(CameraException exception) {
throw exception;
}
});
```
@ -525,7 +536,7 @@ These are still things that need to be done, off the top of my head:
- [ ] add a `setPreferredAspectRatio` API to choose the capture size. Preview size will adapt, and then, if let free, the CameraView will adapt as well
- [ ] animate grid lines similar to stock camera app
- [ ] add onRequestPermissionResults for easy permission callback
- [ ] better error handling, maybe with a onError(e) method in the public listener, or have each public method return a boolean
- [ ] better error handling, maybe extending the current onError(e) method to handle more use cases, or have each public method return a boolean
- [ ] decent code coverage
## Device-specific issues

@ -98,7 +98,9 @@ abstract class CameraController implements CameraPreview.SurfaceCallback {
mCameraCallbacks.dispatchOnCameraOpened(mOptions);
} catch (Exception e) {
mCameraCallbacks.onError("Error while starting the camera engine.", e);
CameraException cameraException =
new CameraException("Error while starting the camera engine.", e);
mCameraCallbacks.onError(cameraException);
}
}
});
@ -121,7 +123,9 @@ abstract class CameraController implements CameraPreview.SurfaceCallback {
mCameraCallbacks.dispatchOnCameraClosed();
} catch (Exception e) {
mCameraCallbacks.onError("Error while stopping the camera engine.", e);
CameraException cameraException =
new CameraException("Error while stopping the camera engine.", e);
mCameraCallbacks.onError(cameraException);
}
}
});
@ -168,7 +172,9 @@ abstract class CameraController implements CameraPreview.SurfaceCallback {
mCameraCallbacks.dispatchOnCameraOpened(mOptions);
} catch (Exception e) {
mCameraCallbacks.onError("Error while restarting the camera engine.", e);
CameraException cameraException =
new CameraException("Error while restarting the camera engine.", e);
mCameraCallbacks.onError(cameraException);
}
}
});

@ -1308,7 +1308,7 @@ public class CameraView extends FrameLayout {
void dispatchOnFocusEnd(@Nullable Gesture trigger, boolean success, PointF where);
void dispatchOnZoomChanged(final float newValue, final PointF[] fingers);
void dispatchOnExposureCorrectionChanged(float newValue, float[] bounds, PointF[] fingers);
void onError(String message, Exception cause);
void onError(CameraException exception);
}
private class Callbacks implements CameraCallbacks {
@ -1560,21 +1560,19 @@ public class CameraView extends FrameLayout {
/**
* Log and redirect the given error information to the CameraListeners.
*
* @param message a message describing which camera action failed
* @param cause the original exception that caused the error
* @param exception the error cause
*/
@Override
public void onError(String message, Exception cause) {
public void onError(final CameraException exception) {
// log
LOG.e(message, cause);
LOG.e(exception.getMessage(), exception.getCause());
// redirect
final CameraException cameraException = new CameraException(message, cause);
mUiHandler.post(new Runnable() {
@Override
public void run() {
for (CameraListener listener : mListeners) {
listener.onError(cameraException);
listener.onError(exception);
}
}
});

Loading…
Cancel
Save