+ this.mContext = context;
+ mHolder = this.getHolder();
+ mHolder.addCallback(this);
+ this.mCallback = cb;
+ }
+
+ public void setLayout(int width, int heitht){
+ this.height = heitht;
+ this.width = width;
+ gLogger.error("setLayout, 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;
+ }
+ gLogger.error("width=" + lp.width + ", height=" + lp.height + ". leftMargin=" + lp.leftMargin + ", topMargin=" + lp.topMargin);
+ this.setLayoutParams(lp);