List of utility methods to do Screen Orientation Check
float | getDirectionNow(final float direction) Take the phone rotation (through a given activity) in account and adjust the direction. return normalize(direction + getRotationOffset());
|
int | getRotationOffset() get Rotation Offset switch (WindowManagerHolder.WINDOW_MANAGER.getDefaultDisplay() .getRotation()) { case Surface.ROTATION_90: return 90; case Surface.ROTATION_180: return 180; case Surface.ROTATION_270: return 270; ... |
boolean | isDefaultToPortrait(Activity activity) Calculate the default orientation of the device based on the width and height of the display when rotation = 0 (i.e. Display currentDisplay = activity.getWindowManager() .getDefaultDisplay(); Point displaySize = new Point(); currentDisplay.getSize(displaySize); int orientation = currentDisplay.getRotation(); int naturalWidth, naturalHeight; if (orientation == Surface.ROTATION_0 || orientation == Surface.ROTATION_180) { ... |
boolean | isLandScape(Context context) is Land Scape return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
boolean | isLandscape(final Context context) Used to determine if the device is currently in landscape mode return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
|
float | reverseDirectionNow(final float direction) Reverse the phone rotation (through a given activity) in account and adjust the direction. return normalize(direction - getRotationOffset());
|
int | roundOrientation(int orientation, int orientationHistory) round Orientation boolean changeOrientation = false; if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) { changeOrientation = true; } else { int dist = Math.abs(orientation - orientationHistory); dist = Math.min(dist, 360 - dist); changeOrientation = (dist >= 45 + ORIENTATION_HYSTERESIS); if (changeOrientation) { return ((orientation + 45) / 90 * 90) % 360; return orientationHistory; |
String | getDisplayOrientation(Context context) get Display Orientation String text; switch (context.getResources().getConfiguration().orientation) { case Configuration.ORIENTATION_PORTRAIT: text = "portrait"; break; case Configuration.ORIENTATION_LANDSCAPE: text = "landscape"; break; ... |