@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
requestWindowFeature(Window.FEATURE_NO_TITLE);
this.setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
Preview mPreview = new Preview(this);
mRenderer = new CubeRenderer(true);
mGLSurfaceView = new GLSurfaceView(this);
//translucent
mGLSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0);
mGLSurfaceView.getHolder().setFormat(PixelFormat.RGBA_8888);
mGLSurfaceView.setRenderer(mRenderer);
//OpenGL 먼저 표시하기
setContentView(mGLSurfaceView);
//그 다음 카메라 표시하기
addContentView(mPreview, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
private GLSurfaceView mGLSurfaceView;
private CubeRenderer mRenderer;
@Override
protected void onResume() {
super.onResume();
}
@Override
protected void onPause() {
super.onPause();
}
}
//////////////////////////////
// camer preview
////////////////////////////
class Preview extends SurfaceView implements SurfaceHolder.Callback {
SurfaceHolder mHolder;
Camera mCamera;
boolean mPreviewRunning = false;
Preview(Context context) {
super(context);
mHolder = getHolder();
mHolder.addCallback(this);
mHolder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
}
Camera.PictureCallback mPictureCallback = new Camera.PictureCallback() {
public void onPictureTaken(byte[] data, Camera c) {
mCamera.startPreview();
}
};
public void surfaceCreated(SurfaceHolder holder) {
mCamera = Camera.open();
try{
mCamera.setPreviewDisplay(holder);
if (false) throw new IOException();
}catch (IOException e){
//do something
}
}
public void surfaceDestroyed(SurfaceHolder holder) {
mCamera.stopPreview();
mPreviewRunning = false;//// added
mCamera = null;
}
public void surfaceChanged(SurfaceHolder holder, int format, int w, int h) {
if (mPreviewRunning) { ///added
mCamera.stopPreview();
}
Camera.Parameters parameters = mCamera.getParameters();
parameters.setPreviewSize(w, h);
mCamera.setParameters(parameters);
mCamera.startPreview();
//
try{
mCamera.setPreviewDisplay(holder);
if (false) throw new IOException();
}catch (IOException e){
//do something
}
mCamera.startPreview();
mPreviewRunning = true; ///added
}
}