|
|
@ -23,30 +23,25 @@ import androidx.appcompat.app.AppCompatActivity |
|
|
import androidx.core.view.WindowCompat |
|
|
import androidx.core.view.WindowCompat |
|
|
import androidx.core.view.WindowInsetsCompat |
|
|
import androidx.core.view.WindowInsetsCompat |
|
|
import androidx.core.view.WindowInsetsControllerCompat |
|
|
import androidx.core.view.WindowInsetsControllerCompat |
|
|
import androidx.lifecycle.Lifecycle |
|
|
|
|
|
import androidx.lifecycle.lifecycleScope |
|
|
|
|
|
import androidx.lifecycle.repeatOnLifecycle |
|
|
|
|
|
import androidx.window.layout.WindowInfoTracker |
|
|
|
|
|
import kotlinx.coroutines.Dispatchers |
|
|
|
|
|
import kotlinx.coroutines.launch |
|
|
|
|
|
|
|
|
import androidx.navigation.fragment.NavHostFragment |
|
|
import org.yuzu.yuzu_emu.NativeLibrary |
|
|
import org.yuzu.yuzu_emu.NativeLibrary |
|
|
import org.yuzu.yuzu_emu.R |
|
|
import org.yuzu.yuzu_emu.R |
|
|
|
|
|
import org.yuzu.yuzu_emu.databinding.ActivityEmulationBinding |
|
|
import org.yuzu.yuzu_emu.features.settings.model.SettingsViewModel |
|
|
import org.yuzu.yuzu_emu.features.settings.model.SettingsViewModel |
|
|
import org.yuzu.yuzu_emu.fragments.EmulationFragment |
|
|
|
|
|
import org.yuzu.yuzu_emu.model.Game |
|
|
import org.yuzu.yuzu_emu.model.Game |
|
|
import org.yuzu.yuzu_emu.utils.ControllerMappingHelper |
|
|
import org.yuzu.yuzu_emu.utils.ControllerMappingHelper |
|
|
import org.yuzu.yuzu_emu.utils.ForegroundService |
|
|
import org.yuzu.yuzu_emu.utils.ForegroundService |
|
|
import org.yuzu.yuzu_emu.utils.InputHandler |
|
|
import org.yuzu.yuzu_emu.utils.InputHandler |
|
|
import org.yuzu.yuzu_emu.utils.NfcReader |
|
|
import org.yuzu.yuzu_emu.utils.NfcReader |
|
|
import org.yuzu.yuzu_emu.utils.SerializableHelper.parcelable |
|
|
|
|
|
import org.yuzu.yuzu_emu.utils.ThemeHelper |
|
|
import org.yuzu.yuzu_emu.utils.ThemeHelper |
|
|
import kotlin.math.roundToInt |
|
|
import kotlin.math.roundToInt |
|
|
|
|
|
|
|
|
class EmulationActivity : AppCompatActivity(), SensorEventListener { |
|
|
class EmulationActivity : AppCompatActivity(), SensorEventListener { |
|
|
|
|
|
private lateinit var binding: ActivityEmulationBinding |
|
|
|
|
|
|
|
|
private var controllerMappingHelper: ControllerMappingHelper? = null |
|
|
private var controllerMappingHelper: ControllerMappingHelper? = null |
|
|
|
|
|
|
|
|
var isActivityRecreated = false |
|
|
var isActivityRecreated = false |
|
|
private var emulationFragment: EmulationFragment? = null |
|
|
|
|
|
private lateinit var nfcReader: NfcReader |
|
|
private lateinit var nfcReader: NfcReader |
|
|
private lateinit var inputHandler: InputHandler |
|
|
private lateinit var inputHandler: InputHandler |
|
|
|
|
|
|
|
|
@ -55,8 +50,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { |
|
|
private var motionTimestamp: Long = 0 |
|
|
private var motionTimestamp: Long = 0 |
|
|
private var flipMotionOrientation: Boolean = false |
|
|
private var flipMotionOrientation: Boolean = false |
|
|
|
|
|
|
|
|
private lateinit var game: Game |
|
|
|
|
|
|
|
|
|
|
|
private val settingsViewModel: SettingsViewModel by viewModels() |
|
|
private val settingsViewModel: SettingsViewModel by viewModels() |
|
|
|
|
|
|
|
|
override fun onDestroy() { |
|
|
override fun onDestroy() { |
|
|
@ -70,47 +63,31 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { |
|
|
settingsViewModel.settings.loadSettings() |
|
|
settingsViewModel.settings.loadSettings() |
|
|
|
|
|
|
|
|
super.onCreate(savedInstanceState) |
|
|
super.onCreate(savedInstanceState) |
|
|
if (savedInstanceState == null) { |
|
|
|
|
|
// Get params we were passed |
|
|
|
|
|
game = intent.parcelable(EXTRA_SELECTED_GAME)!! |
|
|
|
|
|
isActivityRecreated = false |
|
|
|
|
|
} else { |
|
|
|
|
|
isActivityRecreated = true |
|
|
|
|
|
restoreState(savedInstanceState) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
binding = ActivityEmulationBinding.inflate(layoutInflater) |
|
|
|
|
|
setContentView(binding.root) |
|
|
|
|
|
|
|
|
|
|
|
val navHostFragment = |
|
|
|
|
|
supportFragmentManager.findFragmentById(R.id.fragment_container) as NavHostFragment |
|
|
|
|
|
val navController = navHostFragment.navController |
|
|
|
|
|
navController |
|
|
|
|
|
.setGraph(R.navigation.emulation_navigation, intent.extras) |
|
|
|
|
|
|
|
|
|
|
|
isActivityRecreated = savedInstanceState != null |
|
|
|
|
|
|
|
|
controllerMappingHelper = ControllerMappingHelper() |
|
|
controllerMappingHelper = ControllerMappingHelper() |
|
|
|
|
|
|
|
|
// Set these options now so that the SurfaceView the game renders into is the right size. |
|
|
// Set these options now so that the SurfaceView the game renders into is the right size. |
|
|
enableFullscreenImmersive() |
|
|
enableFullscreenImmersive() |
|
|
|
|
|
|
|
|
setContentView(R.layout.activity_emulation) |
|
|
|
|
|
window.decorView.setBackgroundColor(getColor(android.R.color.black)) |
|
|
window.decorView.setBackgroundColor(getColor(android.R.color.black)) |
|
|
|
|
|
|
|
|
// Find or create the EmulationFragment |
|
|
|
|
|
emulationFragment = |
|
|
|
|
|
supportFragmentManager.findFragmentById(R.id.frame_emulation_fragment) as EmulationFragment? |
|
|
|
|
|
if (emulationFragment == null) { |
|
|
|
|
|
emulationFragment = EmulationFragment.newInstance(game) |
|
|
|
|
|
supportFragmentManager.beginTransaction() |
|
|
|
|
|
.add(R.id.frame_emulation_fragment, emulationFragment!!) |
|
|
|
|
|
.commit() |
|
|
|
|
|
} |
|
|
|
|
|
title = game.title |
|
|
|
|
|
|
|
|
|
|
|
nfcReader = NfcReader(this) |
|
|
nfcReader = NfcReader(this) |
|
|
nfcReader.initialize() |
|
|
nfcReader.initialize() |
|
|
|
|
|
|
|
|
inputHandler = InputHandler() |
|
|
inputHandler = InputHandler() |
|
|
inputHandler.initialize() |
|
|
inputHandler.initialize() |
|
|
|
|
|
|
|
|
lifecycleScope.launch(Dispatchers.Main) { |
|
|
|
|
|
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) { |
|
|
|
|
|
WindowInfoTracker.getOrCreate(this@EmulationActivity) |
|
|
|
|
|
.windowLayoutInfo(this@EmulationActivity) |
|
|
|
|
|
.collect { emulationFragment?.updateCurrentLayout(this@EmulationActivity, it) } |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Start a foreground service to prevent the app from getting killed in the background |
|
|
// Start a foreground service to prevent the app from getting killed in the background |
|
|
val startIntent = Intent(this, ForegroundService::class.java) |
|
|
val startIntent = Intent(this, ForegroundService::class.java) |
|
|
startForegroundService(startIntent) |
|
|
startForegroundService(startIntent) |
|
|
@ -157,11 +134,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { |
|
|
nfcReader.onNewIntent(intent) |
|
|
nfcReader.onNewIntent(intent) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
override fun onSaveInstanceState(outState: Bundle) { |
|
|
|
|
|
outState.putParcelable(EXTRA_SELECTED_GAME, game) |
|
|
|
|
|
super.onSaveInstanceState(outState) |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
override fun dispatchKeyEvent(event: KeyEvent): Boolean { |
|
|
override fun dispatchKeyEvent(event: KeyEvent): Boolean { |
|
|
if (event.source and InputDevice.SOURCE_JOYSTICK != InputDevice.SOURCE_JOYSTICK && |
|
|
if (event.source and InputDevice.SOURCE_JOYSTICK != InputDevice.SOURCE_JOYSTICK && |
|
|
event.source and InputDevice.SOURCE_GAMEPAD != InputDevice.SOURCE_GAMEPAD |
|
|
event.source and InputDevice.SOURCE_GAMEPAD != InputDevice.SOURCE_GAMEPAD |
|
|
@ -248,10 +220,6 @@ class EmulationActivity : AppCompatActivity(), SensorEventListener { |
|
|
|
|
|
|
|
|
override fun onAccuracyChanged(sensor: Sensor, i: Int) {} |
|
|
override fun onAccuracyChanged(sensor: Sensor, i: Int) {} |
|
|
|
|
|
|
|
|
private fun restoreState(savedInstanceState: Bundle) { |
|
|
|
|
|
game = savedInstanceState.parcelable(EXTRA_SELECTED_GAME)!! |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private fun enableFullscreenImmersive() { |
|
|
private fun enableFullscreenImmersive() { |
|
|
WindowCompat.setDecorFitsSystemWindows(window, false) |
|
|
WindowCompat.setDecorFitsSystemWindows(window, false) |
|
|
|
|
|
|
|
|
|