Just a quick note on implemeting “orientation hinting” with a default orientation lock at the start. What it actually means:
Say, an activity is defaulted to landscape mode lock, and still allowing the user to change back to portrait only when the user intentionally doing so (rotate the devices to landscape then back to portrait).
This is particularly helpful in a situation where the user would be shown and locked into a preferred mode no matter how he/she holding the device, while still offering a mechanism to change orientation if the user intends to.
This hack here is to first set the default orientation lock, landscape in this example, first thing in the onCreate method. Then prepare the OrientationEventListener to listen on sensor events. When landscape event (clockwise or anti-clockwise) followed by a portrait event is detected, it will then dismiss the orientation lock by setting it to follow the sensor. The “orientationUnlockFlag” here serves two purposes:
- to make sure default orientation, landscape in this case, is shown no matter how the device was holded initially
- to act as a lock, only when user intended to break the default orientation (landscape-2-portrait event is detected), will it set the orientation to be sensor-based afterwards (hinting part).
Note that, onConfigurationChanged was not used in this case, due to the fact that, it won’t receive any orientation event other than the initial landscape once it’s landscape locked, thus not able to do the hinting part.