title: SurfaceTexture preview for camera2 stretches on some devices
body: <p>I'm developing a camera2 app. Everything is working fine on Nexus 5 and Nexus 4, but on LG G2 preview for video is stretched (only for back camera, for front camera everything is fine). I'm setting SurfaceTexture the next way:</p>
  
  <pre><code>@Override
      protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
          super.onMeasure(widthMeasureSpec, heightMeasureSpec);
          int width = MeasureSpec.getSize(widthMeasureSpec);
          int height = MeasureSpec.getSize(heightMeasureSpec);
          float ratioSurface = width &gt; height ? (float) width / height : (float) height / width;
          float ratioPreview = (float) mRatioWidth / mRatioHeight;
          int scaledHeight = height;
          int scaledWidth = width;
          if (ratioPreview &gt; ratioSurface) {
              scaledHeight = (int) (((float) mRatioWidth / mRatioHeight) * width);
          } else if (ratioPreview &lt; ratioSurface) {
              scaledWidth = (int) (height / ((float) mRatioWidth / mRatioHeight));
          }
          setMeasuredDimension(scaledWidth, scaledHeight);
      }
  </code></pre>
  
  <p>After setAspectRatio() I'm called setSurfaceTexture():</p>
  
  <pre><code>private void setSurfaceTexture(Size size) {
          final Matrix matrix = new Matrix();
          int width = resource.cameraTexture.getWidth();
          int height = resource.cameraTexture.getHeight();
          int rotation = controller.getRotation();
          if (Surface.ROTATION_90 == rotation || Surface.ROTATION_270 == rotation) {
              matrix.postRotate(90 * (rotation - 2), width / 2, height / 2);
          }
          resource.mForegroundHandler.post(new Runnable() {
              @Override
              public void run() {
                  resource.cameraTexture.setTransform(matrix);
              }
          });
      }
  </code></pre>
  
  <p>I was trying to use SurfaceView, but result is the same: when switches to video mode, preview is stretched. I tried many ways, but result is always the same.
  Please, help me...</p>
  
  <p>EDIT: Video is still stretched on LG G2 with CyanogenMod, but in phones with official Lollipop the issue was next: LEGACY devices not always support preview video 16:9, so I've changed video size to 4:3. </p>