@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);
  }
  public Intent getIntent() {
    final Class<?> cls =
        !mForceCamera1 && CameraUtil.hasCamera2(mContext)
            ? CaptureActivity2.class
            : CaptureActivity.class;
    Intent intent =
        new Intent(mContext, cls)
            .putExtra(CameraIntentKey.LENGTH_LIMIT, mLengthLimit)
            .putExtra(CameraIntentKey.ALLOW_RETRY, mAllowRetry)
            .putExtra(CameraIntentKey.AUTO_SUBMIT, mAutoSubmit)
            .putExtra(CameraIntentKey.SAVE_DIR, mSaveDir)
            .putExtra(CameraIntentKey.PRIMARY_COLOR, mPrimaryColor)
            .putExtra(CameraIntentKey.SHOW_PORTRAIT_WARNING, mShowPortraitWarning)
            .putExtra(CameraIntentKey.DEFAULT_TO_FRONT_FACING, mDefaultToFrontFacing)
            .putExtra(CameraIntentKey.COUNTDOWN_IMMEDIATELY, mCountdownImmediately)
            .putExtra(CameraIntentKey.RETRY_EXITS, mRetryExists)
            .putExtra(CameraIntentKey.RESTART_TIMER_ON_RETRY, mRestartTimerOnRetry)
            .putExtra(CameraIntentKey.CONTINUE_TIMER_IN_PLAYBACK, mContinueTimerInPlayback);

    if (mVideoBitRate > 0) intent.putExtra(CameraIntentKey.VIDEO_BIT_RATE, mVideoBitRate);
    if (mVideoFrameRate > 0) intent.putExtra(CameraIntentKey.VIDEO_FRAME_RATE, mVideoFrameRate);
    if (mVideoPreferredHeight > 0)
      intent.putExtra(CameraIntentKey.VIDEO_PREFERRED_HEIGHT, mVideoPreferredHeight);
    if (mVideoPreferredAspect > 0f)
      intent.putExtra(CameraIntentKey.VIDEO_PREFERRED_ASPECT, mVideoPreferredAspect);
    return intent;
  }
  @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;
  }