Universal way to detect landscape mode in Android

Hello everybody,

Today I have faced a real challenge how to determinate the screen mode 🙂

Issue was to detect orientation (Landscape or portrait) for ANY Android device.
Xoom has 0,3 – landscape 1,2 – portrait, Galaxy 1,2 – landscape 0,3 – portrait,
so it is difficult to handle all necessary events for different devices due to theirs default orientation. I didn’t find the way to get default orientation, so I have implement a super easy way to detect if we are in Landscape mode:

Notes:
To retrieve current orientation id, you are able to use:

This function returns 0,1,2 or 3 integers, which are corresponds to the appropriate constants in Surface class:

Happy orientation detection ^__^

Best regards,
Yahor