Code example for Camera

Methods: cancelAutoFocusgetParameterssetParametersstartPreview

0
    if (camera == null) {
      return; 
    } 
 
    // Start the camera preview. 
    Camera.Parameters parameters = camera.getParameters();
    parameters.setPreviewSize(previewSize.width, previewSize.height);
    parameters.setPictureSize(pictureSize.width, pictureSize.height);
    parameters.setJpegQuality(90);
    Log.d(LOG_PREFIX, "Preview: " + previewSize.width + "," + previewSize.height + " Picture: "
        + pictureSize.width + "," + pictureSize.height);
    requestLayout();
    try { 
      camera.cancelAutoFocus();
    } catch (RuntimeException e) {
      // No biggie. I guess we weren't focusing. 
    } 
    // TODO: Fix this. Sometimes the native camera code throws an exception 
    // claiming that autofocus is still running even though we just cancelled 
    // it. 
    try { 
      camera.setParameters(parameters);
    } catch (RuntimeException e) {
      e.printStackTrace();
    } 
    camera.startPreview();
 
    // Give the user a couple seconds to aim and then focus the camera. 
    DelayedCameraFocuser focuser = new DelayedCameraFocuser(camera);
    focuser.focusIn(2000);
  }