@SuppressWarnings("WrongConstant")
  private void setCameraDisplayOrientation(Camera.Parameters parameters) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(getCurrentCameraId(), info);
    final int deviceOrientation = Degrees.getDisplayRotation(getActivity());
    mDisplayOrientation =
        Degrees.getDisplayOrientation(
            info.orientation,
            deviceOrientation,
            info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT);
    Log.d(
        "CameraFragment",
        String.format(
            "Orientations: Sensor = %d˚, Device = %d˚, Display = %d˚",
            info.orientation, deviceOrientation, mDisplayOrientation));

    int previewOrientation;
    if (CameraUtil.isArcWelder()) {
      previewOrientation = 0;
    } else {
      previewOrientation = mDisplayOrientation;
      if (Degrees.isPortrait(deviceOrientation)
          && getCurrentCameraPosition() == CAMERA_POSITION_FRONT)
        previewOrientation = Degrees.mirror(mDisplayOrientation);
    }
    parameters.setRotation(previewOrientation);
    mCamera.setDisplayOrientation(previewOrientation);
  }
  @Override
  public void stopRecordingVideo(final boolean reachedZero) {
    super.stopRecordingVideo(reachedZero);

    if (mInterface.hasLengthLimit()
        && mInterface.shouldAutoSubmit()
        && (mInterface.getRecordingStart() < 0 || mMediaRecorder == null)) {
      stopCounter();
      if (mCamera != null) {
        try {
          mCamera.lock();
        } catch (Throwable t) {
          t.printStackTrace();
        }
      }
      releaseRecorder();
      closeCamera();
      mButtonFacing.postDelayed(
          new Runnable() {
            @Override
            public void run() {
              mInterface.onShowPreview(mOutputUri, reachedZero);
            }
          },
          100);
      return;
    }

    if (mCamera != null) mCamera.lock();
    releaseRecorder();
    closeCamera();

    if (!mInterface.didRecord()) mOutputUri = null;

    mButtonVideo.setImageDrawable(VC.get(this, R.drawable.mcam_action_capture));
    if (!CameraUtil.isArcWelder()) mButtonFacing.setVisibility(View.VISIBLE);
    if (mInterface.getRecordingStart() > -1 && getActivity() != null)
      mInterface.onShowPreview(mOutputUri, reachedZero);

    stopCounter();
  }
  @Override
  public boolean startRecordingVideo() {
    super.startRecordingVideo();
    if (prepareMediaRecorder()) {
      try {
        // UI
        mButtonVideo.setImageDrawable(VC.get(this, R.drawable.mcam_action_stop));
        if (!CameraUtil.isArcWelder()) mButtonFacing.setVisibility(View.GONE);

        // Only start counter if count down wasn't already started
        if (!mInterface.hasLengthLimit()) {
          mInterface.setRecordingStart(System.currentTimeMillis());
          startCounter();
        }

        // Start recording
        mMediaRecorder.start();

        mButtonVideo.setEnabled(false);
        mButtonVideo.postDelayed(
            new Runnable() {
              @Override
              public void run() {
                mButtonVideo.setEnabled(true);
              }
            },
            200);

        return true;
      } catch (Throwable t) {
        t.printStackTrace();
        mInterface.setRecordingStart(-1);
        stopRecordingVideo(false);
        throwError(new Exception("Failed to start recording: " + t.getMessage(), t));
      }
    }
    return false;
  }