diff options
| author | Mathias Agopian <mathias@google.com> | 2010-02-26 14:16:50 -0800 |
|---|---|---|
| committer | Mathias Agopian <mathias@google.com> | 2010-02-26 17:10:38 -0800 |
| commit | 7895da44e32e9c76e07663aae7084f11cbacbbdb (patch) | |
| tree | 3e6a579172ef35d2c2724b55a3c3ebd5de8a4418 | |
| parent | 210fc914db37b3cf77ebb3bf75b0b509a1ecb07c (diff) | |
| download | frameworks_base-7895da44e32e9c76e07663aae7084f11cbacbbdb.zip frameworks_base-7895da44e32e9c76e07663aae7084f11cbacbbdb.tar.gz frameworks_base-7895da44e32e9c76e07663aae7084f11cbacbbdb.tar.bz2 | |
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.
| -rw-r--r-- | core/java/android/hardware/SensorManager.java | 25 |
1 files changed, 23 insertions, 2 deletions
diff --git a/core/java/android/hardware/SensorManager.java b/core/java/android/hardware/SensorManager.java index aebe84e..98172e6 100644 --- a/core/java/android/hardware/SensorManager.java +++ b/core/java/android/hardware/SensorManager.java @@ -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; + } + } } } |
