I’m checking the orientation of a screen inside a view using:
getResources().getConfiguration().orientation
New versions of Android provide with more orientation states so I was thinking on using a switch with all the states I want to handle.
switch (getResources().getConfiguration().orientation) {
case ActivityInfo.SCREEN_ORIENTATION_PORTRAIT:
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_PORTRAIT:
case ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE:
case ActivityInfo.SCREEN_ORIENTATION_REVERSE_LANDSCAPE:
}
Now, will this break the application on old devices? Given that some of the constants are new for API 9+? I’m not sure because I’m not sure how constants (final static) are treated by the compiler. Are they inlined or referenced? I would think that if they are inlined there should be no issue with this method.
Thanks
Not if you use them the way you are. The Java compiler will replace the symbols with their numeric equivalents at compile time.
However, you cannot get at those values via reflection on older devices, though that would be a rather unusual technique.