Android Utililty Methods Screen Orientation Check

List of utility methods to do Screen Orientation Check

Description

The list of methods to do Screen Orientation Check are organized into topic(s).

Method

floatgetDirectionNow(final float direction)
Take the phone rotation (through a given activity) in account and adjust the direction.
return normalize(direction + getRotationOffset());
intgetRotationOffset()
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;
...
booleanisDefaultToPortrait(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) {
...
booleanisLandScape(Context context)
is Land Scape
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
booleanisLandscape(final Context context)
Used to determine if the device is currently in landscape mode
return context.getResources().getConfiguration().orientation == Configuration.ORIENTATION_LANDSCAPE;
floatreverseDirectionNow(final float direction)
Reverse the phone rotation (through a given activity) in account and adjust the direction.
return normalize(direction - getRotationOffset());
introundOrientation(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;
StringgetDisplayOrientation(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;
...