Example usage for android.view OrientationEventListener ORIENTATION_UNKNOWN

List of usage examples for android.view OrientationEventListener ORIENTATION_UNKNOWN

Introduction

In this page you can find the example usage for android.view OrientationEventListener ORIENTATION_UNKNOWN.

Prototype

int ORIENTATION_UNKNOWN

To view the source code for android.view OrientationEventListener ORIENTATION_UNKNOWN.

Click Source Link

Document

Returned from onOrientationChanged when the device orientation cannot be determined (typically when the device is in a close to flat position).

Usage

From source file:Main.java

public static int roundOrientation(int orientation, int orientationHistory) {
    boolean changeOrientation = false;
    if (orientationHistory == OrientationEventListener.ORIENTATION_UNKNOWN) {
        changeOrientation = true;//from ww w . java2  s.  com
    } 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;
}

From source file:Main.java

public static int roundOrientation(int orientationInput) {
    int orientation = orientationInput;

    if (orientation == OrientationEventListener.ORIENTATION_UNKNOWN) {
        orientation = 0;/*from   ww w . j  a va  2 s  .  co  m*/
    }

    orientation = orientation % 360;
    int retVal;
    if (orientation < (0 * 90) + 45) {
        retVal = 0;
    } else if (orientation < (1 * 90) + 45) {
        retVal = 90;
    } else if (orientation < (2 * 90) + 45) {
        retVal = 180;
    } else if (orientation < (3 * 90) + 45) {
        retVal = 270;
    } else {
        retVal = 0;
    }

    return retVal;
}