Example usage for android.hardware Camera setPreviewDisplay

List of usage examples for android.hardware Camera setPreviewDisplay

Introduction

In this page you can find the example usage for android.hardware Camera setPreviewDisplay.

Prototype

public final void setPreviewDisplay(SurfaceHolder holder) throws IOException 

Source Link

Document

Sets the Surface to be used for live preview.

Usage

From source file:com.TaxiDriver.jy.CameraPreview.java

public void switchCamera(Camera camera) {
    setCamera(camera);/*from   w w  w  .j  a  v a 2 s  .  co m*/
    try {
        camera.setPreviewDisplay(mHolder);
    } catch (IOException exception) {
        Log.e(TAG, "IOException caused by setPreviewDisplay()", exception);
    }
    Camera.Parameters parameters = camera.getParameters();
    parameters.setPreviewSize(mPreviewSize.width, mPreviewSize.height);
    requestLayout();

    camera.setParameters(parameters);
}

From source file:com.googlecode.android_scripting.facade.CameraFacade.java

private FutureActivityTask<SurfaceHolder> setPreviewDisplay(Camera camera)
        throws IOException, InterruptedException {
    FutureActivityTask<SurfaceHolder> task = new FutureActivityTask<SurfaceHolder>() {
        @Override/*from  w w w  .  j a  va 2s.  c  o  m*/
        public void onCreate() {
            super.onCreate();
            final SurfaceView view = new SurfaceView(getActivity());
            getActivity().setContentView(view);
            getActivity().getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_UNCHANGED);
            view.getHolder().setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS);
            view.getHolder().addCallback(new Callback() {
                @Override
                public void surfaceDestroyed(SurfaceHolder holder) {
                }

                @Override
                public void surfaceCreated(SurfaceHolder holder) {
                    setResult(view.getHolder());
                }

                @Override
                public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
                }
            });
        }
    };
    FutureActivityTaskExecutor taskQueue = ((BaseApplication) mService.getApplication()).getTaskExecutor();
    taskQueue.execute(task);
    camera.setPreviewDisplay(task.getResult());
    return task;
}