Fix view-based selfie flash.

fork-5.53.8
Alex Hart 2022-08-30 13:56:29 -03:00 zatwierdzone przez Greyson Parrelli
rodzic 6cb359b2d0
commit 5a1a23d9ac
2 zmienionych plików z 13 dodań i 1 usunięć

Wyświetl plik

@ -458,6 +458,7 @@ public class CameraXFragment extends LoggingFragment implements CameraFragment {
selfieFlash
);
flashHelper.onWillTakePicture();
cameraController.takePicture(Executors.mainThreadExecutor(), new ImageCapture.OnImageCapturedCallback() {
@Override
public void onCaptureSuccess(@NonNull ImageProxy image) {

Wyświetl plik

@ -23,6 +23,7 @@ final class CameraXSelfieFlashHelper {
private float brightnessBeforeFlash;
private boolean inFlash;
private int flashMode = -1;
CameraXSelfieFlashHelper(@NonNull Window window,
@NonNull CameraController camera,
@ -33,6 +34,13 @@ final class CameraXSelfieFlashHelper {
this.selfieFlash = selfieFlash;
}
void onWillTakePicture() {
if (!inFlash && shouldUseViewBasedFlash()) {
flashMode = camera.getImageCaptureFlashMode();
camera.setImageCaptureFlashMode(ImageCapture.FLASH_MODE_OFF);
}
}
void startFlash() {
if (inFlash || !shouldUseViewBasedFlash()) return;
inFlash = true;
@ -56,6 +64,9 @@ final class CameraXSelfieFlashHelper {
params.screenBrightness = brightnessBeforeFlash;
window.setAttributes(params);
camera.setImageCaptureFlashMode(flashMode);
flashMode = -1;
selfieFlash.animate()
.alpha(0f)
.setDuration(SELFIE_FLASH_DURATION_MS);
@ -66,7 +77,7 @@ final class CameraXSelfieFlashHelper {
private boolean shouldUseViewBasedFlash() {
CameraSelector cameraSelector = camera.getCameraSelector() ;
return camera.getImageCaptureFlashMode() == ImageCapture.FLASH_MODE_ON &&
return (camera.getImageCaptureFlashMode() == ImageCapture.FLASH_MODE_ON || flashMode == ImageCapture.FLASH_MODE_ON) &&
cameraSelector == CameraSelector.DEFAULT_FRONT_CAMERA;
}
}