kopia lustrzana https://github.com/ryukoposting/Signal-Android
Fix view-based selfie flash.
rodzic
6cb359b2d0
commit
5a1a23d9ac
|
@ -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) {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue