Program: 38203
Project: 38203
Buggy source:
public void layoutPreview(float ratio){
  FrameLayout.LayoutParams lp;
  float scaledTextureWidth, scaledTextureHeight;
  int rotation=CameraUtil.getDisplayRotation(mActivity);
  mScreenRatio=CameraUtil.determineRatio(ratio);
  if (mScreenRatio == CameraUtil.RATIO_16_9 && CameraUtil.determinCloseRatio(ratio) == CameraUtil.RATIO_4_3) {
    int l=(mTopMargin + mBottomMargin) * 4;
    int s=l * 9 / 16;
switch (rotation) {
case 90:
      lp=new FrameLayout.LayoutParams(l * 3 / 4,s);
    lp.setMargins(mTopMargin,0,mBottomMargin,0);
  scaledTextureWidth=l * 3 / 4;
scaledTextureHeight=s;
break;
case 180:
lp=new FrameLayout.LayoutParams(s,l * 3 / 4);
lp.setMargins(0,mBottomMargin,0,mTopMargin);
scaledTextureWidth=s;
scaledTextureHeight=l * 3 / 4;
break;
case 270:
lp=new FrameLayout.LayoutParams(l * 3 / 4,s);
lp.setMargins(mBottomMargin,0,mTopMargin,0);
scaledTextureWidth=l * 3 / 4;
scaledTextureHeight=s;
break;
default :
lp=new FrameLayout.LayoutParams(s,l * 3 / 4);
lp.setMargins(0,mTopMargin,0,mBottomMargin);
scaledTextureWidth=s;
scaledTextureHeight=l * 3 / 4;
break;
}
}
 else {
float width=mMaxPreviewWidth, height=mMaxPreviewHeight;
if (width == 0 || height == 0) return;
if (mScreenRatio == CameraUtil.RATIO_4_3) height-=(mTopMargin + mBottomMargin);
if (mOrientationResize) {
scaledTextureWidth=height * mAspectRatio;
if (scaledTextureWidth > width) {
scaledTextureWidth=width;
scaledTextureHeight=scaledTextureWidth / mAspectRatio;
}
 else {
scaledTextureHeight=height;
}
}
 else {
if (width > height) {
if (Math.max(width,height * mAspectRatio) > width) {
scaledTextureWidth=width;
scaledTextureHeight=width / mAspectRatio;
}
 else {
scaledTextureWidth=height * mAspectRatio;
scaledTextureHeight=height;
}
}
 else {
if (Math.max(height,width * mAspectRatio) > height) {
scaledTextureWidth=height / mAspectRatio;
scaledTextureHeight=height;
}
 else {
scaledTextureWidth=width;
scaledTextureHeight=width * mAspectRatio;
}
}
}
Log.v(TAG,"String_Node_Str" + scaledTextureWidth + "String_Node_Str"+ scaledTextureHeight);
if (((rotation == 0 || rotation == 180) && scaledTextureWidth > scaledTextureHeight) || ((rotation == 90 || rotation == 270) && scaledTextureWidth < scaledTextureHeight)) {
lp=new FrameLayout.LayoutParams((int)scaledTextureHeight,(int)scaledTextureWidth,Gravity.CENTER);
}
 else {
lp=new FrameLayout.LayoutParams((int)scaledTextureWidth,(int)scaledTextureHeight,Gravity.CENTER);
}
if (mScreenRatio == CameraUtil.RATIO_4_3) {
lp.gravity=Gravity.CENTER_HORIZONTAL | Gravity.TOP;
lp.setMargins(0,mTopMargin,0,mBottomMargin);
}
}
if (mSurfaceTextureUncroppedWidth != scaledTextureWidth || mSurfaceTextureUncroppedHeight != scaledTextureHeight) {
mSurfaceTextureUncroppedWidth=scaledTextureWidth;
mSurfaceTextureUncroppedHeight=scaledTextureHeight;
if (mSurfaceTextureSizeListener != null) {
mSurfaceTextureSizeListener.onSurfaceTextureSizeChanged((int)mSurfaceTextureUncroppedWidth,(int)mSurfaceTextureUncroppedHeight);
Log.d(TAG,"String_Node_Str" + mSurfaceTextureUncroppedWidth + "String_Node_Str"+ mSurfaceTextureUncroppedHeight);
}
}
mSurfaceView.setLayoutParams(lp);
if (mFaceView != null) {
mFaceView.setLayoutParams(lp);
}
}

Fixed version (ground truth):
public void layoutPreview(float ratio){
  FrameLayout.LayoutParams lp;
  float scaledTextureWidth, scaledTextureHeight;
  int rotation=CameraUtil.getDisplayRotation(mActivity);
  mScreenRatio=CameraUtil.determineRatio(ratio);
  if (mScreenRatio == CameraUtil.RATIO_16_9 && CameraUtil.determinCloseRatio(ratio) == CameraUtil.RATIO_4_3) {
    int l=(mTopMargin + mBottomMargin) * 4;
    int s=l * 9 / 16;
switch (rotation) {
case 90:
      lp=new FrameLayout.LayoutParams(l * 3 / 4,s);
    lp.setMargins(mTopMargin,0,mBottomMargin,0);
  scaledTextureWidth=l * 3 / 4;
scaledTextureHeight=s;
break;
case 180:
lp=new FrameLayout.LayoutParams(s,l * 3 / 4);
lp.setMargins(0,mBottomMargin,0,mTopMargin);
scaledTextureWidth=s;
scaledTextureHeight=l * 3 / 4;
break;
case 270:
lp=new FrameLayout.LayoutParams(l * 3 / 4,s);
lp.setMargins(mBottomMargin,0,mTopMargin,0);
scaledTextureWidth=l * 3 / 4;
scaledTextureHeight=s;
break;
default :
lp=new FrameLayout.LayoutParams(s,l * 3 / 4);
lp.setMargins(0,mTopMargin,0,mBottomMargin);
scaledTextureWidth=s;
scaledTextureHeight=l * 3 / 4;
break;
}
}
 else {
float width=mMaxPreviewWidth, height=mMaxPreviewHeight;
if (width == 0 || height == 0) return;
if (mScreenRatio == CameraUtil.RATIO_4_3) height-=(mTopMargin + mBottomMargin);
if (mOrientationResize) {
scaledTextureWidth=height * mAspectRatio;
if (scaledTextureWidth > width) {
scaledTextureWidth=width;
scaledTextureHeight=scaledTextureWidth / mAspectRatio;
}
 else {
scaledTextureHeight=height;
}
}
 else {
if (width > height) {
if (Math.max(width,height * mAspectRatio) > width) {
scaledTextureWidth=width;
scaledTextureHeight=width / mAspectRatio;
}
 else {
scaledTextureWidth=height * mAspectRatio;
scaledTextureHeight=height;
}
}
 else {
if (Math.max(height,width * mAspectRatio) > height) {
scaledTextureWidth=height / mAspectRatio;
scaledTextureHeight=height;
}
 else {
scaledTextureWidth=width;
scaledTextureHeight=width * mAspectRatio;
}
}
}
Log.v(TAG,"String_Node_Str" + scaledTextureWidth + "String_Node_Str"+ scaledTextureHeight);
if (((rotation == 0 || rotation == 180) && scaledTextureWidth > scaledTextureHeight) || ((rotation == 90 || rotation == 270) && scaledTextureWidth < scaledTextureHeight)) {
lp=new FrameLayout.LayoutParams((int)scaledTextureHeight,(int)scaledTextureWidth,Gravity.CENTER);
}
 else {
lp=new FrameLayout.LayoutParams((int)scaledTextureWidth,(int)scaledTextureHeight,Gravity.CENTER);
}
if (mScreenRatio == CameraUtil.RATIO_4_3) {
lp.gravity=Gravity.CENTER_HORIZONTAL | Gravity.TOP;
lp.setMargins(0,mTopMargin,0,mBottomMargin);
}
}
if (mSurfaceTextureUncroppedWidth != scaledTextureWidth || mSurfaceTextureUncroppedHeight != scaledTextureHeight) {
mSurfaceTextureUncroppedWidth=scaledTextureWidth;
mSurfaceTextureUncroppedHeight=scaledTextureHeight;
if (mSurfaceTextureSizeListener != null) {
mSurfaceTextureSizeListener.onSurfaceTextureSizeChanged((int)mSurfaceTextureUncroppedWidth,(int)mSurfaceTextureUncroppedHeight);
Log.d(TAG,"String_Node_Str" + mSurfaceTextureUncroppedWidth + "String_Node_Str"+ mSurfaceTextureUncroppedHeight);
}
}
mSurfaceView.setLayoutParams(lp);
if (mFaceView != null) {
mFaceView.setLayoutParams(lp);
}
mIsLayoutInitializedAlready=true;
}