Android how to detect if phone is turned around
<p>This is my code for detecting if phone is turned around or not</p>

<pre><code>private SensorManager sensorManager;
    private int orientationLim = 165;

@Override
    public void onSensorChanged(SensorEvent event) {
        if (event.sensor.getType() == Sensor.TYPE_ORIENTATION) {

            // If shake to stop is enabled
            boolean turnAroundToStop = Utils.getBooleanFromProperties(this, Properties.SP_CB_TURN_AROUND_TO_STOP);

            if (turnAroundToStop) {
                float value = Math.abs(event.values[1]);
                if (value &gt; orientationLim &amp;&amp; !stopped) {
                    // Down
                    stopped = true;
                } else {
                    // Up
                    stopped = false;
                }
            }
        }
    }
</code></pre>

<p>but problem is that <code>stopped</code> variable is set to true even phone is not completely turned around but just a little.</p>

<p>How can i modify this code that will be executed only when phone is relay turned around.</p>
