mirror of
https://github.com/Lime3DS/Lime3DS
synced 2024-10-29 19:27:53 +00:00
android: Add screen orientation presets to layout settings (#420)
Some checks are pending
lime-build / source (push) Waiting to run
lime-build / linux (appimage) (push) Waiting to run
lime-build / linux (fresh) (push) Waiting to run
lime-build / macos (arm64) (push) Waiting to run
lime-build / macos (x86_64) (push) Waiting to run
lime-build / macos-universal (push) Blocked by required conditions
lime-build / windows (msvc) (push) Waiting to run
lime-build / windows (msys2) (push) Waiting to run
lime-build / android (push) Waiting to run
lime-build / release (push) Blocked by required conditions
lime-format / clang-format (push) Waiting to run
lime-transifex / transifex (push) Waiting to run
Some checks are pending
lime-build / source (push) Waiting to run
lime-build / linux (appimage) (push) Waiting to run
lime-build / linux (fresh) (push) Waiting to run
lime-build / macos (arm64) (push) Waiting to run
lime-build / macos (x86_64) (push) Waiting to run
lime-build / macos-universal (push) Blocked by required conditions
lime-build / windows (msvc) (push) Waiting to run
lime-build / windows (msys2) (push) Waiting to run
lime-build / android (push) Waiting to run
lime-build / release (push) Blocked by required conditions
lime-format / clang-format (push) Waiting to run
lime-transifex / transifex (push) Waiting to run
Co-authored-by: OpenSauce04 <opensauce04@gmail.com>
This commit is contained in:
parent
0a5536aebe
commit
d739ef13ab
8 changed files with 95 additions and 20 deletions
|
@ -34,6 +34,7 @@ import io.github.lime3ds.android.databinding.ActivityEmulationBinding
|
|||
import io.github.lime3ds.android.display.ScreenAdjustmentUtil
|
||||
import io.github.lime3ds.android.features.hotkeys.HotkeyUtility
|
||||
import io.github.lime3ds.android.features.settings.model.BooleanSetting
|
||||
import io.github.lime3ds.android.features.settings.model.IntSetting
|
||||
import io.github.lime3ds.android.features.settings.model.SettingsViewModel
|
||||
import io.github.lime3ds.android.features.settings.model.view.InputBindingSetting
|
||||
import io.github.lime3ds.android.fragments.EmulationFragment
|
||||
|
@ -75,7 +76,7 @@ class EmulationActivity : AppCompatActivity() {
|
|||
NativeLibrary.enableAdrenoTurboMode(BooleanSetting.ADRENO_GPU_BOOST.boolean)
|
||||
|
||||
binding = ActivityEmulationBinding.inflate(layoutInflater)
|
||||
screenAdjustmentUtil = ScreenAdjustmentUtil(windowManager, settingsViewModel.settings)
|
||||
screenAdjustmentUtil = ScreenAdjustmentUtil(this, windowManager, settingsViewModel.settings)
|
||||
hotkeyUtility = HotkeyUtility(screenAdjustmentUtil)
|
||||
setContentView(binding.root)
|
||||
|
||||
|
@ -105,6 +106,8 @@ class EmulationActivity : AppCompatActivity() {
|
|||
|
||||
isEmulationRunning = true
|
||||
instance = this
|
||||
|
||||
applyOrientationSettings() // Check for orientation settings at startup
|
||||
}
|
||||
|
||||
// On some devices, the system bars will not disappear on first boot or after some
|
||||
|
@ -113,6 +116,7 @@ class EmulationActivity : AppCompatActivity() {
|
|||
override fun onResume() {
|
||||
super.onResume()
|
||||
enableFullscreenImmersive()
|
||||
applyOrientationSettings() // Check for orientation settings changes on runtime
|
||||
}
|
||||
|
||||
override fun onWindowFocusChanged(hasFocus: Boolean) {
|
||||
|
@ -204,6 +208,11 @@ class EmulationActivity : AppCompatActivity() {
|
|||
}
|
||||
}
|
||||
|
||||
private fun applyOrientationSettings() {
|
||||
val orientationOption = IntSetting.ORIENTATION_OPTION.int
|
||||
screenAdjustmentUtil.changeActivityOrientation(orientationOption)
|
||||
}
|
||||
|
||||
// Gets button presses
|
||||
@Suppress("DEPRECATION")
|
||||
@SuppressLint("GestureBackNavigation")
|
||||
|
|
|
@ -4,16 +4,21 @@
|
|||
|
||||
package io.github.lime3ds.android.display
|
||||
import android.view.WindowManager
|
||||
import android.content.Context
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.app.Activity
|
||||
import io.github.lime3ds.android.NativeLibrary
|
||||
import io.github.lime3ds.android.features.settings.model.BooleanSetting
|
||||
import io.github.lime3ds.android.features.settings.model.IntSetting
|
||||
import io.github.lime3ds.android.features.settings.model.Settings
|
||||
import io.github.lime3ds.android.features.settings.utils.SettingsFile
|
||||
import io.github.lime3ds.android.utils.EmulationMenuSettings
|
||||
import io.github.lime3ds.android.R
|
||||
|
||||
class ScreenAdjustmentUtil(
|
||||
private val context: Context,
|
||||
private val windowManager: WindowManager,
|
||||
private val settings: Settings
|
||||
private val settings: Settings,
|
||||
) {
|
||||
fun swapScreen() {
|
||||
val isEnabled = !EmulationMenuSettings.swapScreens
|
||||
|
@ -26,21 +31,20 @@ class ScreenAdjustmentUtil(
|
|||
settings.saveSetting(BooleanSetting.SWAP_SCREEN, SettingsFile.FILE_NAME_CONFIG)
|
||||
}
|
||||
fun cycleLayouts() {
|
||||
// TODO: figure out how to pull these from R.array
|
||||
val landscape_values = intArrayOf(2,1,3,4,0,5);
|
||||
val portrait_values = intArrayOf(0,1);
|
||||
if (NativeLibrary.isPortraitMode) {
|
||||
val current_layout = IntSetting.PORTRAIT_SCREEN_LAYOUT.int
|
||||
val pos = portrait_values.indexOf(current_layout)
|
||||
val layout_option = portrait_values[(pos + 1) % portrait_values.size]
|
||||
changePortraitOrientation(layout_option)
|
||||
} else {
|
||||
val current_layout = IntSetting.SCREEN_LAYOUT.int
|
||||
val pos = landscape_values.indexOf(current_layout)
|
||||
val layout_option = landscape_values[(pos + 1) % landscape_values.size]
|
||||
changeScreenOrientation(layout_option)
|
||||
}
|
||||
val landscapeValues = context.resources.getIntArray(R.array.landscapeValues)
|
||||
val portraitValues = context.resources.getIntArray(R.array.portraitValues)
|
||||
|
||||
if (NativeLibrary.isPortraitMode) {
|
||||
val currentLayout = IntSetting.PORTRAIT_SCREEN_LAYOUT.int
|
||||
val pos = portraitValues.indexOf(currentLayout)
|
||||
val layoutOption = portraitValues[(pos + 1) % portraitValues.size]
|
||||
changePortraitOrientation(layoutOption)
|
||||
} else {
|
||||
val currentLayout = IntSetting.SCREEN_LAYOUT.int
|
||||
val pos = landscapeValues.indexOf(currentLayout)
|
||||
val layoutOption = landscapeValues[(pos + 1) % landscapeValues.size]
|
||||
changeScreenOrientation(layoutOption)
|
||||
}
|
||||
}
|
||||
|
||||
fun changePortraitOrientation(layoutOption: Int) {
|
||||
|
@ -56,4 +60,11 @@ class ScreenAdjustmentUtil(
|
|||
NativeLibrary.reloadSettings()
|
||||
NativeLibrary.updateFramebuffer(NativeLibrary.isPortraitMode)
|
||||
}
|
||||
|
||||
fun changeActivityOrientation(orientationOption: Int) {
|
||||
val activity = context as? Activity ?: return
|
||||
IntSetting.ORIENTATION_OPTION.int = orientationOption
|
||||
settings.saveSetting(IntSetting.ORIENTATION_OPTION, SettingsFile.FILE_NAME_CONFIG)
|
||||
activity.requestedOrientation = orientationOption
|
||||
}
|
||||
}
|
||||
|
|
|
@ -60,8 +60,8 @@ enum class IntSetting(
|
|||
TEXTURE_FILTER("texture_filter", Settings.SECTION_RENDERER, 0),
|
||||
USE_FRAME_LIMIT("use_frame_limit", Settings.SECTION_RENDERER, 1),
|
||||
DELAY_RENDER_THREAD_US("delay_game_render_thread_us", Settings.SECTION_RENDERER, 0),
|
||||
USE_ARTIC_BASE_CONTROLLER("use_artic_base_controller", Settings.SECTION_CONTROLS, 0);
|
||||
|
||||
USE_ARTIC_BASE_CONTROLLER("use_artic_base_controller", Settings.SECTION_CONTROLS, 0),
|
||||
ORIENTATION_OPTION("screen_orientation", Settings.SECTION_LAYOUT, 2);
|
||||
override var int: Int = defaultValue
|
||||
|
||||
override val valueAsString: String
|
||||
|
|
|
@ -905,6 +905,17 @@ class SettingsFragmentPresenter(private val fragmentView: SettingsFragmentView)
|
|||
private fun addLayoutSettings(sl: ArrayList<SettingsItem>) {
|
||||
settingsActivity.setToolbarTitle(settingsActivity.getString(R.string.preferences_layout))
|
||||
sl.apply {
|
||||
add(
|
||||
SingleChoiceSetting(
|
||||
IntSetting.ORIENTATION_OPTION,
|
||||
R.string.layout_screen_orientation,
|
||||
0,
|
||||
R.array.screenOrientations,
|
||||
R.array.screenOrientationValues,
|
||||
IntSetting.ORIENTATION_OPTION.key,
|
||||
IntSetting.ORIENTATION_OPTION.defaultValue
|
||||
)
|
||||
)
|
||||
add(
|
||||
SingleChoiceSetting(
|
||||
IntSetting.SCREEN_LAYOUT,
|
||||
|
|
|
@ -146,8 +146,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback, Choreographer.Fram
|
|||
retainInstance = true
|
||||
emulationState = EmulationState(game.path)
|
||||
emulationActivity = requireActivity() as EmulationActivity
|
||||
screenAdjustmentUtil =
|
||||
ScreenAdjustmentUtil(emulationActivity.windowManager, settingsViewModel.settings)
|
||||
screenAdjustmentUtil = ScreenAdjustmentUtil(requireContext(), requireActivity().windowManager, settingsViewModel.settings)
|
||||
EmulationLifecycleUtil.addShutdownHook(hook = { emulationState.stop() })
|
||||
EmulationLifecycleUtil.addPauseResumeHook(hook = { togglePause() })
|
||||
}
|
||||
|
|
|
@ -202,6 +202,14 @@ custom_bottom_y =
|
|||
custom_bottom_width =
|
||||
custom_bottom_height =
|
||||
|
||||
# Orientation option for the emulator
|
||||
# 2 (default): Automatic
|
||||
# 0: Landscape
|
||||
# 8: Landscape (Flipped)
|
||||
# 1: Portrait
|
||||
# 9: Portrait (Flipped)
|
||||
screen_orientation =
|
||||
|
||||
# Layout for the portrait mode
|
||||
# 0 (default): Top and bottom screens at top, full width
|
||||
# 1: Custom Layout
|
||||
|
|
|
@ -530,4 +530,32 @@
|
|||
<item>12</item>
|
||||
</integer-array>
|
||||
|
||||
<integer-array name="landscapeValues">
|
||||
<item>2</item>
|
||||
<item>1</item>
|
||||
<item>3</item>
|
||||
<item>4</item>
|
||||
<item>0</item>
|
||||
<item>5</item>
|
||||
</integer-array>
|
||||
<integer-array name="portraitValues">
|
||||
<item>0</item>
|
||||
<item>1</item>
|
||||
</integer-array>
|
||||
|
||||
<string-array name="screenOrientations">
|
||||
<item>@string/layout_screen_orientation_auto_sensor</item>
|
||||
<item>@string/layout_screen_orientation_landscape</item>
|
||||
<item>@string/layout_screen_orientation_landscape_reverse</item>
|
||||
<item>@string/layout_screen_orientation_portrait</item>
|
||||
<item>@string/layout_screen_orientation_portrait_reverse</item>
|
||||
</string-array>
|
||||
<integer-array name="screenOrientationValues">
|
||||
<item>2</item>
|
||||
<item>0</item>
|
||||
<item>8</item>
|
||||
<item>1</item>
|
||||
<item>9</item>
|
||||
</integer-array>
|
||||
|
||||
</resources>
|
||||
|
|
|
@ -289,6 +289,14 @@
|
|||
<string name="audio_input_type">Audio Input Device</string>
|
||||
<string name="sound_output_mode">Sound Output Mode</string>
|
||||
|
||||
<!-- Layout settings strings -->
|
||||
<string name="layout_screen_orientation">Screen Orientation</string>
|
||||
<string name="layout_screen_orientation_auto_sensor">Automatic</string>
|
||||
<string name="layout_screen_orientation_landscape">Landscape</string>
|
||||
<string name="layout_screen_orientation_landscape_reverse">Reverse Landscape</string>
|
||||
<string name="layout_screen_orientation_portrait">Portrait</string>
|
||||
<string name="layout_screen_orientation_portrait_reverse">Reverse Portrait</string>
|
||||
|
||||
<!-- Miscellaneous -->
|
||||
<string name="clear">Clear</string>
|
||||
<string name="slider_default">Default</string>
|
||||
|
@ -336,6 +344,7 @@
|
|||
<string name="preferences_debug">Debug</string>
|
||||
<string name="preferences_theme">Theme and Color</string>
|
||||
<string name="preferences_layout">Layout</string>
|
||||
|
||||
<!-- ROM loading errors -->
|
||||
<string name="loader_error_encrypted">Your ROM is Encrypted</string>
|
||||
<string name="loader_error_invalid_format">Invalid ROM format</string>
|
||||
|
|
Loading…
Reference in a new issue