private static DirectionData.DeviceOrientation calculateDeviceOrientationFrom(final float[] orientationVector) {
        if (orientationVector == null || orientationVector.length < 3) {
            return DirectionData.DeviceOrientation.UNKNOWN;
        }

        //Rule: if either pitch or roll is close to -270/-90/90/270 degree we say device is upright (either portrait or landscape)
        final double pitchSin = Math.abs(Math.sin(orientationVector[1]));
        final double rollSin = Math.abs(Math.sin(orientationVector[2]));

        final double border = 0.75d;

        return pitchSin >= border || rollSin >= border ? DirectionData.DeviceOrientation.UPRIGHT : DirectionData.DeviceOrientation.FLAT;
    }
calculates/estimates device orientation from given (raw, uncorrected) orientation vector
main/src/main/java/cgeo/geocaching/sensors/DirectionDataCalculator.java