android: Set default rotation to landscape

This commit is contained in:
Abandoned Cart 2023-06-04 14:44:24 -04:00
parent 4767fe993b
commit 7ab4ab16a7
2 changed files with 10 additions and 28 deletions

View file

@ -6,15 +6,12 @@ package org.yuzu.yuzu_emu.activities
import android.app.Activity
import android.content.Context
import android.content.Intent
import android.content.res.Configuration
import android.graphics.Rect
import android.hardware.Sensor
import android.hardware.SensorEvent
import android.hardware.SensorEventListener
import android.hardware.SensorManager
import android.hardware.display.DisplayManager
import android.os.Bundle
import android.view.Display
import android.view.InputDevice
import android.view.KeyEvent
import android.view.MotionEvent
@ -22,7 +19,6 @@ import android.view.Surface
import android.view.View
import android.view.inputmethod.InputMethodManager
import androidx.appcompat.app.AppCompatActivity
import androidx.core.content.getSystemService
import androidx.core.view.WindowCompat
import androidx.core.view.WindowInsetsCompat
import androidx.core.view.WindowInsetsControllerCompat
@ -144,8 +140,8 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
startMotionSensorListener()
NativeLibrary.notifyOrientationChange(
EmulationMenuSettings.screenLayout,
getAdjustedRotation()
EmulationMenuSettings.LayoutOption_MobileLandscape,
Surface.ROTATION_90
)
}
@ -252,23 +248,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener {
override fun onAccuracyChanged(sensor: Sensor, i: Int) {}
private fun getAdjustedRotation():Int {
val rotation = getSystemService<DisplayManager>()!!.getDisplay(Display.DEFAULT_DISPLAY).rotation
val config: Configuration = resources.configuration
if ((config.screenLayout and Configuration.SCREENLAYOUT_LONG_YES) != 0 ||
(config.screenLayout and Configuration.SCREENLAYOUT_LONG_NO) == 0) {
return rotation
}
when (rotation) {
Surface.ROTATION_0 -> return Surface.ROTATION_90
Surface.ROTATION_90 -> return Surface.ROTATION_0
Surface.ROTATION_180 -> return Surface.ROTATION_270
Surface.ROTATION_270 -> return Surface.ROTATION_180
}
return rotation
}
private fun restoreState(savedInstanceState: Bundle) {
game = savedInstanceState.parcelable(EXTRA_SELECTED_GAME)!!
}

View file

@ -187,16 +187,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
val emulatorLayout = when (newConfig.orientation) {
Configuration.ORIENTATION_LANDSCAPE -> { EmulationMenuSettings.LayoutOption_MobileLandscape }
Configuration.ORIENTATION_PORTRAIT -> { EmulationMenuSettings.LayoutOption_MobilePortrait }
Configuration.ORIENTATION_UNDEFINED -> { EmulationMenuSettings.LayoutOption_MobileLandscape }
else -> { EmulationMenuSettings.LayoutOption_MobileLandscape }
}
emulationActivity?.let {
var rotation = it.getSystemService<DisplayManager>()!!
.getDisplay(Display.DEFAULT_DISPLAY).rotation
if ((newConfig.screenLayout and Configuration.SCREENLAYOUT_LONG_YES) == 0 ||
(newConfig.screenLayout and Configuration.SCREENLAYOUT_LONG_NO) != 0
) {
if (newConfig.orientation != Configuration.ORIENTATION_PORTRAIT) {
rotation = when (rotation) {
Surface.ROTATION_0 -> Surface.ROTATION_90
Surface.ROTATION_90 -> Surface.ROTATION_0
@ -205,7 +202,13 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback {
else -> { rotation }
}
}
NativeLibrary.notifyOrientationChange(emulatorLayout, rotation)
if (it.isInPictureInPictureMode) {
NativeLibrary.notifyOrientationChange(
EmulationMenuSettings.LayoutOption_MobileLandscape, rotation
)
} else {
NativeLibrary.notifyOrientationChange(emulatorLayout, rotation)
}
}
}