I need to be able to detect the reverse landscape sensor on a device.
This is the code I was using to detect reverse landscape, however doesn't seem to be working for Nexus 5X:
public boolean isSensorInReverseLandscape() {
return ((getCameraPosition().equals(Position.FRONT) && mCameraInfo.orientation == 90) ||
(getCameraPosition().equals(Position.BACK) && mCameraInfo.orientation == 270));
}
Seems to be working fine for my Nexus 6P which has the front camera sensor in reverse landscape and therefore orientation is returned as 90 for both back and front cameras (when normal front camera returns 270). However Nexus 5X CameraInfo.orientation
seems to be returning 90, which is the same as your normal back camera orientation.
Is there any other reliable way of detecting that the camera sensor is positioned in reverse landscape? Unfortunately I don't have a device to play around with.
EDIT:
Looking at the CameraInfo docs:
public int orientation
Added in API level 9 The orientation of the camera image. The value is the angle that the camera image needs to be rotated clockwise so it shows correctly on the display in its natural orientation. It should be 0, 90, 180, or 270.
For example, suppose a device has a naturally tall screen. The back-facing camera sensor is mounted in landscape. You are looking at the screen. If the top side of the camera sensor is aligned with the right edge of the screen in natural orientation, the value should be 90. If the top side of a front-facing camera sensor is aligned with the right of the screen, the value should be 270.
So why does the back facing camera sensor mounted in reverse landscape orientation also reports 90? That is just strange..
EDIT 2:
My code for getting the camera info:
for (int i = 0; i < Camera.getNumberOfCameras(); i++) {
int cameraId = i;
CameraInfo cameraInfo = new CameraInfo();
Camera.getCameraInfo(i, cameraInfo);
CameraLegacy camera = new CameraLegacy(cameraId, cameraInfo, mContext, mMode);
cameras.add(camera);
}
Where CameraLegacy saves the info into mCamraInfo.
EDIT 3:
This is how the camera constructor outputs orientation:
02-19 18:48:01.832: D/CameraController(8093): .findAvailableCameraDevices() - entered
02-19 18:48:01.833: D/CameraController(8093): .findAvailableCameraDevices() - camera id is 0
02-19 18:48:01.833: D/CameraController(8093): .findAvailableCameraDevices() - camera orientation is 90
02-19 18:48:01.994: D/CameraLegacy(8093): CameraLegacy() - camera orientation in constructor is 90
02-19 18:48:01.994: D/CameraController(8093): .findAvailableCameraDevices() - camera id is 1
02-19 18:48:01.995: D/CameraController(8093): .findAvailableCameraDevices() - camera orientation is 270
02-19 18:48:01.995: D/CameraLegacy(8093): CameraLegacy() - camera orientation in constructor is 270