Example #1
0
 /**
  * Possible Picture Orientation fix
  *
  * @param param
  * @param orientation
  */
 public void onOrientationChanged(Parameters param, int orientation) {
   if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) return;
   CameraInfo info = new CameraInfo();
   Camera.getCameraInfo(0, info);
   orientation = (orientation + 45) / 90 * 90;
   int rotation = 0;
   if (info.facing == CameraInfo.CAMERA_FACING_FRONT) {
     rotation = (info.orientation - orientation + 360) % 360;
   } else { // back-facing camera
     rotation = (info.orientation + orientation) % 360;
   }
   param.setRotation(rotation);
 }
  private void setUpCamera(Camera c) {
    Camera.CameraInfo info = new Camera.CameraInfo();
    Camera.getCameraInfo(cameraId, info);
    rotation = getWindowManager().getDefaultDisplay().getRotation();
    int degree = 0;
    switch (rotation) {
      case Surface.ROTATION_0:
        degree = 0;
        break;
      case Surface.ROTATION_90:
        degree = 90;
        break;
      case Surface.ROTATION_180:
        degree = 180;
        break;
      case Surface.ROTATION_270:
        degree = 270;
        break;

      default:
        break;
    }

    if (info.facing == Camera.CameraInfo.CAMERA_FACING_FRONT) {
      // frontFacing
      rotation = (info.orientation + degree) % 330;
      rotation = (360 - rotation) % 360;
    } else {
      // Back-facing
      rotation = (info.orientation - degree + 360) % 360;
    }
    c.setDisplayOrientation(rotation);
    Parameters params = c.getParameters();

    showFlashButton(params);

    List<String> focusModes = params.getSupportedFlashModes();
    if (focusModes != null) {
      if (focusModes.contains(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE)) {
        params.setFlashMode(Camera.Parameters.FOCUS_MODE_CONTINUOUS_PICTURE);
      }
    }

    params.setRotation(rotation);
  }