private void startPreviewIfReady() {
        if (currentSurfaceSize != null && previewSize != null && surfaceRect != null) {
            if (surfaceView != null && currentSurfaceSize.equals(new Size(surfaceRect.width(), surfaceRect.height()))) {
                startCameraPreview(new CameraSurface(surfaceView.getHolder()));
            } else if (textureView != null && textureView.getSurfaceTexture() != null) {
                if (previewSize != null) {
                    Matrix transform = calculateTextureTransform(new Size(textureView.getWidth(), textureView.getHeight()), previewSize);
                    textureView.setTransform(transform);
                }

                startCameraPreview(new CameraSurface(textureView.getSurfaceTexture()));
            } else {
                // Surface is not the correct size yet
            }
        }
    }
Calculate transformation for the TextureView.

An identity matrix would cause the preview to be scaled up/down to fill the TextureView.

@param textureSize the size of the textureView
@param previewSize the camera preview resolution
@return the transform matrix for the TextureView
zxing-android-embedded/src/com/journeyapps/barcodescanner/CameraPreview.java