mirror of
https://github.com/azahar-emu/azahar.git
synced 2026-06-06 02:33:44 -04:00
android: Block activity recreation due to orientation changes on boot (#2030)
This commit is contained in:
parent
6eca4afac5
commit
599069eb33
1 changed files with 33 additions and 6 deletions
|
|
@ -8,6 +8,7 @@ import android.Manifest.permission
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
import android.content.Intent
|
import android.content.Intent
|
||||||
import android.content.SharedPreferences
|
import android.content.SharedPreferences
|
||||||
|
import android.content.pm.ActivityInfo
|
||||||
import android.content.pm.PackageManager
|
import android.content.pm.PackageManager
|
||||||
import android.net.Uri
|
import android.net.Uri
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
|
|
@ -80,7 +81,9 @@ class EmulationActivity : AppCompatActivity() {
|
||||||
return navHostFragment.getChildFragmentManager().fragments.last() as EmulationFragment
|
return navHostFragment.getChildFragmentManager().fragments.last() as EmulationFragment
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private var isRotationBlocked: Boolean = true
|
||||||
private var isEmulationRunning: Boolean = false
|
private var isEmulationRunning: Boolean = false
|
||||||
|
private var isEmulationReady: Boolean = false
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
requestWindowFeature(Window.FEATURE_NO_TITLE)
|
||||||
|
|
@ -89,12 +92,20 @@ class EmulationActivity : AppCompatActivity() {
|
||||||
|
|
||||||
ThemeUtil.setTheme(this)
|
ThemeUtil.setTheme(this)
|
||||||
settingsViewModel.settings.loadSettings()
|
settingsViewModel.settings.loadSettings()
|
||||||
|
|
||||||
|
screenAdjustmentUtil = ScreenAdjustmentUtil(this, windowManager, settingsViewModel.settings)
|
||||||
|
|
||||||
|
// Block orientation until emulation is ready to prevent unneccesary
|
||||||
|
// surface recreation until the renderer is ready.
|
||||||
|
isRotationBlocked = true
|
||||||
|
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_LOCKED
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|
||||||
secondaryDisplay = SecondaryDisplay(this)
|
secondaryDisplay = SecondaryDisplay(this)
|
||||||
secondaryDisplay.updateDisplay()
|
secondaryDisplay.updateDisplay()
|
||||||
|
|
||||||
binding = ActivityEmulationBinding.inflate(layoutInflater)
|
binding = ActivityEmulationBinding.inflate(layoutInflater)
|
||||||
screenAdjustmentUtil = ScreenAdjustmentUtil(this, windowManager, settingsViewModel.settings)
|
|
||||||
hotkeyUtility = HotkeyUtility(screenAdjustmentUtil, this)
|
hotkeyUtility = HotkeyUtility(screenAdjustmentUtil, this)
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
|
@ -119,8 +130,6 @@ class EmulationActivity : AppCompatActivity() {
|
||||||
isEmulationRunning = true
|
isEmulationRunning = true
|
||||||
instance = this
|
instance = this
|
||||||
|
|
||||||
applyOrientationSettings() // Check for orientation settings at startup
|
|
||||||
|
|
||||||
val game = try {
|
val game = try {
|
||||||
intent.extras?.let { extras ->
|
intent.extras?.let { extras ->
|
||||||
BundleCompat.getParcelable(extras, "game", Game::class.java)
|
BundleCompat.getParcelable(extras, "game", Game::class.java)
|
||||||
|
|
@ -140,9 +149,18 @@ class EmulationActivity : AppCompatActivity() {
|
||||||
// rotations. Here we set full screen immersive repeatedly in onResume and in
|
// rotations. Here we set full screen immersive repeatedly in onResume and in
|
||||||
// onWindowFocusChanged to prevent the unwanted status bar state.
|
// onWindowFocusChanged to prevent the unwanted status bar state.
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
super.onResume()
|
|
||||||
enableFullscreenImmersive()
|
enableFullscreenImmersive()
|
||||||
applyOrientationSettings() // Check for orientation settings changes on runtime
|
if (isEmulationReady) {
|
||||||
|
// If emulation is ready then unblock rotation
|
||||||
|
isRotationBlocked = false
|
||||||
|
applyOrientationSettings()
|
||||||
|
emulationViewModel.setEmulationStarted(true)
|
||||||
|
} else {
|
||||||
|
if (!isRotationBlocked) {
|
||||||
|
applyOrientationSettings()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
super.onResume()
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onStop() {
|
override fun onStop() {
|
||||||
|
|
@ -151,8 +169,8 @@ class EmulationActivity : AppCompatActivity() {
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||||
super.onWindowFocusChanged(hasFocus)
|
|
||||||
enableFullscreenImmersive()
|
enableFullscreenImmersive()
|
||||||
|
super.onWindowFocusChanged(hasFocus)
|
||||||
}
|
}
|
||||||
|
|
||||||
public override fun onRestart() {
|
public override fun onRestart() {
|
||||||
|
|
@ -164,11 +182,15 @@ class EmulationActivity : AppCompatActivity() {
|
||||||
override fun onSaveInstanceState(outState: Bundle) {
|
override fun onSaveInstanceState(outState: Bundle) {
|
||||||
super.onSaveInstanceState(outState)
|
super.onSaveInstanceState(outState)
|
||||||
outState.putBoolean("isEmulationRunning", isEmulationRunning)
|
outState.putBoolean("isEmulationRunning", isEmulationRunning)
|
||||||
|
outState.putBoolean("isEmulationReady", isEmulationReady)
|
||||||
|
outState.putBoolean("isRotationBlocked", isRotationBlocked)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
override fun onRestoreInstanceState(savedInstanceState: Bundle) {
|
||||||
super.onRestoreInstanceState(savedInstanceState)
|
super.onRestoreInstanceState(savedInstanceState)
|
||||||
isEmulationRunning = savedInstanceState.getBoolean("isEmulationRunning", false)
|
isEmulationRunning = savedInstanceState.getBoolean("isEmulationRunning", false)
|
||||||
|
isEmulationReady = savedInstanceState.getBoolean("isEmulationReady", false)
|
||||||
|
isRotationBlocked = savedInstanceState.getBoolean("isRotationBlocked", isRotationBlocked)
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
|
@ -222,6 +244,11 @@ class EmulationActivity : AppCompatActivity() {
|
||||||
|
|
||||||
fun onEmulationStarted() {
|
fun onEmulationStarted() {
|
||||||
emulationViewModel.setEmulationStarted(true)
|
emulationViewModel.setEmulationStarted(true)
|
||||||
|
isEmulationReady = true
|
||||||
|
if (isRotationBlocked) {
|
||||||
|
isRotationBlocked = false
|
||||||
|
applyOrientationSettings()
|
||||||
|
}
|
||||||
Toast.makeText(
|
Toast.makeText(
|
||||||
applicationContext,
|
applicationContext,
|
||||||
getString(R.string.emulation_menu_help),
|
getString(R.string.emulation_menu_help),
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue