Here's a rundown on how the code sets up the preview:
- First, we set up the TextureView.SurfaceTextureListener with the setSurfaceTextureListener() method in onCreate()
- When we get the onSurfaceTextureAvailable() callback, we open the camera
- We pass our CameraDevice.StateCallback class to the openCamera() method, which eventually calls the onOpened() callback
- onOpened() gets the surface for the preview by calling getSurfaceTexture() and passes it to the CameraDevice by calling createCaptureSession()
- Finally, when CameraCaptureSession.StateCallback onConfigured() is called, we start the preview with the setRepeatingRequest() method