replace screen ratio with more detailed option

This commit is contained in:
qimiko committed 2024-02-13 23:40:12 -07:00
1 parent cd73362c1c
commit c53a23faf9
4 files changed
+54 -11

No files matched your search

@@ -12,6 +12,7 @@ import android.os.Bundle
import android.os.Environment
import android.util.Log
import android.view.ViewGroup
import android.view.WindowManager
import android.widget.FrameLayout
import androidx.appcompat.app.AlertDialog
import androidx.appcompat.app.AppCompatActivity
@@ -35,6 +36,17 @@ import java.io.File
import java.io.FileInputStream
import java.io.FileOutputStream
enum class DisplayMode {
DEFAULT, LIMITED, FULLSCREEN;
companion object {
fun fromInt(i: Int) = when (i) {
1 -> LIMITED
2 -> FULLSCREEN
else -> DEFAULT
}
}
}
class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener, GeodeUtils.CapabilityListener {
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
@@ -44,6 +56,8 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
private var mHasWindowFocus = false
private var mReceiver: BroadcastReceiver? = null
private var displayMode = DisplayMode.DEFAULT
override fun onCreate(savedInstanceState: Bundle?) {
setupUIState()
@@ -270,9 +284,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
val frameLayout = ConstrainedFrameLayout(this)
frameLayout.layoutParams = frameLayoutParams
val isRestricted = PreferenceUtils.get(this)
.getBoolean(PreferenceUtils.Key.LIMIT_ASPECT_RATIO)
if (isRestricted) {
if (displayMode == DisplayMode.LIMITED) {
// despite not being perfectly 16:9, this is what Android calls "16:9"
frameLayout.aspectRatio = 1.86f
}
@@ -308,6 +320,14 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
private fun setupUIState() {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
displayMode = DisplayMode.fromInt(
PreferenceUtils.get(this).getInt(PreferenceUtils.Key.DISPLAY_MODE)
)
if (displayMode == DisplayMode.FULLSCREEN && Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
}
hideSystemUi()
}
@@ -193,6 +193,15 @@ fun themeToKey(theme: Int): String {
}
}
@Composable
fun displayOptionToKey(option: Int): String {
return when (option) {
1 -> stringResource(R.string.preference_display_mode_legacy)
2 -> stringResource(R.string.preference_display_mode_fullscreen)
else -> stringResource(R.string.preference_display_mode_default)
}
}
fun updateTheme(context: Context, theme: Int) {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
@@ -302,10 +311,13 @@ fun SettingsScreen(
description = context.getString(R.string.preference_load_automatically_description),
preferenceKey = PreferenceUtils.Key.LOAD_AUTOMATICALLY,
)
SettingsCard(
title = stringResource(R.string.preference_limit_aspect_ratio_name),
description = stringResource(R.string.preference_limit_aspect_ratio_description),
preferenceKey = PreferenceUtils.Key.LIMIT_ASPECT_RATIO
SettingsSelectCard(
title = stringResource(R.string.preference_display_mode_name),
dialogTitle = stringResource(R.string.preference_display_mode_select),
// necessary api doesn't exist on older versions of android
maxVal = if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) 2 else 1,
preferenceKey = PreferenceUtils.Key.DISPLAY_MODE,
toLabel = { displayOptionToKey(it) }
)
OptionsButton(
title = stringResource(R.string.preferences_open_file_manager),
@@ -136,7 +136,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
DISMISSED_GJ_UPDATE,
LAUNCH_ARGUMENTS,
IGNORE_LOAD_FAILURE,
LIMIT_ASPECT_RATIO
LIMIT_ASPECT_RATIO,
DISPLAY_MODE
}
private fun defaultValueForBooleanKey(key: Key): Boolean {
@@ -147,6 +148,11 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
}
}
private fun defaultValueForIntKey(key: Key) = when (key) {
Key.DISPLAY_MODE -> if (this.getBoolean(Key.LIMIT_ASPECT_RATIO)) 1 else 0
else -> 0
}
private fun keyToName(key: Key): String {
return when (key) {
Key.LOAD_TESTING -> "PreferenceLoadTesting"
@@ -163,6 +169,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
Key.LAUNCH_ARGUMENTS -> "PreferenceLaunchArguments"
Key.IGNORE_LOAD_FAILURE -> "PreferenceIgnoreLoadFailure"
Key.LIMIT_ASPECT_RATIO -> "PreferenceLimitAspectRatio"
Key.DISPLAY_MODE -> "PreferenceDisplayMode"
}
}
@@ -217,7 +224,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
fun getInt(key: Key): Int {
val keyName = keyToName(key)
return sharedPreferences.getInt(keyName, 0)
return sharedPreferences.getInt(keyName, defaultValueForIntKey(key))
}
fun setInt(key: Key, value: Int) {