mirror of
https://github.com/izzy2lost/xemu.git
synced 2026-07-06 00:20:22 -07:00
fix orientations to not flip upside down
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
|
||||
<activity
|
||||
android:name=".LauncherActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="true">
|
||||
|
||||
<intent-filter>
|
||||
@@ -35,7 +35,7 @@
|
||||
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:screenOrientation="sensorLandscape"
|
||||
android:screenOrientation="landscape"
|
||||
android:configChanges="keyboard|keyboardHidden|orientation|screenSize|screenLayout|smallestScreenSize|uiMode"
|
||||
android:hardwareAccelerated="true"
|
||||
android:process=":xemu"
|
||||
@@ -48,17 +48,17 @@
|
||||
|
||||
<activity
|
||||
android:name=".SetupWizardActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".GameLibraryActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="false" />
|
||||
|
||||
<activity
|
||||
android:name=".SettingsActivity"
|
||||
android:screenOrientation="fullSensor"
|
||||
android:screenOrientation="portrait"
|
||||
android:exported="false" />
|
||||
|
||||
</application>
|
||||
|
||||
@@ -151,6 +151,7 @@ class GameLibraryActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
OrientationLocker(this).enable()
|
||||
setContentView(R.layout.activity_game_library)
|
||||
EdgeToEdgeHelper.enable(this)
|
||||
EdgeToEdgeHelper.applySystemBarPadding(findViewById(R.id.library_scroll))
|
||||
|
||||
@@ -15,6 +15,7 @@ class LauncherActivity : Activity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
OrientationLocker(this).enable()
|
||||
|
||||
val prefs = getSharedPreferences("x1box_prefs", MODE_PRIVATE)
|
||||
var setupComplete = prefs.getBoolean("setup_complete", false)
|
||||
|
||||
@@ -78,6 +78,7 @@ class MainActivity : SDLActivity(), InputManager.InputDeviceListener {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
OrientationLocker(this, landscapeOnly = true).enable()
|
||||
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
|
||||
val requestedSlot = intent?.getIntExtra(EXTRA_AUTO_LOAD_SNAPSHOT_SLOT, 0) ?: 0
|
||||
if (requestedSlot in 1..TOTAL_SNAPSHOT_SLOTS) {
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
package com.izzy2lost.x1box
|
||||
|
||||
import android.app.Activity
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.view.OrientationEventListener
|
||||
|
||||
/**
|
||||
* Prevents reversed (upside-down) orientations.
|
||||
*
|
||||
* UI mode: portrait when upright/right-rotated, left landscape otherwise.
|
||||
* Game mode: always left landscape, no exceptions.
|
||||
*/
|
||||
class OrientationLocker(private val activity: Activity, private val landscapeOnly: Boolean = false) {
|
||||
|
||||
private val listener = object : OrientationEventListener(activity) {
|
||||
override fun onOrientationChanged(orientation: Int) {
|
||||
if (orientation == ORIENTATION_UNKNOWN) return
|
||||
|
||||
val target = if (landscapeOnly) {
|
||||
// In-game: always left landscape regardless of how the device is held.
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||
} else {
|
||||
// UI: portrait when upright or rotating right, landscape otherwise.
|
||||
// 315-360 / 0-134 → portrait (upright + right rotation)
|
||||
// 135-314 → landscape (upside-down + left rotation)
|
||||
if (orientation < 135 || orientation >= 315)
|
||||
ActivityInfo.SCREEN_ORIENTATION_PORTRAIT
|
||||
else
|
||||
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE
|
||||
}
|
||||
|
||||
if (activity.requestedOrientation != target) {
|
||||
activity.requestedOrientation = target
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun enable() {
|
||||
if (listener.canDetectOrientation()) listener.enable()
|
||||
}
|
||||
|
||||
fun disable() {
|
||||
listener.disable()
|
||||
}
|
||||
}
|
||||
@@ -207,6 +207,7 @@ class SettingsActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
OrientationLocker(this).enable()
|
||||
setContentView(R.layout.activity_settings)
|
||||
EdgeToEdgeHelper.enable(this)
|
||||
EdgeToEdgeHelper.applySystemBarPadding(findViewById(R.id.settings_scroll))
|
||||
|
||||
@@ -152,6 +152,7 @@ class SetupWizardActivity : AppCompatActivity() {
|
||||
|
||||
override fun onCreate(savedInstanceState: Bundle?) {
|
||||
super.onCreate(savedInstanceState)
|
||||
OrientationLocker(this).enable()
|
||||
|
||||
mcpxPath = loadValidatedLocalPath("mcpxPath", "mcpxUri", ::isSavedMcpxFileValid)
|
||||
flashPath = loadValidatedLocalPath("flashPath", "flashUri", ::isSavedFlashFileValid)
|
||||
|
||||
Reference in New Issue
Block a user