@@ -0,0 +1,1755 @@
+package io.fotoapparat.hardware.v2.session;%0A%0Aimport android.hardware.camera2.CameraCharacteristics;%0Aimport android.os.Build;%0Aimport android.support.annotation.RequiresApi;%0A%0Aimport static android.hardware.camera2.CameraCharacteristics.LENS_FACING;%0Aimport static android.hardware.camera2.CameraMetadata.LENS_FACING_FRONT;%0Aimport static android.view.OrientationEventListener.ORIENTATION_UNKNOWN;%0A%0A/**%0A *%0A */%0A@RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)%0Apublic class Orientation %7B%0A%0A%09private final CameraCharacteristics characteristics;%0A%0A%09Orientation(CameraCharacteristics characteristics) %7B%0A%09%09this.characteristics = characteristics;%0A%09%7D%0A%0A%09/**%0A%09 * @param deviceOrientation The rotation of the device relative to the native device%0A%09 *                          orientation.%0A%09 * @return The clockwise rotation angle in degrees, relative to the orientation to the camera,%0A%09 * that the JPEG picture needs to be rotated by, to be viewed upright.%0A%09 */%0A%09@SuppressWarnings(%22ConstantConditions%22)%0A%09int getJpegOrientation(int deviceOrientation) %7B%0A%09%09if (deviceOrientation == ORIENTATION_UNKNOWN) %7B%0A%09%09%09return 0;%0A%09%09%7D%0A%0A%09%09int sensorOrientation = characteristics.get(CameraCharacteristics.SENSOR_ORIENTATION);%0A%09%09int calculateDeviceOrientation = calculateDeviceOrientation(deviceOrientation);%0A%0A%09%09return (sensorOrientation + calculateDeviceOrientation + 360) %25 360;%0A%09%7D%0A%0A%09@SuppressWarnings(%22ConstantConditions%22)%0A%09private int calculateDeviceOrientation(int deviceOrientation) %7B%0A%09%09// Round device orientation to a multiple of 90%0A%09%09deviceOrientation = (deviceOrientation + 45) / 90 * 90;%0A%0A%09%09boolean shouldReverseOrientation = characteristics.get(LENS_FACING) == LENS_FACING_FRONT;%0A%0A%09%09if (shouldReverseOrientation) %7B%0A%09%09%09deviceOrientation *= -1;%0A%09%09%7D%0A%09%09return deviceOrientation;%0A%09%7D%0A%7D%0A

Add orientation calculator