X-Git-Url: http://47.100.26.94:8080/?a=blobdiff_plain;f=app%2Fsrc%2Fmain%2Fjava%2Fai%2Fsuanzi%2Frtmpclient%2FCameraView.java;h=71a684d922fe39147731e7e7630b6e21bfbd35be;hb=c6604883de5525540d63ceacf4cf08fe3e82a286;hp=5ddcb5ef73e001f1377be2d9d2bbcd5fe2f042cd;hpb=6aa3850f260161c015474faf68165158165afea8;p=rtmpclient.git diff --git a/app/src/main/java/ai/suanzi/rtmpclient/CameraView.java b/app/src/main/java/ai/suanzi/rtmpclient/CameraView.java index 5ddcb5e..71a684d 100644 --- a/app/src/main/java/ai/suanzi/rtmpclient/CameraView.java +++ b/app/src/main/java/ai/suanzi/rtmpclient/CameraView.java @@ -3,6 +3,7 @@ package ai.suanzi.rtmpclient; import android.content.Context; import android.view.SurfaceHolder; import android.view.SurfaceView; +import android.widget.FrameLayout; import org.apache.log4j.Logger; @@ -15,6 +16,8 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback { private Context mContext; private SurfaceHolder mHolder; private Callback mCallback; + private int width; + private int height; public CameraView (Context context, Callback cb) { super(context); @@ -24,10 +27,32 @@ public class CameraView extends SurfaceView implements SurfaceHolder.Callback { this.mCallback = cb; } + public void setLayout(int width, int heitht){ + this.height = heitht; + this.width = width; + gLogger.error("SurfacedCreated, screen size w: " + SCREEN_WIDTH + ", h:" + SCREEN_HEIGHT + ". preview size, w: " + width + ", h: " + height); + + float ratio = (float) height / width; // 3/4,,, 640x480 1008x1344 + FrameLayout.LayoutParams lp = (FrameLayout.LayoutParams)getLayoutParams(); + gLogger.error("ratio = " + ratio + ". xxx=" + (float)(SCREEN_HEIGHT / SCREEN_HEIGHT)); + if(ratio > (float)(SCREEN_HEIGHT / SCREEN_WIDTH) ){ + lp.width = SCREEN_HEIGHT * width / height; + lp.height = SCREEN_HEIGHT; + lp.leftMargin = (SCREEN_WIDTH - lp.width ) / 2; + lp.topMargin = 0; + } else { + lp.width = SCREEN_WIDTH; + lp.height = SCREEN_WIDTH * height / width; + lp.leftMargin = 0; + lp.topMargin = (SCREEN_HEIGHT - lp.height) / 2; + } + this.setLayoutParams(lp); + } + // SurfaceHolder.Callback implementation @Override public void surfaceCreated(final SurfaceHolder holder){ - gLogger.error("SurfacedCreated"); + gLogger.error("SurfacedCreated, screen size w: " + SCREEN_WIDTH + ", h:" + SCREEN_HEIGHT + ". preview size, w: " + width + ", h: " + height); } @Override