@SuppressWarnings("deprecation") public CameraView(Context context) { super(context); // Set up cameraController: // Camera controller & camera selection: cameraController = new CameraController(field.isUseFrontFacingCamera()); if (!cameraController.foundCamera()) { // no camera found, try the other one: cameraController.findCamera(!field.isUseFrontFacingCamera()); if (!cameraController .foundCamera()) { // still no camera, this device does not seem to have one: mediaDone(null, false); return; } } // Set flash mode: cameraController.setFlashMode(field.getFlashMode()); // --- Capture UI: captureLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.collector_camera_capture, null); // Create the surface for previewing the camera: final SurfaceView surfaceView = (SurfaceView) captureLayout.findViewById(R.id.capture_layout_surface); // Set-up surface holder: SurfaceHolder holder = surfaceView.getHolder(); holder.addCallback(cameraController); holder.setKeepScreenOn(true); // !!! Deprecated but cameraController preview crashes without it (at least on the // XCover/Gingerbread): holder.setType(SurfaceHolder.SURFACE_TYPE_PUSH_BUFFERS); // Add the Capture button: final LinearLayout captureLayoutButtons = (LinearLayout) captureLayout.findViewById(R.id.capture_layout_buttons); captureLayoutButtons.addView(new CaptureButtonView(getContext())); // Add the CaptureLayout to the screen this.addView(captureLayout); // --- Review UI: reviewLayout = (LinearLayout) LayoutInflater.from(context).inflate(R.layout.collector_camera_review, null); reviewView = (ImageView) reviewLayout.findViewById(R.id.review_layout_imageview); reviewView.setScaleType(ScaleType.FIT_CENTER); // Add the Capture button: final LinearLayout reviewLayoutButtons = (LinearLayout) reviewLayout.findViewById(R.id.review_layout_buttons); reviewLayoutButtons.addView(new ReviewButtonView(getContext())); // Add the ReviewLayout to the screen this.addView(reviewLayout); }
public void finalise() { if (cameraController != null) cameraController.close(); }