commonsguy/cwac-camera — pull request #223 by daj (2014-10-11 23:09:04+00:00)
Title: Add lockToPortrait method to CameraView

This change is based on the suggestion in issue 169: https://github.com/commonsguy/cwac-camera/issues/169

I've added a lockToPortrait method, and have updated the "Single-Shot Mode" DisplayActivity to be locked to the same orientation as the preview screen, as I think that matches the most common use cases for orientation locking.

ISSUES / QUESTIONS

1)
Having reviewed this change, I now think I should combine lockToPortrait and lockToLandscape into a single lockToOrientation method. Please let me know if you agree and I will update the pull request.

Suggested implementation of lockToOrientation:
```
/**
* Lock the camera and preview to the provided orientation. Passing in
* SCREEN_ORIENTATION_UNSPECIFIED will re-enable automatic
* orientation changes.
*
* Expected parameter values:
* ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE
* ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT
* ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
*/
public void lockToOrientation(int screenOrientation) {
if (screenOrientation == ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED) {
getActivity().setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
onOrientationChange.disable();
}
else {
getActivity().setRequestedOrientation(screenOrientation);
onOrientationChange.enable();
}
}
```

2)
The preview screen does not behave quite as I would expect. This is existing behaviour, and I'm not sure if this is working as designed. Scenario:
-Select "Lock to Landscape" and "Single-Shot Mode".
-Hold the phone in *portrait* orientation and take a photo.
-The preview screen is also locked to landscape, but a portrait photo seems to have been taken.

I tested this on the Nexus 4 running OS 4.4.4.