Android - terrain reverse orientation detection

I need to determine the reverse orientation of the terrain so that the user does not start to capture vertical videos.

I implemented 2 layouts in the layout-land and layout-port folders with a different set of controls. The problem is that Android does not allow me to create a separate layout specifically for the reverse landscape. I need this because the video is recorded upside down in this case, although the user interface is displayed correctly.

If I rotate the device from 0 to 180, then Android does not even call onCreate() my activity, but in this case the video is flipped.

Can anyone suggest a working example on how to determine a specific orientation of the device (reverse landscape in my case) so that I can use a different layout for this orientation?

+3
source share
1 answer

Use OrientationEventListener to get the orientation in degrees of the phone.

After creating a listener and calling enable() , onOrientationChanged(int) will be called whenever the orientation of the phone changes.

Then you can check if it is in the range in which you want the phone to be.

Remember to use SENSOR_DELAY_NORMAL as a bet. Thus, this will only be triggered when a change in orientation occurs that you really need, rather than small changes that usually occur when the user processes their phone.

+4
source

Source: https://habr.com/ru/post/1240381/


All Articles