Increase logging around camera errors, skip toast if context is null.

This commit is contained in:
Alex Hart
2021-11-09 09:16:09 -04:00
parent 5dd3d8515f
commit 151e2e5203
2 changed files with 9 additions and 1 deletions

View File

@@ -403,6 +403,7 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
try {
return CameraXUtil.toJpeg(image, camera.getCameraLensFacing() == CameraSelector.LENS_FACING_FRONT);
} catch (IOException e) {
Log.w(TAG, "Failed to encode captured image.", e);
return null;
} finally {
image.close();
@@ -421,6 +422,7 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
@Override
public void onError(ImageCaptureException exception) {
Log.w(TAG, "Failed to capture image", exception);
flashHelper.endFlash();
controller.onCameraError();
}

View File

@@ -99,7 +99,13 @@ class MediaCaptureFragment : Fragment(R.layout.fragment_container), CameraFragme
override fun onCameraError() {
Log.w(TAG, "Camera Error.")
Toast.makeText(requireContext(), R.string.MediaSendActivity_camera_unavailable, Toast.LENGTH_SHORT).show()
val context = this.context
if (context != null) {
Toast.makeText(context, R.string.MediaSendActivity_camera_unavailable, Toast.LENGTH_SHORT).show()
} else {
Log.w(TAG, "Could not post toast, fragment not attached to a context.")
}
}
override fun onImageCaptured(data: ByteArray, width: Int, height: Int) {