From a890a5073f86b5cb5eb1d5023b6873ee41a52b78 Mon Sep 17 00:00:00 2001 From: gladius Date: Sat, 24 May 2025 17:47:49 +0200 Subject: [PATCH 1/4] fix(android): sensor listeners registered with maxReportLatencyUs value --- .../implementation/OrientationSensorsEventListener.kt | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt b/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt index 96613ba..4790e3f 100644 --- a/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt +++ b/android/src/main/java/com/orientationdirector/implementation/OrientationSensorsEventListener.kt @@ -20,7 +20,8 @@ class OrientationSensorsEventListener( private var mMagneticFieldSensor: Sensor? = mSensorManager.getDefaultSensor(Sensor.TYPE_MAGNETIC_FIELD) - private var hasRotationSensor: Boolean = mRotationSensor != null + private var hasRotationSensor: Boolean = + mRotationSensor != null private var hasAccelerometerAndMagneticFieldSensors: Boolean = mAccelerometerSensor != null && mMagneticFieldSensor != null From a948c7922bafc4fefcb8102a0872d66c362e6c9b Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Thu, 26 Jun 2025 20:00:17 +0200 Subject: [PATCH 2/4] fix: landscape mode check not accounting for pitch --- .../com/orientationdirector/implementation/Utils.kt | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/android/src/main/java/com/orientationdirector/implementation/Utils.kt b/android/src/main/java/com/orientationdirector/implementation/Utils.kt index 779cab3..07a8fa7 100644 --- a/android/src/main/java/com/orientationdirector/implementation/Utils.kt +++ b/android/src/main/java/com/orientationdirector/implementation/Utils.kt @@ -38,11 +38,13 @@ class Utils(private val context: ReactContext) { // ////////////////////////////////////// + val isPitchInLandscapeModeRange = checkIfPitchIsInLandscapeModeRange(pitchDegrees) + return when { rollDegrees.equals(-0f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_UP rollDegrees.equals(-180f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_DOWN - rollDegrees in tolerance..landscapeRightLimit - tolerance -> Orientation.LANDSCAPE_RIGHT - rollDegrees in landscapeLeftLimit + tolerance..-tolerance -> Orientation.LANDSCAPE_LEFT + rollDegrees in tolerance..landscapeRightLimit - tolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_RIGHT + rollDegrees in landscapeLeftLimit + tolerance..-tolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_LEFT pitchDegrees in portraitLimit..-0f -> Orientation.PORTRAIT else -> Orientation.PORTRAIT_UPSIDE_DOWN } @@ -94,4 +96,9 @@ class Utils(private val context: ReactContext) { return context.currentActivity!!.requestedOrientation; } + + private fun checkIfPitchIsInLandscapeModeRange(pitchDegrees: Float): Boolean { + val tolerance = 5f + return pitchDegrees > -tolerance && pitchDegrees < tolerance + } } From 5ea2f17d6488b9387516b0845a69bd9936c10c17 Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Thu, 26 Jun 2025 20:06:23 +0200 Subject: [PATCH 3/4] fix: add pitch tolerance to improve portrait and upside down detection --- .../java/com/orientationdirector/implementation/Utils.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/orientationdirector/implementation/Utils.kt b/android/src/main/java/com/orientationdirector/implementation/Utils.kt index 07a8fa7..ef62c37 100644 --- a/android/src/main/java/com/orientationdirector/implementation/Utils.kt +++ b/android/src/main/java/com/orientationdirector/implementation/Utils.kt @@ -26,6 +26,7 @@ class Utils(private val context: ReactContext) { val rollDegrees = Math.toDegrees(rollRadians.toDouble()).toFloat() // This is needed to account for inaccuracy due to subtle movements such as tilting + val pitchTolerance = 5f val tolerance = 20f ////////////////////////////////////// @@ -38,14 +39,14 @@ class Utils(private val context: ReactContext) { // ////////////////////////////////////// - val isPitchInLandscapeModeRange = checkIfPitchIsInLandscapeModeRange(pitchDegrees) + val isPitchInLandscapeModeRange = checkIfPitchIsInLandscapeModeRange(pitchDegrees, pitchTolerance) return when { rollDegrees.equals(-0f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_UP rollDegrees.equals(-180f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_DOWN rollDegrees in tolerance..landscapeRightLimit - tolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_RIGHT rollDegrees in landscapeLeftLimit + tolerance..-tolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_LEFT - pitchDegrees in portraitLimit..-0f -> Orientation.PORTRAIT + pitchDegrees in portraitLimit..pitchTolerance -> Orientation.PORTRAIT else -> Orientation.PORTRAIT_UPSIDE_DOWN } } @@ -97,8 +98,7 @@ class Utils(private val context: ReactContext) { return context.currentActivity!!.requestedOrientation; } - private fun checkIfPitchIsInLandscapeModeRange(pitchDegrees: Float): Boolean { - val tolerance = 5f + private fun checkIfPitchIsInLandscapeModeRange(pitchDegrees: Float, tolerance: Float): Boolean { return pitchDegrees > -tolerance && pitchDegrees < tolerance } } From dd09065204086a936eb9ce2284c62731ac80c5f9 Mon Sep 17 00:00:00 2001 From: gladiuscode Date: Thu, 26 Jun 2025 22:34:27 +0200 Subject: [PATCH 4/4] feat: increase pitch tolerance and rename tolerance to rollTolerance --- .../java/com/orientationdirector/implementation/Utils.kt | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/android/src/main/java/com/orientationdirector/implementation/Utils.kt b/android/src/main/java/com/orientationdirector/implementation/Utils.kt index ef62c37..b362f3c 100644 --- a/android/src/main/java/com/orientationdirector/implementation/Utils.kt +++ b/android/src/main/java/com/orientationdirector/implementation/Utils.kt @@ -26,8 +26,8 @@ class Utils(private val context: ReactContext) { val rollDegrees = Math.toDegrees(rollRadians.toDouble()).toFloat() // This is needed to account for inaccuracy due to subtle movements such as tilting - val pitchTolerance = 5f - val tolerance = 20f + val pitchTolerance = 15f + val rollTolerance = 20f ////////////////////////////////////// // These limits are set based on SensorManager.getOrientation reference @@ -44,8 +44,8 @@ class Utils(private val context: ReactContext) { return when { rollDegrees.equals(-0f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_UP rollDegrees.equals(-180f) && (pitchDegrees.equals(0f) || pitchDegrees.equals(-0f)) -> Orientation.FACE_DOWN - rollDegrees in tolerance..landscapeRightLimit - tolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_RIGHT - rollDegrees in landscapeLeftLimit + tolerance..-tolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_LEFT + rollDegrees in rollTolerance..landscapeRightLimit - rollTolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_RIGHT + rollDegrees in landscapeLeftLimit + rollTolerance..-rollTolerance && isPitchInLandscapeModeRange -> Orientation.LANDSCAPE_LEFT pitchDegrees in portraitLimit..pitchTolerance -> Orientation.PORTRAIT else -> Orientation.PORTRAIT_UPSIDE_DOWN }