import android.content.Context;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
+import android.widget.FrameLayout;
import org.apache.log4j.Logger;
private Context mContext;
private SurfaceHolder mHolder;
private Callback mCallback;
+ private int width;
+ private int height;
public CameraView (Context context, Callback cb) {
super(context);
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);
+ }
+
// SurfaceHolder.Callback implementation
@Override
public void surfaceCreated(final SurfaceHolder holder){
- gLogger.error("SurfacedCreated");
+ gLogger.debug("SurfacedCreated, screen size w: " + SCREEN_WIDTH + ", h:" + SCREEN_HEIGHT + ". preview size, w: " + width + ", h: " + height);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int widht, int height){
- gLogger.error("surfaceChanged");
+ gLogger.debug("surfaceChanged");
mHolder = holder;
mCallback.onSurfaceChanged(holder, format, widht, height);
}