Exemple #1
0
 public void lockToLandscape(boolean enable) {
   if (enable) {
     getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
     onOrientationChange.enable();
   } else {
     getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
     onOrientationChange.disable();
   }
 }
Exemple #2
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);
      }
    }
  }
Exemple #3
0
  public void takePicture(final PictureTransaction xact) {
    if (inPreview) {
      if (isAutoFocusing) {
        throw new IllegalStateException("Camera cannot take a picture while auto-focusing");
      } else {
        previewParams = camera.getParameters();

        Camera.Parameters pictureParams = camera.getParameters();
        Camera.Size pictureSize = xact.host.getPictureSize(xact, pictureParams);

        pictureParams.setPictureSize(pictureSize.width, pictureSize.height);
        pictureParams.setPictureFormat(ImageFormat.JPEG);

        if (xact.flashMode != null) {
          pictureParams.setFlashMode(xact.flashMode);
        }

        if (!onOrientationChange.isEnabled()) {
          setCameraPictureOrientation(pictureParams);
        }

        camera.setParameters(xact.host.adjustPictureParameters(xact, pictureParams));
        xact.cameraView = this;

        postDelayed(
            new Runnable() {
              @Override
              public void run() {
                try {
                  camera.takePicture(xact, null, new PictureTransactionCallback(xact));
                } catch (Exception e) {
                  android.util.Log.e(getClass().getSimpleName(), "Exception taking a picture", e);
                  // TODO get this out to library clients
                }
              }
            },
            xact.host.getDeviceProfile().getPictureDelay());

        inPreview = false;
      }
    } else {
      throw new IllegalStateException(
          "Preview mode must have started before you can take a picture");
    }
  }