diff options
Diffstat (limited to 'src')
4 files changed, 33 insertions, 46 deletions
diff --git a/src/android/app/src/main/AndroidManifest.xml b/src/android/app/src/main/AndroidManifest.xml index 36e2dac98..933244140 100644 --- a/src/android/app/src/main/AndroidManifest.xml +++ b/src/android/app/src/main/AndroidManifest.xml | |||
| @@ -56,7 +56,6 @@ SPDX-License-Identifier: GPL-3.0-or-later | |||
| 56 | android:name="org.yuzu.yuzu_emu.activities.EmulationActivity" | 56 | android:name="org.yuzu.yuzu_emu.activities.EmulationActivity" |
| 57 | android:theme="@style/Theme.Yuzu.Main" | 57 | android:theme="@style/Theme.Yuzu.Main" |
| 58 | android:launchMode="singleTop" | 58 | android:launchMode="singleTop" |
| 59 | android:screenOrientation="userLandscape" | ||
| 60 | android:supportsPictureInPicture="true" | 59 | android:supportsPictureInPicture="true" |
| 61 | android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|uiMode" | 60 | android:configChanges="orientation|screenSize|smallestScreenSize|screenLayout|uiMode" |
| 62 | android:exported="true"> | 61 | android:exported="true"> |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt index a5af5a7ae..e6fffc832 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/features/settings/ui/SettingsActivity.kt | |||
| @@ -11,7 +11,6 @@ import android.view.View | |||
| 11 | import android.view.ViewGroup.MarginLayoutParams | 11 | import android.view.ViewGroup.MarginLayoutParams |
| 12 | import android.widget.Toast | 12 | import android.widget.Toast |
| 13 | import androidx.activity.OnBackPressedCallback | 13 | import androidx.activity.OnBackPressedCallback |
| 14 | import androidx.activity.result.ActivityResultLauncher | ||
| 15 | import androidx.activity.viewModels | 14 | import androidx.activity.viewModels |
| 16 | import androidx.appcompat.app.AppCompatActivity | 15 | import androidx.appcompat.app.AppCompatActivity |
| 17 | import androidx.core.view.ViewCompat | 16 | import androidx.core.view.ViewCompat |
| @@ -246,17 +245,5 @@ class SettingsActivity : AppCompatActivity(), SettingsActivityView { | |||
| 246 | settings.putExtra(ARG_GAME_ID, gameId) | 245 | settings.putExtra(ARG_GAME_ID, gameId) |
| 247 | context.startActivity(settings) | 246 | context.startActivity(settings) |
| 248 | } | 247 | } |
| 249 | |||
| 250 | fun launch( | ||
| 251 | context: Context, | ||
| 252 | launcher: ActivityResultLauncher<Intent>, | ||
| 253 | menuTag: String?, | ||
| 254 | gameId: String? | ||
| 255 | ) { | ||
| 256 | val settings = Intent(context, SettingsActivity::class.java) | ||
| 257 | settings.putExtra(ARG_MENU_TAG, menuTag) | ||
| 258 | settings.putExtra(ARG_GAME_ID, gameId) | ||
| 259 | launcher.launch(settings) | ||
| 260 | } | ||
| 261 | } | 248 | } |
| 262 | } | 249 | } |
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt index 25b9d4018..09e93a017 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/fragments/EmulationFragment.kt | |||
| @@ -7,7 +7,6 @@ import android.annotation.SuppressLint | |||
| 7 | import android.app.AlertDialog | 7 | import android.app.AlertDialog |
| 8 | import android.content.Context | 8 | import android.content.Context |
| 9 | import android.content.DialogInterface | 9 | import android.content.DialogInterface |
| 10 | import android.content.Intent | ||
| 11 | import android.content.SharedPreferences | 10 | import android.content.SharedPreferences |
| 12 | import android.content.pm.ActivityInfo | 11 | import android.content.pm.ActivityInfo |
| 13 | import android.content.res.Configuration | 12 | import android.content.res.Configuration |
| @@ -19,8 +18,6 @@ import android.util.Rational | |||
| 19 | import android.view.* | 18 | import android.view.* |
| 20 | import android.widget.TextView | 19 | import android.widget.TextView |
| 21 | import androidx.activity.OnBackPressedCallback | 20 | import androidx.activity.OnBackPressedCallback |
| 22 | import androidx.activity.result.ActivityResultLauncher | ||
| 23 | import androidx.activity.result.contract.ActivityResultContracts | ||
| 24 | import androidx.appcompat.widget.PopupMenu | 21 | import androidx.appcompat.widget.PopupMenu |
| 25 | import androidx.core.content.res.ResourcesCompat | 22 | import androidx.core.content.res.ResourcesCompat |
| 26 | import androidx.core.graphics.Insets | 23 | import androidx.core.graphics.Insets |
| @@ -66,8 +63,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 66 | 63 | ||
| 67 | private var isInFoldableLayout = false | 64 | private var isInFoldableLayout = false |
| 68 | 65 | ||
| 69 | private lateinit var onReturnFromSettings: ActivityResultLauncher<Intent> | ||
| 70 | |||
| 71 | override fun onAttach(context: Context) { | 66 | override fun onAttach(context: Context) { |
| 72 | super.onAttach(context) | 67 | super.onAttach(context) |
| 73 | if (context is EmulationActivity) { | 68 | if (context is EmulationActivity) { |
| @@ -81,11 +76,6 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 81 | .collect { updateFoldableLayout(context, it) } | 76 | .collect { updateFoldableLayout(context, it) } |
| 82 | } | 77 | } |
| 83 | } | 78 | } |
| 84 | |||
| 85 | onReturnFromSettings = context.activityResultRegistry.register( | ||
| 86 | "SettingsResult", | ||
| 87 | ActivityResultContracts.StartActivityForResult() | ||
| 88 | ) { updateScreenLayout() } | ||
| 89 | } else { | 79 | } else { |
| 90 | throw IllegalStateException("EmulationFragment must have EmulationActivity parent") | 80 | throw IllegalStateException("EmulationFragment must have EmulationActivity parent") |
| 91 | } | 81 | } |
| @@ -149,12 +139,7 @@ class EmulationFragment : Fragment(), SurfaceHolder.Callback { | |||
| 149 | } | 139 | } |
| 150 | 140 | ||
| 151 | R.id.menu_settings -> { | 141 | R.id.menu_settings -> { |
| 152 | SettingsActivity.launch( | 142 | SettingsActivity.launch(requireContext(), SettingsFile.FILE_NAME_CONFIG, "") |
| 153 | requireContext(), | ||
| 154 | onReturnFromSettings, | ||
| 155 | SettingsFile.FILE_NAME_CONFIG, | ||
| 156 | "" | ||
| 157 | ) | ||
| 158 | true | 143 | true |
| 159 | } | 144 | } |
| 160 | 145 | ||
diff --git a/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/FixedRatioSurfaceView.kt b/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/FixedRatioSurfaceView.kt index 685ccaa76..2f0868c63 100644 --- a/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/FixedRatioSurfaceView.kt +++ b/src/android/app/src/main/java/org/yuzu/yuzu_emu/views/FixedRatioSurfaceView.kt | |||
| @@ -7,7 +7,6 @@ import android.content.Context | |||
| 7 | import android.util.AttributeSet | 7 | import android.util.AttributeSet |
| 8 | import android.util.Rational | 8 | import android.util.Rational |
| 9 | import android.view.SurfaceView | 9 | import android.view.SurfaceView |
| 10 | import kotlin.math.roundToInt | ||
| 11 | 10 | ||
| 12 | class FixedRatioSurfaceView @JvmOverloads constructor( | 11 | class FixedRatioSurfaceView @JvmOverloads constructor( |
| 13 | context: Context, | 12 | context: Context, |
| @@ -22,27 +21,44 @@ class FixedRatioSurfaceView @JvmOverloads constructor( | |||
| 22 | */ | 21 | */ |
| 23 | fun setAspectRatio(ratio: Rational?) { | 22 | fun setAspectRatio(ratio: Rational?) { |
| 24 | aspectRatio = ratio?.toFloat() ?: 0f | 23 | aspectRatio = ratio?.toFloat() ?: 0f |
| 24 | requestLayout() | ||
| 25 | } | 25 | } |
| 26 | 26 | ||
| 27 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { | 27 | override fun onMeasure(widthMeasureSpec: Int, heightMeasureSpec: Int) { |
| 28 | super.onMeasure(widthMeasureSpec, heightMeasureSpec) | 28 | val displayWidth: Float = MeasureSpec.getSize(widthMeasureSpec).toFloat() |
| 29 | val width = MeasureSpec.getSize(widthMeasureSpec) | 29 | val displayHeight: Float = MeasureSpec.getSize(heightMeasureSpec).toFloat() |
| 30 | val height = MeasureSpec.getSize(heightMeasureSpec) | ||
| 31 | if (aspectRatio != 0f) { | 30 | if (aspectRatio != 0f) { |
| 32 | val newWidth: Int | 31 | val displayAspect = displayWidth / displayHeight |
| 33 | val newHeight: Int | 32 | if (displayAspect < aspectRatio) { |
| 34 | if (height * aspectRatio < width) { | 33 | // Max out width |
| 35 | newWidth = (height * aspectRatio).roundToInt() | 34 | val halfHeight = displayHeight / 2 |
| 36 | newHeight = height | 35 | val surfaceHeight = displayWidth / aspectRatio |
| 36 | val newTop: Float = halfHeight - (surfaceHeight / 2) | ||
| 37 | val newBottom: Float = halfHeight + (surfaceHeight / 2) | ||
| 38 | super.onMeasure( | ||
| 39 | widthMeasureSpec, | ||
| 40 | MeasureSpec.makeMeasureSpec( | ||
| 41 | newBottom.toInt() - newTop.toInt(), | ||
| 42 | MeasureSpec.EXACTLY | ||
| 43 | ) | ||
| 44 | ) | ||
| 45 | return | ||
| 37 | } else { | 46 | } else { |
| 38 | newWidth = width | 47 | // Max out height |
| 39 | newHeight = (width / aspectRatio).roundToInt() | 48 | val halfWidth = displayWidth / 2 |
| 49 | val surfaceWidth = displayHeight * aspectRatio | ||
| 50 | val newLeft: Float = halfWidth - (surfaceWidth / 2) | ||
| 51 | val newRight: Float = halfWidth + (surfaceWidth / 2) | ||
| 52 | super.onMeasure( | ||
| 53 | MeasureSpec.makeMeasureSpec( | ||
| 54 | newRight.toInt() - newLeft.toInt(), | ||
| 55 | MeasureSpec.EXACTLY | ||
| 56 | ), | ||
| 57 | heightMeasureSpec | ||
| 58 | ) | ||
| 59 | return | ||
| 40 | } | 60 | } |
| 41 | val left = (width - newWidth) / 2 | ||
| 42 | val top = (height - newHeight) / 2 | ||
| 43 | setLeftTopRightBottom(left, top, left + newWidth, top + newHeight) | ||
| 44 | } else { | ||
| 45 | setLeftTopRightBottom(0, 0, width, height) | ||
| 46 | } | 61 | } |
| 62 | super.onMeasure(widthMeasureSpec, heightMeasureSpec) | ||
| 47 | } | 63 | } |
| 48 | } | 64 | } |