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;
|
||||
|
||||
import android.Manifest;
|
||||
import android.animation.Animator;
|
||||
import android.animation.ValueAnimator;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
|
@ -23,11 +22,13 @@ import com.bumptech.glide.util.Executors;
|
|||
import org.signal.core.util.logging.Log;
|
||||
import org.thoughtcrime.securesms.R;
|
||||
import org.thoughtcrime.securesms.permissions.Permissions;
|
||||
import org.thoughtcrime.securesms.util.Debouncer;
|
||||
import org.thoughtcrime.securesms.util.MemoryFileDescriptor;
|
||||
import org.thoughtcrime.securesms.video.VideoUtil;
|
||||
|
||||
import java.io.FileDescriptor;
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@RequiresApi(26)
|
||||
class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener {
|
||||
|
@ -41,6 +42,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
|||
private final @NonNull Callback callback;
|
||||
private final @NonNull MemoryFileDescriptor memoryFileDescriptor;
|
||||
private final @NonNull ValueAnimator updateProgressAnimator;
|
||||
private final @NonNull Debouncer debouncer;
|
||||
|
||||
private boolean isRecording;
|
||||
private ValueAnimator cameraMetricsAnimator;
|
||||
|
@ -51,6 +53,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
|||
public void onVideoSaved(@NonNull VideoCapture.OutputFileResults outputFileResults) {
|
||||
try {
|
||||
isRecording = false;
|
||||
debouncer.clear();
|
||||
camera.setZoomRatio(camera.getMinZoomRatio());
|
||||
memoryFileDescriptor.seek(0);
|
||||
callback.onVideoSaved(memoryFileDescriptor.getFileDescriptor());
|
||||
|
@ -63,6 +66,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
|||
@Override
|
||||
public void onError(int videoCaptureError, @NonNull String message, @Nullable Throwable cause) {
|
||||
isRecording = false;
|
||||
debouncer.clear();
|
||||
callback.onVideoError(cause);
|
||||
}
|
||||
};
|
||||
|
@ -78,16 +82,11 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
|||
this.camera = camera;
|
||||
this.memoryFileDescriptor = memoryFileDescriptor;
|
||||
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.addUpdateListener(anim -> captureButton.setProgress(anim.getAnimatedFraction()));
|
||||
updateProgressAnimator.addListener(new AnimationEndCallback() {
|
||||
@Override
|
||||
public void onAnimationEnd(Animator animation) {
|
||||
if (isRecording) onVideoCaptureComplete();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -126,6 +125,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
|||
|
||||
camera.startRecording(options, Executors.mainThreadExecutor(), videoSavedListener);
|
||||
updateProgressAnimator.start();
|
||||
debouncer.publish(this::onVideoCaptureComplete);
|
||||
}
|
||||
|
||||
private void shrinkCaptureArea() {
|
||||
|
@ -190,6 +190,7 @@ class CameraXVideoCaptureHelper implements CameraButtonView.VideoCaptureListener
|
|||
}
|
||||
|
||||
updateProgressAnimator.cancel();
|
||||
debouncer.clear();
|
||||
}
|
||||
|
||||
@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 {
|
||||
void onVideoRecordStarted();
|
||||
|
||||
void onVideoSaved(@NonNull FileDescriptor fd);
|
||||
|
||||
void onVideoError(@Nullable Throwable cause);
|
||||
}
|
||||
}
|
||||
|
|
Ładowanie…
Reference in New Issue