Search in sources :

Example 1 with CameraXFlashToggleView

use of org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView in project Signal-Android by signalapp.

the class CameraXFragment method initControls.

@SuppressLint({ "ClickableViewAccessibility", "MissingPermission" })
private void initControls() {
    View flipButton = requireView().findViewById(R.id.camera_flip_button);
    CameraButtonView captureButton = requireView().findViewById(R.id.camera_capture_button);
    View galleryButton = requireView().findViewById(R.id.camera_gallery_button);
    View countButton = requireView().findViewById(R.id.camera_review_button);
    CameraXFlashToggleView flashButton = requireView().findViewById(R.id.camera_flash_button);
    selfieFlash = requireView().findViewById(R.id.camera_selfie_flash);
    captureButton.setOnClickListener(v -> {
        captureButton.setEnabled(false);
        flipButton.setEnabled(false);
        flashButton.setEnabled(false);
        onCaptureClicked();
    });
    camera.setScaleType(PreviewView.ScaleType.FILL_CENTER);
    ProcessCameraProvider.getInstance(requireContext()).addListener(() -> initializeFlipButton(flipButton, flashButton), Executors.mainThreadExecutor());
    flashButton.setAutoFlashEnabled(camera.hasFlash());
    flashButton.setFlash(camera.getFlash());
    flashButton.setOnFlashModeChangedListener(camera::setFlash);
    galleryButton.setOnClickListener(v -> controller.onGalleryClicked());
    countButton.setOnClickListener(v -> controller.onCameraCountButtonClicked());
    if (isVideoRecordingSupported(requireContext())) {
        try {
            closeVideoFileDescriptor();
            videoFileDescriptor = CameraXVideoCaptureHelper.createFileDescriptor(requireContext());
            Animation inAnimation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_in);
            Animation outAnimation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_out);
            camera.setCaptureMode(SignalCameraView.CaptureMode.MIXED);
            int maxDuration = VideoUtil.getMaxVideoRecordDurationInSeconds(requireContext(), controller.getMediaConstraints());
            Log.d(TAG, "Max duration: " + maxDuration + " sec");
            captureButton.setVideoCaptureListener(new CameraXVideoCaptureHelper(this, captureButton, camera, videoFileDescriptor, maxDuration, new CameraXVideoCaptureHelper.Callback() {

                @Override
                public void onVideoRecordStarted() {
                    hideAndDisableControlsForVideoRecording(captureButton, flashButton, flipButton, outAnimation);
                }

                @Override
                public void onVideoSaved(@NonNull FileDescriptor fd) {
                    showAndEnableControlsAfterVideoRecording(captureButton, flashButton, flipButton, inAnimation);
                    controller.onVideoCaptured(fd);
                }

                @Override
                public void onVideoError(@Nullable Throwable cause) {
                    showAndEnableControlsAfterVideoRecording(captureButton, flashButton, flipButton, inAnimation);
                    controller.onVideoCaptureError();
                }
            }));
            displayVideoRecordingTooltipIfNecessary(captureButton);
        } catch (IOException e) {
            Log.w(TAG, "Video capture is not supported on this device.", e);
        }
    } else {
        Log.i(TAG, "Video capture not supported. " + "API: " + Build.VERSION.SDK_INT + ", " + "MFD: " + MemoryFileDescriptor.supported() + ", " + "Camera: " + CameraXUtil.getLowestSupportedHardwareLevel(requireContext()) + ", " + "MaxDuration: " + VideoUtil.getMaxVideoRecordDurationInSeconds(requireContext(), controller.getMediaConstraints()) + " sec");
    }
}
Also used : CameraXFlashToggleView(org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) PreviewView(androidx.camera.view.PreviewView) CameraXFlashToggleView(org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView) SignalCameraView(androidx.camera.view.SignalCameraView) SuppressLint(android.annotation.SuppressLint) MemoryFileDescriptor(org.thoughtcrime.securesms.util.MemoryFileDescriptor) FileDescriptor(java.io.FileDescriptor) NonNull(androidx.annotation.NonNull) Animation(android.view.animation.Animation) RotateAnimation(android.view.animation.RotateAnimation) Nullable(androidx.annotation.Nullable) SuppressLint(android.annotation.SuppressLint)

Example 2 with CameraXFlashToggleView

use of org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView in project Signal-Android by WhisperSystems.

the class CameraXFragment method initControls.

@SuppressLint({ "ClickableViewAccessibility", "MissingPermission" })
private void initControls() {
    View flipButton = requireView().findViewById(R.id.camera_flip_button);
    CameraButtonView captureButton = requireView().findViewById(R.id.camera_capture_button);
    View galleryButton = requireView().findViewById(R.id.camera_gallery_button);
    View countButton = requireView().findViewById(R.id.camera_review_button);
    CameraXFlashToggleView flashButton = requireView().findViewById(R.id.camera_flash_button);
    selfieFlash = requireView().findViewById(R.id.camera_selfie_flash);
    captureButton.setOnClickListener(v -> {
        captureButton.setEnabled(false);
        flipButton.setEnabled(false);
        flashButton.setEnabled(false);
        onCaptureClicked();
    });
    camera.setScaleType(PreviewView.ScaleType.FILL_CENTER);
    ProcessCameraProvider.getInstance(requireContext()).addListener(() -> initializeFlipButton(flipButton, flashButton), Executors.mainThreadExecutor());
    flashButton.setAutoFlashEnabled(camera.hasFlash());
    flashButton.setFlash(camera.getFlash());
    flashButton.setOnFlashModeChangedListener(camera::setFlash);
    galleryButton.setOnClickListener(v -> controller.onGalleryClicked());
    countButton.setOnClickListener(v -> controller.onCameraCountButtonClicked());
    if (isVideoRecordingSupported(requireContext())) {
        try {
            closeVideoFileDescriptor();
            videoFileDescriptor = CameraXVideoCaptureHelper.createFileDescriptor(requireContext());
            Animation inAnimation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_in);
            Animation outAnimation = AnimationUtils.loadAnimation(requireContext(), R.anim.fade_out);
            camera.setCaptureMode(SignalCameraView.CaptureMode.MIXED);
            int maxDuration = VideoUtil.getMaxVideoRecordDurationInSeconds(requireContext(), controller.getMediaConstraints());
            Log.d(TAG, "Max duration: " + maxDuration + " sec");
            captureButton.setVideoCaptureListener(new CameraXVideoCaptureHelper(this, captureButton, camera, videoFileDescriptor, maxDuration, new CameraXVideoCaptureHelper.Callback() {

                @Override
                public void onVideoRecordStarted() {
                    hideAndDisableControlsForVideoRecording(captureButton, flashButton, flipButton, outAnimation);
                }

                @Override
                public void onVideoSaved(@NonNull FileDescriptor fd) {
                    showAndEnableControlsAfterVideoRecording(captureButton, flashButton, flipButton, inAnimation);
                    controller.onVideoCaptured(fd);
                }

                @Override
                public void onVideoError(@Nullable Throwable cause) {
                    showAndEnableControlsAfterVideoRecording(captureButton, flashButton, flipButton, inAnimation);
                    controller.onVideoCaptureError();
                }
            }));
            displayVideoRecordingTooltipIfNecessary(captureButton);
        } catch (IOException e) {
            Log.w(TAG, "Video capture is not supported on this device.", e);
        }
    } else {
        Log.i(TAG, "Video capture not supported. " + "API: " + Build.VERSION.SDK_INT + ", " + "MFD: " + MemoryFileDescriptor.supported() + ", " + "Camera: " + CameraXUtil.getLowestSupportedHardwareLevel(requireContext()) + ", " + "MaxDuration: " + VideoUtil.getMaxVideoRecordDurationInSeconds(requireContext(), controller.getMediaConstraints()) + " sec");
    }
}
Also used : CameraXFlashToggleView(org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView) IOException(java.io.IOException) ImageView(android.widget.ImageView) View(android.view.View) PreviewView(androidx.camera.view.PreviewView) CameraXFlashToggleView(org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView) SignalCameraView(androidx.camera.view.SignalCameraView) SuppressLint(android.annotation.SuppressLint) MemoryFileDescriptor(org.thoughtcrime.securesms.util.MemoryFileDescriptor) FileDescriptor(java.io.FileDescriptor) NonNull(androidx.annotation.NonNull) Animation(android.view.animation.Animation) RotateAnimation(android.view.animation.RotateAnimation) Nullable(androidx.annotation.Nullable) SuppressLint(android.annotation.SuppressLint)

Aggregations

SuppressLint (android.annotation.SuppressLint)2 View (android.view.View)2 Animation (android.view.animation.Animation)2 RotateAnimation (android.view.animation.RotateAnimation)2 ImageView (android.widget.ImageView)2 NonNull (androidx.annotation.NonNull)2 Nullable (androidx.annotation.Nullable)2 PreviewView (androidx.camera.view.PreviewView)2 SignalCameraView (androidx.camera.view.SignalCameraView)2 FileDescriptor (java.io.FileDescriptor)2 IOException (java.io.IOException)2 CameraXFlashToggleView (org.thoughtcrime.securesms.mediasend.camerax.CameraXFlashToggleView)2 MemoryFileDescriptor (org.thoughtcrime.securesms.util.MemoryFileDescriptor)2