Exemple #1
0
  @TargetApi(Build.VERSION_CODES.ICE_CREAM_SANDWICH)
  public void onResume() {
    addView(previewStrategy.getWidget());

    if (camera == null) {
      cameraId = getHost().getCameraId();

      if (cameraId >= 0) {
        try {
          camera = Camera.open(cameraId);

          if (getActivity().getRequestedOrientation()
              != ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
            onOrientationChange.enable();
          }

          setCameraDisplayOrientation();

          if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH
              && getHost() instanceof Camera.FaceDetectionListener) {
            camera.setFaceDetectionListener((Camera.FaceDetectionListener) getHost());
          }
        } catch (Exception e) {
          getHost().onCameraFail(FailureReason.UNKNOWN);
        }
      } else {
        getHost().onCameraFail(FailureReason.NO_CAMERAS_REPORTED);
      }
    }
  }
  /**
   * Start the camera and set up its preview texture to the given texture (essentially copying
   * camera into texture.
   *
   * @param texture
   */
  public void startCamera(int texture) {
    surface = new SurfaceTexture(texture);
    surface.setOnFrameAvailableListener(this);

    camera = Camera.open();
    camera.setFaceDetectionListener(this);

    try {
      camera.setPreviewTexture(surface);
      camera.startPreview();
    } catch (IOException ioe) {
      Log.w("MainActivity", "Failed to start camera preview on texture.");
    }
    camera.startFaceDetection();
  }
 @Override
 public void setFaceDetectionListener(FaceDetectionListener listener) {
   if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.ICE_CREAM_SANDWICH) {
     camera.setFaceDetectionListener(listener);
   }
 }
Exemple #4
0
 @Override
 public void surfaceCreated(SurfaceHolder holder) {
   // TODO Auto-generated method stub
   camera = Camera.open();
   camera.setFaceDetectionListener(faceDetectionListener);
 }