@SuppressLint("DrawAllocation")
    @Override
    protected void onLayout(boolean changed, int l, int t, int r, int b) {
        containerSized(new Size(r - l, b - t));

        if (surfaceView != null) {
            if (surfaceRect == null) {
                // Match the container, to reduce the risk of issues. The preview should never be drawn
                // while the surface has this size.
                surfaceView.layout(0, 0, getWidth(), getHeight());
            } else {
                surfaceView.layout(surfaceRect.left, surfaceRect.top, surfaceRect.right, surfaceRect.bottom);
            }
        } else if (textureView != null) {
            textureView.layout(0, 0, getWidth(), getHeight());
        }
    }
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