kopia lustrzana https://github.com/ryukoposting/Signal-Android
Utilize debouncer instead of animator timeout for video capture end time.
rodzic
6aa4706e9b
commit
8f85b58612
|
@ -1,7 +1,6 @@
|
||||||
package org.thoughtcrime.securesms.mediasend;
|
package org.thoughtcrime.securesms.mediasend;
|
||||||
|
|
||||||
import android.Manifest;
|
import android.Manifest;
|
||||||
import android.animation.Animator;
|
|
||||||
import android.animation.ValueAnimator;
|
import android.animation.ValueAnimator;
|
||||||
import android.annotation.SuppressLint;
|
import android.annotation.SuppressLint;
|
||||||
import android.content.Context;
|
import android.content.Context;
|
||||||
|
@ -23,11 +22,13 @@ import com.bumptech.glide.util.Executors;
|
||||||
import org.signal.core.util.logging.Log;
|
import org.signal.core.util.logging.Log;
|
||||||
import org.thoughtcrime.securesms.R;
|
import org.thoughtcrime.securesms.R;
|
||||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||||
|
import org.thoughtcrime.securesms.util.Debouncer;
|
||||||
import org.thoughtcrime.securesms.util.MemoryFileDescriptor;
|
import org.thoughtcrime.securesms.util.MemoryFileDescriptor;
|
||||||
import org.thoughtcrime.securesms.video.VideoUtil;
|
import org.thoughtcrime.securesms.video.VideoUtil;
|
||||||
|
|
||||||
import java.io.FileDescriptor;
|
import java.io.FileDescriptor;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
@RequiresApi(26)
|
@RequiresApi(26)
|
||||||
class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener {
|
class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener {
|
||||||
|
@ -41,9 +42,10 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
||||||
private final @NonNull Callback callback;
|
private final @NonNull Callback callback;
|
||||||
private final @NonNull MemoryFileDescriptor memoryFileDescriptor;
|
private final @NonNull MemoryFileDescriptor memoryFileDescriptor;
|
||||||
private final @NonNull ValueAnimator updateProgressAnimator;
|
private final @NonNull ValueAnimator updateProgressAnimator;
|
||||||
|
private final @NonNull Debouncer debouncer;
|
||||||
|
|
||||||
private boolean isRecording;
|
private boolean isRecording;
|
||||||
private ValueAnimator cameraMetricsAnimator;
|
private ValueAnimator cameraMetricsAnimator;
|
||||||
|
|
||||||
private final VideoCapture.OnVideoSavedCallback videoSavedListener = new VideoCapture.OnVideoSavedCallback() {
|
private final VideoCapture.OnVideoSavedCallback videoSavedListener = new VideoCapture.OnVideoSavedCallback() {
|
||||||
@SuppressLint("RestrictedApi")
|
@SuppressLint("RestrictedApi")
|
||||||
|
@ -51,6 +53,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
||||||
public void onVideoSaved(@NonNull VideoCapture.OutputFileResults outputFileResults) {
|
public void onVideoSaved(@NonNull VideoCapture.OutputFileResults outputFileResults) {
|
||||||
try {
|
try {
|
||||||
isRecording = false;
|
isRecording = false;
|
||||||
|
debouncer.clear();
|
||||||
camera.setZoomRatio(camera.getMinZoomRatio());
|
camera.setZoomRatio(camera.getMinZoomRatio());
|
||||||
memoryFileDescriptor.seek(0);
|
memoryFileDescriptor.seek(0);
|
||||||
callback.onVideoSaved(memoryFileDescriptor.getFileDescriptor());
|
callback.onVideoSaved(memoryFileDescriptor.getFileDescriptor());
|
||||||
|
@ -63,6 +66,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
||||||
@Override
|
@Override
|
||||||
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
|
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
|
||||||
isRecording = false;
|
isRecording = false;
|
||||||
|
debouncer.clear();
|
||||||
callback.onVideoError(cause);
|
callback.onVideoError(cause);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -71,23 +75,18 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
||||||
@NonNull CameraButtonView captureButton,
|
@NonNull CameraButtonView captureButton,
|
||||||
@NonNull SignalCameraView camera,
|
@NonNull SignalCameraView camera,
|
||||||
@NonNull MemoryFileDescriptor memoryFileDescriptor,
|
@NonNull MemoryFileDescriptor memoryFileDescriptor,
|
||||||
int maxVideoDurationSec,
|
int maxVideoDurationSec,
|
||||||
@NonNull Callback callback)
|
@NonNull Callback callback)
|
||||||
{
|
{
|
||||||
this.fragment = fragment;
|
this.fragment = fragment;
|
||||||
this.camera = camera;
|
this.camera = camera;
|
||||||
this.memoryFileDescriptor = memoryFileDescriptor;
|
this.memoryFileDescriptor = memoryFileDescriptor;
|
||||||
this.callback = callback;
|
this.callback = callback;
|
||||||
this.updateProgressAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(maxVideoDurationSec * 1000);
|
this.updateProgressAnimator = ValueAnimator.ofFloat(0f, 1f).setDuration(TimeUnit.SECONDS.toMillis(maxVideoDurationSec));
|
||||||
|
this.debouncer = new Debouncer(TimeUnit.SECONDS.toMillis(maxVideoDurationSec));
|
||||||
|
|
||||||
updateProgressAnimator.setInterpolator(new LinearInterpolator());
|
updateProgressAnimator.setInterpolator(new LinearInterpolator());
|
||||||
updateProgressAnimator.addUpdateListener(anim -> captureButton.setProgress(anim.getAnimatedFraction()));
|
updateProgressAnimator.addUpdateListener(anim -> captureButton.setProgress(anim.getAnimatedFraction()));
|
||||||
updateProgressAnimator.addListener(new AnimationEndCallback() {
|
|
||||||
@Override
|
|
||||||
public void onAnimationEnd(Animator animation) {
|
|
||||||
if (isRecording) onVideoCaptureComplete();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -126,14 +125,15 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
||||||
|
|
||||||
camera.startRecording(options, Executors.mainThreadExecutor(), videoSavedListener);
|
camera.startRecording(options, Executors.mainThreadExecutor(), videoSavedListener);
|
||||||
updateProgressAnimator.start();
|
updateProgressAnimator.start();
|
||||||
|
debouncer.publish(this::onVideoCaptureComplete);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shrinkCaptureArea() {
|
private void shrinkCaptureArea() {
|
||||||
Size screenSize = getScreenSize();
|
Size screenSize = getScreenSize();
|
||||||
Size videoRecordingSize = VideoUtil.getVideoRecordingSize();
|
Size videoRecordingSize = VideoUtil.getVideoRecordingSize();
|
||||||
float scale = getSurfaceScaleForRecording();
|
float scale = getSurfaceScaleForRecording();
|
||||||
float targetWidthForAnimation = videoRecordingSize.getWidth() * scale;
|
float targetWidthForAnimation = videoRecordingSize.getWidth() * scale;
|
||||||
float scaleX = targetWidthForAnimation / screenSize.getWidth();
|
float scaleX = targetWidthForAnimation / screenSize.getWidth();
|
||||||
|
|
||||||
if (scaleX == 1f) {
|
if (scaleX == 1f) {
|
||||||
float targetHeightForAnimation = videoRecordingSize.getHeight() * scale;
|
float targetHeightForAnimation = videoRecordingSize.getHeight() * scale;
|
||||||
|
@ -190,6 +190,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
||||||
}
|
}
|
||||||
|
|
||||||
updateProgressAnimator.cancel();
|
updateProgressAnimator.cancel();
|
||||||
|
debouncer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -206,27 +207,11 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static abstract class AnimationEndCallback implements Animator.AnimatorListener {
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void onAnimationStart(Animator animation) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void onAnimationCancel(Animator animation) {
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public final void onAnimationRepeat(Animator animation) {
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
interface Callback {
|
interface Callback {
|
||||||
void onVideoRecordStarted();
|
void onVideoRecordStarted();
|
||||||
|
|
||||||
void onVideoSaved(@NonNull FileDescriptor fd);
|
void onVideoSaved(@NonNull FileDescriptor fd);
|
||||||
|
|
||||||
void onVideoError(@Nullable Throwable cause);
|
void onVideoError(@Nullable Throwable cause);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue