add option to limit aspect ratio

This commit is contained in:
qimiko committed 2024-02-13 01:48:35 -07:00
1 parent 44bbb25c7e
commit 7db022f392
5 files changed
+60 -9

No files matched your search

@@ -21,6 +21,7 @@ import androidx.core.view.WindowInsetsControllerCompat
import com.customRobTop.BaseRobTopActivity
import com.customRobTop.JniToCpp
import com.geode.launcher.utils.Constants
import com.geode.launcher.utils.ConstrainedFrameLayout
import com.geode.launcher.utils.DownloadUtils
import com.geode.launcher.utils.GeodeUtils
import com.geode.launcher.utils.LaunchUtils
@@ -262,10 +263,24 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
}
private fun createView(): FrameLayout {
val frameLayoutParams = ViewGroup.LayoutParams(-1, -1)
val frameLayout = FrameLayout(this)
val frameLayoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.MATCH_PARENT
)
val frameLayout = ConstrainedFrameLayout(this)
frameLayout.layoutParams = frameLayoutParams
val editTextLayoutParams = ViewGroup.LayoutParams(-1, -2)
val isRestricted = PreferenceUtils.get(this)
.getBoolean(PreferenceUtils.Key.LIMIT_ASPECT_RATIO)
if (isRestricted) {
// despite not being perfectly 16:9, this is what Android calls "16:9"
frameLayout.aspectRatio = 1.86f
}
val editTextLayoutParams = ViewGroup.LayoutParams(
ViewGroup.LayoutParams.MATCH_PARENT,
ViewGroup.LayoutParams.WRAP_CONTENT
)
val editText = Cocos2dxEditText(this)
editText.layoutParams = editTextLayoutParams
frameLayout.addView(editText)
@@ -276,11 +291,6 @@ class GeometryDashActivity : AppCompatActivity(), Cocos2dxHelper.Cocos2dxHelperL
frameLayout.addView(this.mGLSurfaceView)
glSurfaceView.setEGLConfigChooser(5, 6, 5, 0, 16, 8)
if (isAndroidEmulator()) {
glSurfaceView.setEGLConfigChooser(8, 8, 8, 8, 16, 0)
}
glSurfaceView.initView()
glSurfaceView.setCocos2dxRenderer(Cocos2dxRenderer())
@@ -302,6 +302,11 @@ 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
)
OptionsButton(
title = stringResource(R.string.preferences_open_file_manager),
onClick = { onOpenFileManager(context) }
@@ -0,0 +1,32 @@
package com.geode.launcher.utils
import android.content.Context
import android.widget.FrameLayout
class ConstrainedFrameLayout(context: Context) : FrameLayout(context) {
// avoid running the aspect ratio fix when we don't need it
var aspectRatio: Float? = null;
override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) {
if (aspectRatio != null) {
val width = MeasureSpec.getSize(widthMeasureSpec)
val height = MeasureSpec.getSize(heightMeasureSpec)
if (width == 0 || height == 0) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec)
}
val calculatedWidth = height * (aspectRatio ?: 1.0f);
val padding = ((width - calculatedWidth) / 2).toInt()
// ignore paddings where the screen ends up looking odd
if (padding > 0) {
setPadding(padding, 0, padding, 0)
}
}
super.onMeasure(
widthMeasureSpec,
heightMeasureSpec
)
}
}
@@ -135,7 +135,8 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
LAST_DISMISSED_UPDATE,
DISMISSED_GJ_UPDATE,
LAUNCH_ARGUMENTS,
IGNORE_LOAD_FAILURE
IGNORE_LOAD_FAILURE,
LIMIT_ASPECT_RATIO
}
private fun defaultValueForBooleanKey(key: Key): Boolean {
@@ -161,6 +162,7 @@ class PreferenceUtils(private val sharedPreferences: SharedPreferences) {
Key.DISMISSED_GJ_UPDATE -> "PreferenceDismissedGJUpdate"
Key.LAUNCH_ARGUMENTS -> "PreferenceLaunchArguments"
Key.IGNORE_LOAD_FAILURE -> "PreferenceIgnoreLoadFailure"
Key.LIMIT_ASPECT_RATIO -> "PreferenceLimitAspectRatio"
}
}
+2
View File
@@ -90,6 +90,8 @@
<string name="preference_theme_light">Light</string>
<string name="preference_theme_dark">Dark</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_category_updater">Updates</string>
<string name="preference_update_automatically_name">Enable automatic updates</string>