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 package com.geode.launcher
import android.annotation.SuppressLint import android.annotation.SuppressLint
import android.content.BroadcastReceiver
import android.content.Intent import android.content.Intent
import android.content.pm.ActivityInfo import android.content.pm.ActivityInfo
import android.content.pm.ApplicationInfo import android.content.pm.ApplicationInfo
@@ -9,6 +8,7 @@ import android.content.pm.PackageInfo
import android.os.Build import android.os.Build
import android.os.Bundle import android.os.Bundle
import android.os.Environment import android.os.Environment
import android.text.InputType
import android.util.Log import android.util.Log
import android.view.ViewGroup import android.view.ViewGroup
import android.view.WindowManager 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 { class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener, GeodeUtils.CapabilityListener {
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
private val sTag = GeometryDashActivity::class.simpleName private val sTag = GeometryDashActivity::class.simpleName
@@ -60,6 +67,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
private var displayMode = DisplayMode.DEFAULT private var displayMode = DisplayMode.DEFAULT
private var forceRefreshRate = false private var forceRefreshRate = false
private var mAspectRatio = 0.0f
override fun onCreate(savedInstanceState: Bundle?) { override fun onCreate(savedInstanceState: Bundle?) {
setupUIState() setupUIState()
@@ -368,7 +376,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
frameLayout.layoutParams = frameLayoutParams frameLayout.layoutParams = frameLayoutParams
if (displayMode == DisplayMode.LIMITED) { if (displayMode == DisplayMode.LIMITED) {
frameLayout.aspectRatio = 1.77f frameLayout.aspectRatio = mAspectRatio
} }
val editTextLayoutParams = ViewGroup.LayoutParams( val editTextLayoutParams = ViewGroup.LayoutParams(
@@ -410,7 +418,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
renderer.setFrameRate = true renderer.setFrameRate = true
} }
editText.inputType = 145 editText.inputType = InputType.TYPE_CLASS_TEXT or InputType.TYPE_TEXT_VARIATION_VISIBLE_PASSWORD
glSurfaceView.cocos2dxEditText = editText glSurfaceView.cocos2dxEditText = editText
return frameLayout return frameLayout
@@ -419,11 +427,15 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
private fun setupUIState() { private fun setupUIState() {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
val preferenceUtils = PreferenceUtils.get(this)
displayMode = DisplayMode.fromInt( 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) { if (forceRefreshRate && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
val maxRefreshRate = display?.supportedModes?.maxBy { it.refreshRate }?.refreshRate val maxRefreshRate = display?.supportedModes?.maxBy { it.refreshRate }?.refreshRate
@@ -355,6 +355,18 @@ fun SettingsScreen(
SettingsCard( SettingsCard(
title = stringResource(R.string.preference_force_hrr), title = stringResource(R.string.preference_force_hrr),
preferenceKey = PreferenceUtils.Key.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.fillMaxWidth
import androidx.compose.foundation.layout.height import androidx.compose.foundation.layout.height
import androidx.compose.foundation.layout.padding import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.rememberScrollState
import androidx.compose.foundation.selection.toggleable import androidx.compose.foundation.selection.toggleable
import androidx.compose.foundation.shape.RoundedCornerShape import androidx.compose.foundation.shape.RoundedCornerShape
import androidx.compose.foundation.text.KeyboardOptions import androidx.compose.foundation.text.KeyboardOptions
import androidx.compose.foundation.verticalScroll
import androidx.compose.material.icons.Icons import androidx.compose.material.icons.Icons
import androidx.compose.material.icons.filled.Clear import androidx.compose.material.icons.filled.Clear
import androidx.compose.material3.AlertDialog 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 @Composable
fun SettingsStringCard( fun SettingsStringCard(
title: String, 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 // 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... // maybe there's a better way to make these padding values...
Column { Column(modifier = Modifier.verticalScroll(rememberScrollState())) {
Text( Text(
title, title,
style = Typography.titleLarge, style = Typography.titleLarge,
@@ -142,7 +142,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
RELEASE_CHANNEL_TAG, RELEASE_CHANNEL_TAG,
DEVELOPER_MODE, DEVELOPER_MODE,
CLEANUP_APKS, CLEANUP_APKS,
CUSTOM_SYMBOL_LIST CUSTOM_SYMBOL_LIST,
CUSTOM_ASPECT_RATIO,
} }
private fun defaultValueForBooleanKey(key: Key): Boolean { private fun defaultValueForBooleanKey(key: Key): Boolean {
@@ -159,6 +160,11 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
else -> 0 else -> 0
} }
private fun defaultValueForStringKey(key: Key) = when (key) {
Key.CUSTOM_ASPECT_RATIO -> "16_9"
else -> null
}
private fun keyToName(key: Key): String { private fun keyToName(key: Key): String {
return when (key) { return when (key) {
Key.LOAD_AUTOMATICALLY -> "PreferenceLoadAutomatically" Key.LOAD_AUTOMATICALLY -> "PreferenceLoadAutomatically"
@@ -180,6 +186,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
Key.DEVELOPER_MODE -> "PreferenceDeveloperMode" Key.DEVELOPER_MODE -> "PreferenceDeveloperMode"
Key.CLEANUP_APKS -> "PreferenceCleanupPackages" Key.CLEANUP_APKS -> "PreferenceCleanupPackages"
Key.CUSTOM_SYMBOL_LIST -> "PreferenceCustomSymbolList" 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? { fun getString(key: Key): String? {
val keyName = keyToName(key) val keyName = keyToName(key)
return sharedPreferences.getString(keyName, null) return sharedPreferences.getString(keyName, defaultValueForStringKey(key))
} }
fun setString(key: Key, value: String?) { fun setString(key: Key, value: String?) {
+7
View File
@@ -137,6 +137,13 @@
<string name="preference_display_mode_fullscreen">Edge-to-edge</string> <string name="preference_display_mode_fullscreen">Edge-to-edge</string>
<string name="preference_display_mode_default">Default</string> <string name="preference_display_mode_default">Default</string>
<string name="preference_custom_aspect_ratio_name">Aspect ratio</string>
<string name="preference_custom_aspect_ratio_select">Select aspect ratio</string>
<string name="preference_custom_aspect_ratio_16x9">16:9</string>
<string name="preference_custom_aspect_ratio_16x10">16:10</string>
<string name="preference_custom_aspect_ratio_4x3">4:3</string>
<string name="preference_custom_aspect_ratio_1x1">1:1</string>
<string name="preference_category_updater">Updates</string> <string name="preference_category_updater">Updates</string>
<string name="preference_update_automatically_name">Enable automatic updates</string> <string name="preference_update_automatically_name">Enable automatic updates</string>
<string name="preference_release_channel_name">Use nightly release channel</string> <string name="preference_release_channel_name">Use nightly release channel</string>