Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 7895da44 authored by Mathias Agopian's avatar Mathias Agopian
Browse files

SensorManager: handle 270 and 180 rotation in the legacy APIs

Technically these APIs are deprecated, however old apps might still be using them
so we might as well make sure they work in all orientations.
parent 210fc914
Loading
Loading
Loading
Loading
+23 −2
Original line number Diff line number Diff line
@@ -1447,8 +1447,9 @@ public class SensorManager
            values[3] = x;
            values[4] = y;
            values[5] = z;
            // TODO: add support for 180 and 270 orientations
            if (orientation == Surface.ROTATION_90) {

            if ((orientation & Surface.ROTATION_90) != 0) {
                // handles 90 and 270 rotation
                switch (sensor) {
                    case SENSOR_ACCELEROMETER:
                    case SENSOR_MAGNETIC_FIELD:
@@ -1464,6 +1465,26 @@ public class SensorManager
                        break;
                }
            }
            if ((orientation & Surface.ROTATION_180) != 0) {
                x = values[0];
                y = values[1];
                z = values[2];
                // handles 180 (flip) and 270 (flip + 90) rotation
                switch (sensor) {
                    case SENSOR_ACCELEROMETER:
                    case SENSOR_MAGNETIC_FIELD:
                        values[0] =-x;
                        values[1] =-y;
                        values[2] = z;
                        break;
                    case SENSOR_ORIENTATION:
                    case SENSOR_ORIENTATION_RAW:
                        values[0] = (x >= 180) ? (x - 180) : (x + 180);
                        values[1] =-y;
                        values[2] =-z;
                        break;
                }
            }
        }
    }