diff --git a/app/src/main/java/no/naiv/tiltshift/camera/CameraManager.kt b/app/src/main/java/no/naiv/tiltshift/camera/CameraManager.kt index b6f659d..7f7bed5 100644 --- a/app/src/main/java/no/naiv/tiltshift/camera/CameraManager.kt +++ b/app/src/main/java/no/naiv/tiltshift/camera/CameraManager.kt @@ -194,15 +194,19 @@ class CameraManager(private val context: Context) { /** * Updates the target rotation for Preview and ImageCapture use cases. - * Call when the device rotates: this rotates the SurfaceTexture transform matrix - * (so the GL preview stays upright) and tags captures with the right orientation. - * Safe to call on the main thread; CameraX permits live target-rotation updates. + * + * Rebinds the use cases so CameraX issues a fresh SurfaceRequest with a + * resolution matching the new rotation and a corresponding texture transform + * matrix. Calling `preview.targetRotation = rotation` alone is insufficient + * for a custom SurfaceProvider — the new rotation only takes effect on + * subsequently bound streams, leaving the live SurfaceTexture matrix and + * buffer size stale (which made the preview appear locked to the original + * portrait orientation when the device was rotated to landscape). */ fun setTargetRotation(rotation: Int) { if (targetRotation == rotation) return targetRotation = rotation - preview?.targetRotation = rotation - imageCapture?.targetRotation = rotation + lifecycleOwnerRef?.get()?.let { bindCameraUseCases(it) } } /** diff --git a/app/src/main/java/no/naiv/tiltshift/util/OrientationDetector.kt b/app/src/main/java/no/naiv/tiltshift/util/OrientationDetector.kt index 45bcf3a..f7b49da 100644 --- a/app/src/main/java/no/naiv/tiltshift/util/OrientationDetector.kt +++ b/app/src/main/java/no/naiv/tiltshift/util/OrientationDetector.kt @@ -24,17 +24,11 @@ class OrientationDetector(private val context: Context) { override fun onOrientationChanged(orientation: Int) { 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 { orientation >= 315 || orientation < 45 -> Surface.ROTATION_0 - orientation >= 45 && orientation < 135 -> Surface.ROTATION_270 + orientation >= 45 && orientation < 135 -> Surface.ROTATION_90 orientation >= 135 && orientation < 225 -> Surface.ROTATION_180 - else -> Surface.ROTATION_90 + else -> Surface.ROTATION_270 } if (rotation != lastRotation) { diff --git a/version.properties b/version.properties index 0f86d43..dd2cc78 100644 --- a/version.properties +++ b/version.properties @@ -1,4 +1,4 @@ versionMajor=1 versionMinor=1 -versionPatch=7 -versionCode=9 +versionPatch=8 +versionCode=10