This commit is contained in:
Andrey 2023-05-15 14:13:47 +08:00 committed by GitHub
commit f0de62aa2e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 58 additions and 4 deletions

View File

@ -172,6 +172,7 @@ dependencies {
implementation 'com.google.android.material:material:1.8.0' implementation 'com.google.android.material:material:1.8.0'
implementation 'androidx.documentfile:documentfile:1.0.1' implementation 'androidx.documentfile:documentfile:1.0.1'
implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0' implementation 'androidx.swiperefreshlayout:swiperefreshlayout:1.1.0'
implementation 'androidx.window:window:1.0.0'
implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1" implementation "androidx.lifecycle:lifecycle-viewmodel-ktx:2.5.1"
implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1" implementation "androidx.lifecycle:lifecycle-livedata-ktx:2.5.1"
implementation 'androidx.fragment:fragment-ktx:1.5.5' implementation 'androidx.fragment:fragment-ktx:1.5.5'

View File

@ -13,12 +13,14 @@ import android.content.BroadcastReceiver
import android.content.Context import android.content.Context
import android.content.Intent import android.content.Intent
import android.content.IntentFilter import android.content.IntentFilter
import android.content.pm.ActivityInfo
import android.content.res.AssetManager import android.content.res.AssetManager
import android.content.res.Configuration import android.content.res.Configuration
import android.graphics.PointF import android.graphics.PointF
import android.graphics.drawable.Icon import android.graphics.drawable.Icon
import android.hardware.display.DisplayManager import android.hardware.display.DisplayManager
import android.os.* import android.os.*
import android.util.DisplayMetrics
import android.util.Log import android.util.Log
import android.util.Rational import android.util.Rational
import android.view.* import android.view.*
@ -30,6 +32,12 @@ import androidx.core.view.isGone
import androidx.core.view.isInvisible import androidx.core.view.isInvisible
import androidx.core.view.updateMargins import androidx.core.view.updateMargins
import androidx.fragment.app.FragmentTransaction import androidx.fragment.app.FragmentTransaction
import androidx.lifecycle.Lifecycle
import androidx.lifecycle.lifecycleScope
import androidx.lifecycle.repeatOnLifecycle
import androidx.window.layout.FoldingFeature
import androidx.window.layout.WindowInfoTracker
import androidx.window.layout.WindowLayoutInfo
import com.google.android.material.dialog.MaterialAlertDialogBuilder import com.google.android.material.dialog.MaterialAlertDialogBuilder
import dagger.hilt.android.AndroidEntryPoint import dagger.hilt.android.AndroidEntryPoint
import emu.skyline.BuildConfig import emu.skyline.BuildConfig
@ -47,12 +55,15 @@ import emu.skyline.settings.NativeSettings
import emu.skyline.utils.ByteBufferSerializable import emu.skyline.utils.ByteBufferSerializable
import emu.skyline.utils.GpuDriverHelper import emu.skyline.utils.GpuDriverHelper
import emu.skyline.utils.serializable import emu.skyline.utils.serializable
import kotlinx.coroutines.Dispatchers
import kotlinx.coroutines.launch
import java.nio.ByteBuffer import java.nio.ByteBuffer
import java.nio.ByteOrder import java.nio.ByteOrder
import java.util.concurrent.FutureTask import java.util.concurrent.FutureTask
import javax.inject.Inject import javax.inject.Inject
import kotlin.math.abs import kotlin.math.abs
private const val ActionPause = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_PAUSE" private const val ActionPause = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_PAUSE"
private const val ActionMute = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_MUTE" private const val ActionMute = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_MUTE"
@ -305,6 +316,14 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
} }
) )
lifecycleScope.launch(Dispatchers.Main) {
lifecycle.repeatOnLifecycle(Lifecycle.State.STARTED) {
WindowInfoTracker.getOrCreate(this@EmulationActivity)
.windowLayoutInfo(this@EmulationActivity)
.collect { updateCurrentLayout(it) }
}
}
if (emulationSettings.perfStats) { if (emulationSettings.perfStats) {
if (emulationSettings.disableFrameThrottling) if (emulationSettings.disableFrameThrottling)
binding.perfStats.setTextColor(getColor(R.color.colorPerfStatsSecondary)) binding.perfStats.setTextColor(getColor(R.color.colorPerfStatsSecondary))
@ -481,6 +500,24 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
} }
} }
/**
* Updating the layout depending on type and state of device
*/
private fun updateCurrentLayout(newLayoutInfo: WindowLayoutInfo) {
if (!emulationSettings.supportFoldableScreen) return
binding.onScreenGameView.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
requestedOrientation = emulationSettings.orientation
val foldingFeature = newLayoutInfo.displayFeatures.find { it is FoldingFeature }
(foldingFeature as? FoldingFeature)?.let {
if (it.isSeparating) {
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
if (it.orientation == FoldingFeature.Orientation.HORIZONTAL)
binding.onScreenGameView.layoutParams.height = it.bounds.top
}
}
binding.onScreenGameView.requestLayout()
}
/** /**
* Stop the currently executing ROM and replace it with the one specified in the new intent * Stop the currently executing ROM and replace it with the one specified in the new intent
*/ */

View File

@ -39,6 +39,7 @@ class EmulationSettings private constructor(context : Context, prefName : String
var orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, prefName = prefName) var orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, prefName = prefName)
var aspectRatio by sharedPreferences(context, 0, prefName = prefName) var aspectRatio by sharedPreferences(context, 0, prefName = prefName)
var respectDisplayCutout by sharedPreferences(context, false, prefName = prefName) var respectDisplayCutout by sharedPreferences(context, false, prefName = prefName)
var supportFoldableScreen by sharedPreferences(context, false, prefName = prefName)
// GPU // GPU
var gpuDriver by sharedPreferences(context, SYSTEM_GPU_DRIVER, prefName = prefName) var gpuDriver by sharedPreferences(context, SYSTEM_GPU_DRIVER, prefName = prefName)

View File

@ -9,11 +9,17 @@
tools:context=".EmulationActivity" tools:context=".EmulationActivity"
tools:ignore="RtlHardcoded"> tools:ignore="RtlHardcoded">
<emu.skyline.views.FixedRatioSurfaceView <FrameLayout
android:id="@+id/game_view" android:id="@+id/on_screen_game_view"
android:layout_width="match_parent" android:layout_width="match_parent"
android:layout_height="match_parent" android:layout_height="match_parent">
android:layout_gravity="center" />
<emu.skyline.views.FixedRatioSurfaceView
android:id="@+id/game_view"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center" />
</FrameLayout>
<emu.skyline.input.onscreen.OnScreenControllerView <emu.skyline.input.onscreen.OnScreenControllerView
android:id="@+id/on_screen_controller_view" android:id="@+id/on_screen_controller_view"

View File

@ -93,6 +93,9 @@
<string name="respect_display_cutout">Respect Display Cutout</string> <string name="respect_display_cutout">Respect Display Cutout</string>
<string name="respect_display_cutout_enabled">Do not draw UI elements in the cutout area</string> <string name="respect_display_cutout_enabled">Do not draw UI elements in the cutout area</string>
<string name="respect_display_cutout_disabled">Allow UI elements to be drawn in the cutout area</string> <string name="respect_display_cutout_disabled">Allow UI elements to be drawn in the cutout area</string>
<string name="support_foldable_screen">Support Foldable Screens</string>
<string name="support_foldable_screen_enabled">Folded devices will display game and controller separately</string>
<string name="support_foldable_screen_disabled">Display controller over games even when device is folded</string>
<!-- Settings - Audio --> <!-- Settings - Audio -->
<string name="audio">Audio</string> <string name="audio">Audio</string>
<string name="disable_audio_output">Disable Audio Output</string> <string name="disable_audio_output">Disable Audio Output</string>

View File

@ -67,6 +67,12 @@
android:summaryOn="@string/respect_display_cutout_enabled" android:summaryOn="@string/respect_display_cutout_enabled"
app:key="respect_display_cutout" app:key="respect_display_cutout"
app:title="@string/respect_display_cutout" /> app:title="@string/respect_display_cutout" />
<SwitchPreferenceCompat
android:defaultValue="true"
android:summaryOff="@string/support_foldable_screen_disabled"
android:summaryOn="@string/support_foldable_screen_enabled"
app:key="support_foldable_screen"
app:title="@string/support_foldable_screen" />
</PreferenceCategory> </PreferenceCategory>
<PreferenceCategory <PreferenceCategory
android:key="category_audio" android:key="category_audio"