Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(bank-sdk): Added forced autofocus before image capture #550

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -444,33 +444,18 @@ public CompletableFuture<Photo> takePicture() {
// as being stopped before it is really stopped
mPreviewRunning = false;

CompletableFuture<Boolean> focusFuture = new CompletableFuture<>();
if (isUsingFocusMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE, mCamera)) {
// When continuous focus mode is used no auto-focus run is needed
focusFuture.complete(true);
} else {
// Continuous focus mode is not used and we need to do an auto-focus run
focusFuture = focus();
}

focusFuture.handle(new CompletableFuture.BiFun<Boolean, Throwable, Void>() {
@Override
public Void apply(final Boolean aBoolean, final Throwable throwable) {
takePicture(new Camera.PictureCallback() {
@Override
public void onPictureTaken(final byte[] bytes, final Camera camera) {
mTakingPictureFuture.set(null);
final Photo photo = PhotoFactory.newPhotoFromJpeg(bytes,
getDisplayOrientationForCamera(mActivity),
getDeviceOrientation(mActivity),
getDeviceType(mActivity),
Document.Source.newCameraSource());
LOG.info("Picture taken");
pictureTaken.complete(photo);
}
});
return null;
}
focus().handle((CompletableFuture.BiFun<Boolean, Throwable, Void>) (aBoolean, throwable) -> {
takePicture((bytes, camera) -> {
mTakingPictureFuture.set(null);
final Photo photo = PhotoFactory.newPhotoFromJpeg(bytes,
getDisplayOrientationForCamera(mActivity),
getDeviceOrientation(mActivity),
getDeviceType(mActivity),
Document.Source.newCameraSource());
LOG.info("Picture taken");
pictureTaken.complete(photo);
});
return null;
});

return pictureTaken;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -307,49 +307,52 @@ internal class CameraXController(val activity: Activity) : CameraInterface {
return pictureFuture
}

imageCaptureUseCase?.takePicture(ContextCompat.getMainExecutor(activity),
object : ImageCapture.OnImageCapturedCallback() {
override fun onCaptureSuccess(image: ImageProxy) {
// Not playing shutter sound because on some devices (for eg. Samsung Galaxy S9) it
// always plays at 100% volume
// mediaActionSound?.play(MediaActionSound.SHUTTER_CLICK)
focus().thenApply {
imageCaptureUseCase?.takePicture(ContextCompat.getMainExecutor(activity),
object : ImageCapture.OnImageCapturedCallback() {
override fun onCaptureSuccess(image: ImageProxy) {
// Not playing shutter sound because on some devices (for eg. Samsung Galaxy S9) it
// always plays at 100% volume
// mediaActionSound?.play(MediaActionSound.SHUTTER_CLICK)

vibrate(SHUTTER_VIBRATION_DURATION_MS)

val byteArray = try {
image.toCroppedByteArray()
} catch (e: CameraException) {
LOG.error("Failed to take picture", e)
pictureFuture.completeExceptionally(e)
image.close()
return
}

val photo = PhotoFactory.newPhotoFromJpeg(
byteArray,
image.imageInfo.rotationDegrees,
DeviceHelper.getDeviceOrientation(activity),
DeviceHelper.getDeviceType(activity),
Document.Source.newCameraSource()
)

vibrate(SHUTTER_VIBRATION_DURATION_MS)
LOG.info("Picture taken with resolution {}x{}", image.cropRect.width(),
image.cropRect.height())

val byteArray = try {
image.toCroppedByteArray()
} catch (e: CameraException) {
LOG.error("Failed to take picture", e)
pictureFuture.completeExceptionally(e)
pictureFuture.complete(photo)
image.close()
return
}

val photo = PhotoFactory.newPhotoFromJpeg(
byteArray,
image.imageInfo.rotationDegrees,
DeviceHelper.getDeviceOrientation(activity),
DeviceHelper.getDeviceType(activity),
Document.Source.newCameraSource()
)

LOG.info("Picture taken with resolution {}x{}", image.cropRect.width(),
image.cropRect.height())

pictureFuture.complete(photo)
image.close()
}

override fun onError(exception: ImageCaptureException) {
LOG.error("Failed to take picture", exception)
pictureFuture.completeExceptionally(
CameraException(
exception,
CameraException.Type.SHOT_FAILED
override fun onError(exception: ImageCaptureException) {
LOG.error("Failed to take picture", exception)
pictureFuture.completeExceptionally(
CameraException(
exception,
CameraException.Type.SHOT_FAILED
)
)
)
}
})
}
})
}

return pictureFuture
}
Expand Down