Sensor, portrait, Landscape Settings

This commit is contained in:
BeZide93 2025-09-06 17:29:05 -05:00 committed by KeatonTheBot
parent d73d82fbc0
commit 316dc3a9b3
3 changed files with 86 additions and 8 deletions

View file

@ -60,7 +60,7 @@ class MainActivity : BaseActivity() {
mainViewModel?.gameHost?.hideProgressIndicator()
}
// <<< NEW: is called from the Native/Lib page to set the loading progress
// <<< is called from the Native/Lib page to set the loading progress
@JvmStatic
fun updateProgress(info: String, percent: Float) {
// Route directly via the GameHost it takes care of the progress states
@ -143,6 +143,9 @@ class MainActivity : BaseActivity() {
WindowCompat.setDecorFitsSystemWindows(window, false)
window.addFlags(WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON)
// --- Apply alignment
applyOrientationPreference()
WindowInsetsControllerCompat(window, window.decorView).let { controller ->
controller.hide(WindowInsetsCompat.Type.systemBars())
controller.systemBarsBehavior = WindowInsetsControllerCompat.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
@ -215,6 +218,9 @@ class MainActivity : BaseActivity() {
override fun onResume() {
super.onResume()
// --- Reapply alignment if necessary
applyOrientationPreference()
handler.postDelayed(delayedHandleIntent, 10)
isActive = true
@ -258,22 +264,21 @@ class MainActivity : BaseActivity() {
}
}
private fun applyOrientationPreference() {
val pref = QuickSettings(this).orientationPreference
requestedOrientation = pref.value
}
fun shutdownAndRestart() {
// Create an intent to restart the app
val packageManager = packageManager
val intent = packageManager.getLaunchIntentForPackage(packageName)
val componentName = intent?.component
val restartIntent = Intent.makeRestartActivityTask(componentName)
// Clean up resources if needed
mainViewModel?.let {
it.performanceManager?.setTurboMode(false)
}
// Start the new activity directly
startActivity(restartIntent)
// Force immediate process termination
Runtime.getRuntime().exit(0)
}
}

View file

@ -2,10 +2,25 @@ package org.kenjinx.android.viewmodels
import android.app.Activity
import android.content.SharedPreferences
import android.content.pm.ActivityInfo
import androidx.core.content.edit
import androidx.preference.PreferenceManager
class QuickSettings(val activity: Activity) {
// --- Alignment
enum class OrientationPreference(val value: Int) {
Sensor(ActivityInfo.SCREEN_ORIENTATION_SENSOR),
SensorLandscape(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE),
SensorPortrait(ActivityInfo.SCREEN_ORIENTATION_SENSOR_PORTRAIT);
companion object {
fun fromValue(v: Int): OrientationPreference =
entries.firstOrNull { it.value == v } ?: Sensor
}
}
var orientationPreference: OrientationPreference
var ignoreMissingServices: Boolean
var enablePptc: Boolean
var enableLowPowerPptc: Boolean
@ -41,6 +56,10 @@ class QuickSettings(val activity: Activity) {
private var sharedPref: SharedPreferences = PreferenceManager.getDefaultSharedPreferences(activity)
init {
// --- Load alignment (Default: Sensor)
val oriValue = sharedPref.getInt("orientationPreference", ActivityInfo.SCREEN_ORIENTATION_SENSOR)
orientationPreference = OrientationPreference.fromValue(oriValue)
memoryManagerMode = MemoryManagerMode.entries.toTypedArray()[sharedPref.getInt("memoryManagerMode", MemoryManagerMode.HostMappedUnsafe.ordinal)]
useNce = sharedPref.getBoolean("useNce", false)
memoryConfiguration = MemoryConfiguration.entries.toTypedArray()[sharedPref.getInt("memoryConfiguration", MemoryConfiguration.MemoryConfiguration4GiB.ordinal)]
@ -76,6 +95,8 @@ class QuickSettings(val activity: Activity) {
fun save() {
sharedPref.edit {
// --- Save orientation
putInt("orientationPreference", orientationPreference.value)
putInt("memoryManagerMode", memoryManagerMode.ordinal)
putBoolean("useNce", useNce)

View file

@ -79,6 +79,10 @@ import org.kenjinx.android.widgets.ExpandableView
import org.kenjinx.android.widgets.SimpleAlertDialog
import org.kenjinx.android.widgets.SwitchSelector
// >>> QuickSettings + OrientationPreference
import org.kenjinx.android.viewmodels.QuickSettings
import org.kenjinx.android.viewmodels.QuickSettings.OrientationPreference
class SettingViews {
companion object {
const val EXPANSTION_TRANSITION_DURATION = 450
@ -131,6 +135,11 @@ class SettingViews {
val enableGraphicsLogs = remember { mutableStateOf(true) }
val isNavigating = remember { mutableStateOf(false) }
// Load orientation from QuickSettings
val orientationPref = remember {
mutableStateOf(QuickSettings(mainViewModel.activity).orientationPreference)
}
if (!loaded.value) {
settingsViewModel.initializeState(
memoryManagerMode,
@ -231,6 +240,20 @@ class SettingViews {
) {
ExpandableView(onCardArrowClick = { }, title = "User Interface", icon = Icons.Outlined.BarChart ,isFirst = true) {
Column(modifier = Modifier.fillMaxWidth()) {
// Screen Orientation
OrientationDropdown(
selectedOrientation = orientationPref.value,
onOrientationSelected = { sel ->
orientationPref.value = sel
// Save and use immediately
val qs = QuickSettings(mainViewModel.activity)
qs.orientationPreference = sel
qs.save()
mainViewModel.activity.requestedOrientation = sel.value
}
)
isGrid.SwitchSelector("Use Grid")
Row(
modifier = Modifier
@ -1273,6 +1296,35 @@ class SettingViews {
}
}
// ---- Dropdown for orientation ----
@Composable
fun OrientationDropdown(
selectedOrientation: OrientationPreference,
onOrientationSelected: (OrientationPreference) -> Unit
) {
val options = listOf(
OrientationPreference.Sensor,
OrientationPreference.SensorLandscape,
OrientationPreference.SensorPortrait
)
DropdownSelector(
label = "Screen Orientation",
selectedValue = selectedOrientation,
options = options,
getDisplayText = { opt ->
when (opt) {
OrientationPreference.Sensor -> "Sensor"
OrientationPreference.SensorLandscape -> "Sensor Landscape"
OrientationPreference.SensorPortrait -> "Sensor Portrait"
}
},
onOptionSelected = onOrientationSelected
)
}
// ---- Existing dropdowns ----
@Composable
fun MemoryModeDropdown(
selectedMemoryManagerMode: MemoryManagerMode,
@ -1363,7 +1415,7 @@ class SettingViews {
onOptionSelected = onScaleSelected
)
}
@Composable
fun AnisotropicFilteringDropdown(
selectedAnisotropy: Float,