add custom aspect ratio option

This commit is contained in:
Chloe committed 2025-01-18 14:30:49 -07:00
1 parent a687f8464e
commit 129ee40c0d
5 files changed
+96 -8

No files matched your search

@@ -1,7 +1,6 @@
package com.geode.launcher
import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Intent
import android.content.pm.ActivityInfo
import android.content.pm.ApplicationInfo
@@ -9,6 +8,7 @@ import android.content.pm.PackageInfo
import android.os.Build
import android.os.Bundle
import android.os.Environment
import android.text.InputType
import android.util.Log
import android.view.ViewGroup
import android.view.WindowManager
@@ -51,6 +51,13 @@ enum class DisplayMode {
}
}
fun ratioForPreference(value: String) = when (value) {
"4_3" -> 4/3.0f
"1_1" -> 1.0f
"16_10" -> 16/10.0f
else -> 1.77f
}
class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener, GeodeUtils.CapabilityListener {
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
private val sTag = GeometryDashActivity::class.simpleName
@@ -60,6 +67,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
private var displayMode = DisplayMode.DEFAULT
private var forceRefreshRate = false
private var mAspectRatio = 0.0f
override fun onCreate(savedInstanceState: Bundle?) {
setupUIState()
@@ -368,7 +376,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
frameLayout.layoutParams = frameLayoutParams
if (displayMode == DisplayMode.LIMITED) {
frameLayout.aspectRatio = 1.77f
frameLayout.aspectRatio = mAspectRatio
}
val editTextLayoutParams = ViewGroup.LayoutParams(
@@ -410,7 +418,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
renderer.setFrameRate = true
}
editText.inputType = 145
editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
glSurfaceView.cocos2dxEditText = editText
return frameLayout
@@ -419,11 +427,15 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
private fun setupUIState() {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
val preferenceUtils = PreferenceUtils.get(this)
displayMode = DisplayMode.fromInt(
PreferenceUtils.get(this).getInt(PreferenceUtils.Key.DISPLAY_MODE)
preferenceUtils.getInt(PreferenceUtils.Key.DISPLAY_MODE)
)
forceRefreshRate = PreferenceUtils.get(this).getBoolean(PreferenceUtils.Key.FORCE_HRR)
mAspectRatio = ratioForPreference(preferenceUtils.getString(PreferenceUtils.Key.CUSTOM_ASPECT_RATIO) ?: "16_9")
forceRefreshRate = preferenceUtils.getBoolean(PreferenceUtils.Key.FORCE_HRR)
if (forceRefreshRate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val maxRefreshRate = display?.supportedModes?.maxBy { it.refreshRate }?.refreshRate
@@ -355,6 +355,18 @@ fun SettingsScreen(
SettingsCard(
title = stringResource(R.string.preference_force_hrr),
preferenceKey = PreferenceUtils.Key.FORCE_HRR,
val currentDisplayMode by PreferenceUtils.useIntPreference(PreferenceUtils.Key.DISPLAY_MODE)
if (currentDisplayMode == 1) {
SettingsStringSelectCard(
title = stringResource(R.string.preference_custom_aspect_ratio_name),
dialogTitle = stringResource(R.string.preference_custom_aspect_ratio_select),
preferenceKey = PreferenceUtils.Key.CUSTOM_ASPECT_RATIO,
options = linkedMapOf(
"16_9" to stringResource(R.string.preference_custom_aspect_ratio_16x9),
"16_10" to stringResource(R.string.preference_custom_aspect_ratio_16x10),
"4_3" to stringResource(R.string.preference_custom_aspect_ratio_4x3),
"1_1" to stringResource(R.string.preference_custom_aspect_ratio_1x1),
)
)
}
}
@@ -8,9 +8,11 @@ import androidx.compose.foundation.layout.Row
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Clear
import androidx.compose.material3.AlertDialog
@@ -121,6 +123,54 @@ fun SettingsSelectCard(
}
}
@Composable
fun SettingsStringSelectCard(
title: String,
dialogTitle: String,
preferenceKey: PreferenceUtils.Key,
options: Map<String, String>,
extraSelectBehavior: ((String?) -> Unit)? = null
) {
val preferenceValue by PreferenceUtils.useStringPreference(preferenceKey)
var showDialog by remember { mutableStateOf(false) }
OptionsCard(
title = { OptionsTitle(title = title) },
modifier = Modifier
.clickable(
onClick = {
showDialog = true
},
role = Role.Button
)
) {
Text(options[preferenceValue] ?: preferenceValue ?: "")
}
if (showDialog) {
val context = LocalContext.current
SelectDialog(
title = dialogTitle,
onDismissRequest = {
showDialog = false
},
onSelect = { selected ->
showDialog = false
PreferenceUtils.get(context)
.setString(preferenceKey, selected)
extraSelectBehavior?.invoke(selected)
},
initialValue = preferenceValue,
) {
options.forEach { (k, v) ->
SelectOption(name = v, value = k)
}
}
}
}
@Composable
fun SettingsStringCard(
title: String,
@@ -253,7 +303,7 @@ fun <T> SelectDialog(
) {
// styling a dialog is actually a little hard if you're doing what i'm doing
// maybe there's a better way to make these padding values...
Column {
Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
Text(
title,
style = Typography.titleLarge,
@@ -142,7 +142,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
RELEASE_CHANNEL_TAG,
DEVELOPER_MODE,
CLEANUP_APKS,
CUSTOM_SYMBOL_LIST
CUSTOM_SYMBOL_LIST,
CUSTOM_ASPECT_RATIO,
}
private fun defaultValueForBooleanKey(key: Key): Boolean {
@@ -159,6 +160,11 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
else -> 0
}
private fun defaultValueForStringKey(key: Key) = when (key) {
Key.CUSTOM_ASPECT_RATIO -> "16_9"
else -> null
}
private fun keyToName(key: Key): String {
return when (key) {
Key.LOAD_AUTOMATICALLY -> "PreferenceLoadAutomatically"
@@ -180,6 +186,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
Key.DEVELOPER_MODE -> "PreferenceDeveloperMode"
Key.CLEANUP_APKS -> "PreferenceCleanupPackages"
Key.CUSTOM_SYMBOL_LIST -> "PreferenceCustomSymbolList"
Key.CUSTOM_ASPECT_RATIO -> "PreferenceCustomAspectRatio"
}
}
@@ -210,7 +217,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
fun getString(key: Key): String? {
val keyName = keyToName(key)
return sharedPreferences.getString(keyName, null)
return sharedPreferences.getString(keyName, defaultValueForStringKey(key))
}
fun setString(key: Key, value: String?) {