title: How to set viewfinder using CameraX in Java?
body: <p>I have been working on an app which needed to use CameraX for it's preview stream but it also needs a viewfinder. I have successfully implemented the preview but for the viewfinder part most of the codes that I can find online is in Kotlin and I being a newbie can't seem to effectively convert it to my java based code. Any help would be really appreciated.</p>
  <p>My XML preview code:</p>
  <pre><code>&lt;androidx.camera.view.PreviewView
      android:id=&quot;@+id/previewView&quot;
      android:layout_width=&quot;match_parent&quot;
      android:layout_height=&quot;675dp&quot;
      app:layout_constraintStart_toStartOf=&quot;parent&quot;
      app:layout_constraintTop_toBottomOf=&quot;@+id/toolbar&quot;&gt;
  </code></pre>
  <p>My CameraX preview code:</p>
  <pre><code> PreviewView mCameraView;
   Camera camera;
   void startCamera() {
      mCameraView = findViewById(R.id.previewView);
  
      cameraProviderFuture = ProcessCameraProvider.getInstance(this);
  
      cameraProviderFuture.addListener(() -&gt; {
          try {
              ProcessCameraProvider cameraProvider = cameraProviderFuture.get();
              bindPreview(cameraProvider);
          } catch (ExecutionException | InterruptedException e) {
              // No errors need to be handled for this Future.
              // This should never be reached.
          }
      }, ContextCompat.getMainExecutor(this));
  }
  
   void bindPreview(@NonNull ProcessCameraProvider cameraProvider) {
      Preview preview = new Preview.Builder().
              setTargetResolution(BestSize())
              .build();
  
      CameraSelector cameraSelector = new CameraSelector.Builder()
              .requireLensFacing(CameraSelector.LENS_FACING_BACK)
              .build();
  
      preview.setSurfaceProvider(mCameraView.createSurfaceProvider());
      camera = cameraProvider.bindToLifecycle(this, cameraSelector, preview);
  
      }
  
      private int degreesToFirebaseRotation(int degrees) {
      switch (degrees) {
          case 0:
              return FirebaseVisionImageMetadata.ROTATION_0;
          case 90:
              return FirebaseVisionImageMetadata.ROTATION_90;
          case 180:
              return FirebaseVisionImageMetadata.ROTATION_180;
          case 270:
              return FirebaseVisionImageMetadata.ROTATION_270;
          default:
              throw new IllegalArgumentException(
                      &quot;Rotation must be 0, 90, 180, or 270.&quot;);
      }
  }
  </code></pre>
  <p>Sorry for the weird indentation and if the question is stupid. Thanks in advance.</p>