Fix landscape image rotating opposite to device
OrientationDetector mapped the OrientationEventListener angle to
Surface.ROTATION_* with 90 and 270 swapped relative to the CameraX
docs example. The angle reports the device's physical clockwise
rotation, whereas Surface.ROTATION_* describes the screen's logical
rotation (opposite direction), so the values must be inverted.
Symptom: rotating the phone clockwise rotated the live preview counter-
clockwise (and vice versa), instead of keeping world-up at screen-up.
The bug was previously masked because the only consumer of the value
(deviceRotation in capturePhoto) is unused — the live preview commit
(d321f07) wired this same value into CameraX's setTargetRotation, which
exposed the inverted mapping.
Bump to 1.1.7.
Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
parent
fc64081712
commit
5eb476a059
2 changed files with 10 additions and 4 deletions
|
|
@ -24,11 +24,17 @@ class OrientationDetector(private val context: Context) {
|
||||||
override fun onOrientationChanged(orientation: Int) {
|
override fun onOrientationChanged(orientation: Int) {
|
||||||
if (orientation == ORIENTATION_UNKNOWN) return
|
if (orientation == ORIENTATION_UNKNOWN) return
|
||||||
|
|
||||||
|
// OrientationEventListener reports the device's physical rotation
|
||||||
|
// (clockwise from natural). Surface.ROTATION_* describes the screen's
|
||||||
|
// logical rotation, which is the opposite direction — so device tilted
|
||||||
|
// 90° CW (orientation ≈ 90, "left side at top") maps to ROTATION_270,
|
||||||
|
// and 90° CCW (orientation ≈ 270) maps to ROTATION_90. Matches the
|
||||||
|
// CameraX docs example for setTargetRotation.
|
||||||
val rotation = when {
|
val rotation = when {
|
||||||
orientation >= 315 || orientation < 45 -> Surface.ROTATION_0
|
orientation >= 315 || orientation < 45 -> Surface.ROTATION_0
|
||||||
orientation >= 45 && orientation < 135 -> Surface.ROTATION_90
|
orientation >= 45 && orientation < 135 -> Surface.ROTATION_270
|
||||||
orientation >= 135 && orientation < 225 -> Surface.ROTATION_180
|
orientation >= 135 && orientation < 225 -> Surface.ROTATION_180
|
||||||
else -> Surface.ROTATION_270
|
else -> Surface.ROTATION_90
|
||||||
}
|
}
|
||||||
|
|
||||||
if (rotation != lastRotation) {
|
if (rotation != lastRotation) {
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,4 @@
|
||||||
versionMajor=1
|
versionMajor=1
|
||||||
versionMinor=1
|
versionMinor=1
|
||||||
versionPatch=6
|
versionPatch=7
|
||||||
versionCode=8
|
versionCode=9
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue