title: how to implement custom SurfaceProvider for android Camera x androidx.camera.core.Preview
body: <p>I'm following this original CameraX Example for Android
  here:
  <a href="https://developer.android.com/codelabs/camerax-getting-started#5" rel="noreferrer">https://developer.android.com/codelabs/camerax-getting-started#5</a>
  and here:
  <a href="https://github.com/android/camera-samples/blob/main/CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt#L337" rel="noreferrer">https://github.com/android/camera-samples/blob/main/CameraXBasic/app/src/main/java/com/android/example/cameraxbasic/fragments/CameraFragment.kt#L337</a></p>
  <p>I want to instantiate my Preview like in the example:</p>
  <pre><code>       val preview = Preview.Builder()
             .build()
             .also {
                 it.setSurfaceProvider(viewFinder.surfaceProvider)
             }
  </code></pre>
  <p>But then i realize ... Well , what a pleasant surprise - <strong>viewFinder</strong> /
  <strong>androidx.camera.view.PreviewView</strong> is from a library which is only an alpha version</p>
  <pre><code>    implementation 'androidx.camera:camera-view:1.0.0-alpha24'
  </code></pre>
  <p>(see here)
  <a href="https://github.com/android/camera-samples/blob/main/CameraXBasic/app/build.gradle" rel="noreferrer">https://github.com/android/camera-samples/blob/main/CameraXBasic/app/build.gradle</a></p>
  <p>I of course don't want to use an alpha version!
  So i thought okay maybe i Can implement my own <strong>SurfaceProvider</strong></p>
  <p>documentation suggests i could do something like that:</p>
  <pre><code>         * class MyGlSurfaceProvider implements Preview.SurfaceProvider {
           *     // This executor must have also been used with Preview.setSurfaceProvider() to
           *     // ensure onSurfaceRequested() is called on our GL thread.
           *     Executor mGlExecutor;
           *
           *     {@literal @}Override
           *     public void onSurfaceRequested(@NonNull SurfaceRequest request) {
           *         // If our GL thread/context is shutting down. Signal we will not fulfill
           *         // the request.
           *         if (isShuttingDown()) {
           *             request.willNotProvideSurface();
           *             return;
           *         }
           *
           *         // Create the surface and attempt to provide it to the camera.
           *         Surface surface = resetGlInputSurface(request.getResolution());
           *
           *         // Provide the surface and wait for the result to clean up the surface.
           *         request.provideSurface(surface, mGlExecutor, (result) -&gt; {
           *             // In all cases (even errors), we can clean up the state. As an
           *             // optimization, we could also optionally check for REQUEST_CANCELLED
           *             // since we may be able to reuse the surface on subsequent surface requests.
           *             closeGlInputSurface(surface);
           *         });
           *     }
           * }
  </code></pre>
  <p>yeah but this example seems somewhat incomplete. And i don't know how to implement that properly...
  So any suggestions how i can implement my own SurfaceProvider?</p>