Android: add auto-rotation support#594
Open
chofuhoyu wants to merge 9 commits into
Open
Conversation
- Change AndroidManifest.xml from nosensor to fullSensor - Add setAutoOrientation() extension and sensor mode pass-through - Add setScreenAutoRotation() method to MainActivity - Add setScreenAutoRotation() to LuaInterface - Add android.orientation.setAuto() JNI binding
Member
|
thanks for the contribution!!! all is looking great! I agree with codacy this time :) |
pazos
self-requested a review
June 9, 2026 18:13
pazos
reviewed
Jun 9, 2026
Extract the 7-branch OR condition in setOrientationCompat into a well-named private function to satisfy detekt's complexity threshold.
When 'Lock auto rotation to current orientation' is enabled, use Android's axis-specific sensor modes (SENSOR_PORTRAIT / SENSOR_LANDSCAPE) instead of FULL_SENSOR. This lets the OS itself restrict rotation to the same axis, fixing the lock being bypassed because FULL_SENSOR rotated the screen before Lua's gyro filter could intervene. - Add setLockedAutoOrientation() in ActivityExtensions.kt - Add setScreenAutoRotationLocked() in MainActivity.kt and LuaInterface.kt - Add android.orientation.setAutoLocked() binding in assets/android.lua
Frenzie
reviewed
Jun 11, 2026
Frenzie
approved these changes
Jun 11, 2026
Frenzie
left a comment
Member
There was a problem hiding this comment.
Fine by me. (Mind, only relevant if the others are too busy for the next week.)
…ping screenIsLandscape was determined by comparing current display width/height, but Display.getWidth()/getHeight() return dimensions adjusted for the current rotation. On a native portrait device started in landscape, this caused isLandscape=true, permanently corrupting all orientation calculations. Fix: account for Display.getRotation() when determining native orientation. For ROTATION_90/270, width and height are swapped relative to natural orientation, so invert the comparison. Also fix getOrientationCompat mapping for both native portrait and native landscape devices: ROTATION_90 and ROTATION_270 had incorrect DEVICE_ROTATED_* return values for both cases.
…ionCompat Log evidence shows that for this native portrait device: REVERSE_LANDSCAPE(8) → ROTATION_270 (CCW), and LANDSCAPE(0) → ROTATION_90 (CW). The swap in setOrientationCompat inverted these, so locking to CCW(3) → REVERSE_LANDSCAPE(8) → swap → LANDSCAPE(0) → CW(1), flipping the device 180° from the intended orientation. The Lua framebuffer already maps DEVICE_ROTATED_* to the correct ASCREEN_ORIENTATION_* constants. No further remapping is needed for native portrait devices.
hugleo
self-requested a review
June 13, 2026 14:15
Contributor
|
It might be worth testing on an emulator to verify that manual rotation still works as before on versions above 4.1, both with and without notch emulation. I can also test it on my devices and phone. |
Author
Thanks. It needs more tests. Please let me know if you tried this patch on Android emulator, devices or phone, and whether it works fine. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR adds the Android-side changes needed for auto-rotation support in KOReader (see companion PR in the main repository).
Changes
screenOrientationfromnosensortofullSensor, allowing Android to manage screen rotation via the accelerometer.setAutoOrientation()extension and a sensor mode guard insetOrientationCompatthat passesFULL_SENSORand related constants through without remapping.setScreenAutoRotation(enabled)method to enable/disable auto mode viarequestedOrientation.android.orientation.setAuto(enabled)binding.Dependencies
This PR must be merged before the companion PR in
koreader/koreader, which updates the luajit-launcher submodule pointer and implements the Lua-side auto-rotation UI and logic.Companion PR: koreader/koreader#15507
Testing
This change is