I found a simple solution that in my case is working perfectly:
I've written this method to correctly map the values:
private void mapSensors(float[] input, float[] output) {
switch (((WindowManager) getApplicationContext().getSystemService(
Context.WINDOW_SERVICE)).getDefaultDisplay().getRotation()) {
case 0:
output[0] = input[0];
output[1] = input[1];
break;
case 1:
output[0] = -input[1];
output[1] = input[0];
break;
case 2:
output[0] = -input[0];
output[1] = -input[1];
break;
case 3:
output[0] = input[1];
output[1] = -input[0];
break;
}
}
And the method is called like this:
@Override
public void onSensorChanged(SensorEvent event) {
mapSensors(event.values, gravity);
}
It maps the values from the sensor (event.values) in to my float array (gravity).
Hope this might help someone.