mirror of
https://github.com/Lime3DS/Lime3DS.git
synced 2025-12-16 12:08:49 +00:00
Code cleanup
This commit is contained in:
parent
77910cc2f9
commit
258deecb26
@ -48,7 +48,7 @@ import org.citra.citra_emu.utils.FileBrowserHelper
|
|||||||
import org.citra.citra_emu.utils.EmulationLifecycleUtil
|
import org.citra.citra_emu.utils.EmulationLifecycleUtil
|
||||||
import org.citra.citra_emu.utils.EmulationMenuSettings
|
import org.citra.citra_emu.utils.EmulationMenuSettings
|
||||||
import org.citra.citra_emu.utils.Log
|
import org.citra.citra_emu.utils.Log
|
||||||
import org.citra.citra_emu.utils.MaxRefreshRate
|
import org.citra.citra_emu.utils.RefreshRateUtil
|
||||||
import org.citra.citra_emu.utils.ThemeUtil
|
import org.citra.citra_emu.utils.ThemeUtil
|
||||||
import org.citra.citra_emu.viewmodel.EmulationViewModel
|
import org.citra.citra_emu.viewmodel.EmulationViewModel
|
||||||
|
|
||||||
@ -87,7 +87,7 @@ class EmulationActivity : AppCompatActivity() {
|
|||||||
ThemeUtil.setTheme(this)
|
ThemeUtil.setTheme(this)
|
||||||
settingsViewModel.settings.loadSettings()
|
settingsViewModel.settings.loadSettings()
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
MaxRefreshRate.set(this, forceSixtyHrz = true)
|
RefreshRateUtil.enforceRefreshRate(this, sixtyHz = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
|||||||
@ -38,7 +38,7 @@ import org.citra.citra_emu.features.settings.utils.SettingsFile
|
|||||||
import org.citra.citra_emu.utils.SystemSaveGame
|
import org.citra.citra_emu.utils.SystemSaveGame
|
||||||
import org.citra.citra_emu.utils.DirectoryInitialization
|
import org.citra.citra_emu.utils.DirectoryInitialization
|
||||||
import org.citra.citra_emu.utils.InsetsHelper
|
import org.citra.citra_emu.utils.InsetsHelper
|
||||||
import org.citra.citra_emu.utils.MaxRefreshRate
|
import org.citra.citra_emu.utils.RefreshRateUtil
|
||||||
import org.citra.citra_emu.utils.ThemeUtil
|
import org.citra.citra_emu.utils.ThemeUtil
|
||||||
|
|
||||||
class SettingsActivity : AppCompatActivity(), SettingsActivityView {
|
class SettingsActivity : AppCompatActivity(), SettingsActivityView {
|
||||||
@ -58,7 +58,7 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView {
|
|||||||
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
binding = ActivitySettingsBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
MaxRefreshRate.set(this, forceSixtyHrz = false)
|
RefreshRateUtil.enforceRefreshRate(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|||||||
@ -52,7 +52,7 @@ import org.citra.citra_emu.utils.CitraDirectoryUtils
|
|||||||
import org.citra.citra_emu.utils.DirectoryInitialization
|
import org.citra.citra_emu.utils.DirectoryInitialization
|
||||||
import org.citra.citra_emu.utils.FileBrowserHelper
|
import org.citra.citra_emu.utils.FileBrowserHelper
|
||||||
import org.citra.citra_emu.utils.InsetsHelper
|
import org.citra.citra_emu.utils.InsetsHelper
|
||||||
import org.citra.citra_emu.utils.MaxRefreshRate
|
import org.citra.citra_emu.utils.RefreshRateUtil
|
||||||
import org.citra.citra_emu.utils.PermissionsHandler
|
import org.citra.citra_emu.utils.PermissionsHandler
|
||||||
import org.citra.citra_emu.utils.ThemeUtil
|
import org.citra.citra_emu.utils.ThemeUtil
|
||||||
import org.citra.citra_emu.viewmodel.GamesViewModel
|
import org.citra.citra_emu.viewmodel.GamesViewModel
|
||||||
@ -90,7 +90,7 @@ class MainActivity : AppCompatActivity(), ThemeProvider {
|
|||||||
binding = ActivityMainBinding.inflate(layoutInflater)
|
binding = ActivityMainBinding.inflate(layoutInflater)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
MaxRefreshRate.set(this, forceSixtyHrz = false)
|
RefreshRateUtil.enforceRefreshRate(this)
|
||||||
}
|
}
|
||||||
|
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|||||||
@ -0,0 +1,42 @@
|
|||||||
|
// Copyright Citra Emulator Project / Azahar Emulator Project
|
||||||
|
// Licensed under GPLv2 or any later version
|
||||||
|
// Refer to the license.txt file included.
|
||||||
|
|
||||||
|
package org.citra.citra_emu.utils
|
||||||
|
import android.app.Activity
|
||||||
|
import android.os.Build
|
||||||
|
import androidx.annotation.RequiresApi
|
||||||
|
|
||||||
|
object RefreshRateUtil {
|
||||||
|
// Since Android 15, the OS automatically sets apps categorized as games to run with a 60hz refresh rate.
|
||||||
|
// This functions sets the refresh rate to either the maximum allowed refresh rate or 60hz.
|
||||||
|
@RequiresApi(Build.VERSION_CODES.R)
|
||||||
|
fun enforceRefreshRate(activity: Activity, sixtyHz: Boolean = false) {
|
||||||
|
val display = activity.display
|
||||||
|
val window = activity.window
|
||||||
|
|
||||||
|
display?.let {
|
||||||
|
// Get all supported modes and find the one with the highest refresh rate
|
||||||
|
val supportedModes = it.supportedModes
|
||||||
|
val maxRefreshRate = supportedModes.maxByOrNull { mode -> mode.refreshRate }
|
||||||
|
|
||||||
|
if (maxRefreshRate == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
var newModeId: Int?
|
||||||
|
if (sixtyHz) {
|
||||||
|
newModeId = supportedModes.firstOrNull { mode -> mode.refreshRate == 60f }?.modeId
|
||||||
|
} else {
|
||||||
|
// Set the preferred display mode to the one with the highest refresh rate
|
||||||
|
newModeId = maxRefreshRate.modeId
|
||||||
|
}
|
||||||
|
|
||||||
|
if (newModeId == null) {
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
window.attributes.preferredDisplayModeId = newModeId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1,38 +0,0 @@
|
|||||||
// Copyright Citra Emulator Project / Azahar Emulator Project
|
|
||||||
// Licensed under GPLv2 or any later version
|
|
||||||
// Refer to the license.txt file included.
|
|
||||||
|
|
||||||
package org.citra.citra_emu.utils
|
|
||||||
import android.app.Activity
|
|
||||||
import android.os.Build
|
|
||||||
import androidx.annotation.RequiresApi
|
|
||||||
|
|
||||||
object MaxRefreshRate {
|
|
||||||
//Since Android 15, google automatically forces "games" to be 60 hrz.
|
|
||||||
// This functions sets the refresh rate to max supported rate, unless forced to 60 hrz.
|
|
||||||
@RequiresApi(Build.VERSION_CODES.R)
|
|
||||||
fun set(activity: Activity, forceSixtyHrz: Boolean) {
|
|
||||||
val display = activity.display
|
|
||||||
val window = activity.window
|
|
||||||
display?.let {
|
|
||||||
// Get all supported modes and find the one with the highest refresh rate
|
|
||||||
val supportedModes = it.supportedModes
|
|
||||||
val maxRefreshRate = supportedModes.maxByOrNull { mode -> mode.refreshRate }
|
|
||||||
|
|
||||||
if (maxRefreshRate != null) {
|
|
||||||
val layoutParams = window.attributes
|
|
||||||
val modeId = if (forceSixtyHrz) {
|
|
||||||
supportedModes.firstOrNull { mode -> mode.refreshRate == 60f }?.modeId
|
|
||||||
} else {
|
|
||||||
// Set the preferred display mode to the one with the highest refresh rate
|
|
||||||
maxRefreshRate.modeId
|
|
||||||
}
|
|
||||||
|
|
||||||
if (modeId != null) {
|
|
||||||
layoutParams.preferredDisplayModeId = modeId
|
|
||||||
window.attributes = layoutParams
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Reference in New Issue
Block a user