mirror of
https://github.com/geode-sdk/android-launcher.git
synced 2026-10-21 16:32:39 +00:00
replace screen ratio with more detailed option
This commit is contained in:
4 files changed
+54
-11
No files matched your search
@@ -12,6 +12,7 @@ import android.os.Bundle
|
|||||||
import android.os.Environment
|
import android.os.Environment
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
import android.view.ViewGroup
|
import android.view.ViewGroup
|
||||||
|
import android.view.WindowManager
|
||||||
import android.widget.FrameLayout
|
import android.widget.FrameLayout
|
||||||
import androidx.appcompat.app.AlertDialog
|
import androidx.appcompat.app.AlertDialog
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
@@ -35,6 +36,17 @@ import java.io.File
|
|||||||
import java.io.FileInputStream
|
import java.io.FileInputStream
|
||||||
import java.io.FileOutputStream
|
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 {
|
class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperListener, GeodeUtils.CapabilityListener {
|
||||||
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
private var mGLSurfaceView: Cocos2dxGLSurfaceView? = null
|
||||||
@@ -44,6 +56,8 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
private var mHasWindowFocus = false
|
private var mHasWindowFocus = false
|
||||||
private var mReceiver: BroadcastReceiver? = null
|
private var mReceiver: BroadcastReceiver? = null
|
||||||
|
|
||||||
|
private var displayMode = DisplayMode.DEFAULT
|
||||||
|
|
||||||
override fun onCreate(savedInstanceState: Bundle?) {
|
override fun onCreate(savedInstanceState: Bundle?) {
|
||||||
setupUIState()
|
setupUIState()
|
||||||
|
|
||||||
@@ -270,9 +284,7 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
val frameLayout = ConstrainedFrameLayout(this)
|
val frameLayout = ConstrainedFrameLayout(this)
|
||||||
frameLayout.layoutParams = frameLayoutParams
|
frameLayout.layoutParams = frameLayoutParams
|
||||||
|
|
||||||
val isRestricted = PreferenceUtils.get(this)
|
if (displayMode == DisplayMode.LIMITED) {
|
||||||
.getBoolean(PreferenceUtils.Key.LIMIT_ASPECT_RATIO)
|
|
||||||
if (isRestricted) {
|
|
||||||
// despite not being perfectly 16:9, this is what Android calls "16:9"
|
// despite not being perfectly 16:9, this is what Android calls "16:9"
|
||||||
frameLayout.aspectRatio = 1.86f
|
frameLayout.aspectRatio = 1.86f
|
||||||
}
|
}
|
||||||
@@ -308,6 +320,14 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
|
|||||||
private fun setupUIState() {
|
private fun setupUIState() {
|
||||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_USER_LANDSCAPE
|
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()
|
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) {
|
fun updateTheme(context: Context, theme: Int) {
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S) {
|
||||||
val uiModeManager = context.getSystemService(Context.UI_MODE_SERVICE) as UiModeManager
|
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),
|
description = context.getString(R.string.preference_load_automatically_description),
|
||||||
preferenceKey = PreferenceUtils.Key.LOAD_AUTOMATICALLY,
|
preferenceKey = PreferenceUtils.Key.LOAD_AUTOMATICALLY,
|
||||||
)
|
)
|
||||||
SettingsCard(
|
SettingsSelectCard(
|
||||||
title = stringResource(R.string.preference_limit_aspect_ratio_name),
|
title = stringResource(R.string.preference_display_mode_name),
|
||||||
description = stringResource(R.string.preference_limit_aspect_ratio_description),
|
dialogTitle = stringResource(R.string.preference_display_mode_select),
|
||||||
preferenceKey = PreferenceUtils.Key.LIMIT_ASPECT_RATIO
|
// 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(
|
OptionsButton(
|
||||||
title = stringResource(R.string.preferences_open_file_manager),
|
title = stringResource(R.string.preferences_open_file_manager),
|
||||||
|
|||||||
@@ -136,7 +136,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
DISMISSED_GJ_UPDATE,
|
DISMISSED_GJ_UPDATE,
|
||||||
LAUNCH_ARGUMENTS,
|
LAUNCH_ARGUMENTS,
|
||||||
IGNORE_LOAD_FAILURE,
|
IGNORE_LOAD_FAILURE,
|
||||||
LIMIT_ASPECT_RATIO
|
LIMIT_ASPECT_RATIO,
|
||||||
|
DISPLAY_MODE
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun defaultValueForBooleanKey(key: Key): Boolean {
|
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 {
|
private fun keyToName(key: Key): String {
|
||||||
return when (key) {
|
return when (key) {
|
||||||
Key.LOAD_TESTING -> "PreferenceLoadTesting"
|
Key.LOAD_TESTING -> "PreferenceLoadTesting"
|
||||||
@@ -163,6 +169,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
Key.LAUNCH_ARGUMENTS -> "PreferenceLaunchArguments"
|
Key.LAUNCH_ARGUMENTS -> "PreferenceLaunchArguments"
|
||||||
Key.IGNORE_LOAD_FAILURE -> "PreferenceIgnoreLoadFailure"
|
Key.IGNORE_LOAD_FAILURE -> "PreferenceIgnoreLoadFailure"
|
||||||
Key.LIMIT_ASPECT_RATIO -> "PreferenceLimitAspectRatio"
|
Key.LIMIT_ASPECT_RATIO -> "PreferenceLimitAspectRatio"
|
||||||
|
Key.DISPLAY_MODE -> "PreferenceDisplayMode"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -217,7 +224,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
|
|||||||
|
|
||||||
fun getInt(key: Key): Int {
|
fun getInt(key: Key): Int {
|
||||||
val keyName = keyToName(key)
|
val keyName = keyToName(key)
|
||||||
return sharedPreferences.getInt(keyName, 0)
|
return sharedPreferences.getInt(keyName, defaultValueForIntKey(key))
|
||||||
}
|
}
|
||||||
|
|
||||||
fun setInt(key: Key, value: Int) {
|
fun setInt(key: Key, value: Int) {
|
||||||
|
|||||||
@@ -96,8 +96,12 @@
|
|||||||
<string name="preference_theme_light">Light</string>
|
<string name="preference_theme_light">Light</string>
|
||||||
<string name="preference_theme_dark">Dark</string>
|
<string name="preference_theme_dark">Dark</string>
|
||||||
<string name="preference_black_background_name">Black background in dark theme</string>
|
<string name="preference_black_background_name">Black background in dark theme</string>
|
||||||
<string name="preference_limit_aspect_ratio_name">Limit aspect ratio</string>
|
|
||||||
<string name="preference_limit_aspect_ratio_description">Restricts the game window to a 16:9 ratio.</string>
|
<string name="preference_display_mode_name">Screen scale</string>
|
||||||
|
<string name="preference_display_mode_select">Select screen scale</string>
|
||||||
|
<string name="preference_display_mode_legacy">Limited (16:9)</string>
|
||||||
|
<string name="preference_display_mode_fullscreen">Edge-to-edge</string>
|
||||||
|
<string name="preference_display_mode_default">Default</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>
|
||||||
|
|||||||
Reference in new issue
Block a user