mirror of
https://github.com/Takiiiiiiii/strato.git
synced 2025-07-17 08:46:39 +00:00
Reposition overlays to bottom when active
This commit is contained in:
committed by
Niccolò Betto
parent
454bd94daa
commit
27200bd5a9
@ -16,15 +16,16 @@ import android.content.IntentFilter
|
||||
import android.content.pm.ActivityInfo
|
||||
import android.content.res.AssetManager
|
||||
import android.content.res.Configuration
|
||||
import android.content.res.Resources
|
||||
import android.graphics.PointF
|
||||
import android.graphics.drawable.Icon
|
||||
import android.hardware.display.DisplayManager
|
||||
import android.net.DhcpInfo
|
||||
import android.net.wifi.WifiManager
|
||||
import android.os.*
|
||||
import android.util.DisplayMetrics
|
||||
import android.util.Log
|
||||
import android.util.Rational
|
||||
import android.util.TypedValue
|
||||
import android.view.*
|
||||
import android.widget.Toast
|
||||
import androidx.activity.OnBackPressedCallback
|
||||
@ -33,6 +34,7 @@ import androidx.core.content.getSystemService
|
||||
import androidx.core.view.isGone
|
||||
import androidx.core.view.isInvisible
|
||||
import androidx.core.view.updateMargins
|
||||
import androidx.core.view.updatePadding
|
||||
import androidx.fragment.app.FragmentTransaction
|
||||
import androidx.lifecycle.Lifecycle
|
||||
import androidx.lifecycle.lifecycleScope
|
||||
@ -69,6 +71,8 @@ import kotlin.math.abs
|
||||
private const val ActionPause = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_PAUSE"
|
||||
private const val ActionMute = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_MUTE"
|
||||
|
||||
private val Number.toPx get() = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, this.toFloat(), Resources.getSystem().displayMetrics).toInt()
|
||||
|
||||
@AndroidEntryPoint
|
||||
class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTouchListener, DisplayManager.DisplayListener {
|
||||
companion object {
|
||||
@ -507,18 +511,26 @@ 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 (!emulationSettings.enableFoldableLayout) return
|
||||
val isFolding = (newLayoutInfo.displayFeatures.find { it is FoldingFeature } as? FoldingFeature)?.let {
|
||||
if (it.isSeparating) {
|
||||
requestedOrientation = ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED
|
||||
if (it.orientation == FoldingFeature.Orientation.HORIZONTAL)
|
||||
if (it.orientation == FoldingFeature.Orientation.HORIZONTAL) {
|
||||
binding.onScreenGameView.layoutParams.height = it.bounds.top
|
||||
binding.controllerViewContainer.layoutParams.height = it.bounds.bottom - 48.toPx
|
||||
binding.controllerViewContainer.updatePadding(0, 0, 0, 24.toPx)
|
||||
}
|
||||
}
|
||||
it.isSeparating
|
||||
} ?: false
|
||||
if (!isFolding) {
|
||||
binding.onScreenGameView.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
binding.controllerViewContainer.updatePadding(0, 0, 0, 0)
|
||||
binding.controllerViewContainer.layoutParams.height = ViewGroup.LayoutParams.MATCH_PARENT
|
||||
requestedOrientation = emulationSettings.orientation
|
||||
}
|
||||
binding.onScreenGameView.requestLayout()
|
||||
binding.controllerViewContainer.requestLayout()
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -40,7 +40,7 @@ class EmulationSettings private constructor(context : Context, prefName : String
|
||||
var orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE, prefName = prefName)
|
||||
var aspectRatio by sharedPreferences(context, 0, prefName = prefName)
|
||||
var respectDisplayCutout by sharedPreferences(context, false, prefName = prefName)
|
||||
var supportFoldableScreen by sharedPreferences(context, false, prefName = prefName)
|
||||
var enableFoldableLayout by sharedPreferences(context, false, prefName = prefName)
|
||||
|
||||
// GPU
|
||||
var gpuDriver by sharedPreferences(context, SYSTEM_GPU_DRIVER, prefName = prefName)
|
||||
|
@ -11,12 +11,19 @@ import android.view.View
|
||||
import androidx.preference.Preference
|
||||
import androidx.preference.PreferenceCategory
|
||||
import androidx.preference.PreferenceFragmentCompat
|
||||
import androidx.preference.SwitchPreferenceCompat
|
||||
import androidx.preference.TwoStatePreference
|
||||
import androidx.window.layout.FoldingFeature
|
||||
import androidx.window.layout.WindowInfoTracker
|
||||
import emu.skyline.BuildConfig
|
||||
import emu.skyline.MainActivity
|
||||
import emu.skyline.R
|
||||
import emu.skyline.utils.GpuDriverHelper
|
||||
import emu.skyline.utils.WindowInsetsHelper
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.launch
|
||||
import kotlinx.coroutines.withContext
|
||||
|
||||
/**
|
||||
* This fragment is used to display the global preferences
|
||||
@ -44,6 +51,14 @@ class GlobalSettingsFragment : PreferenceFragmentCompat() {
|
||||
true
|
||||
}
|
||||
|
||||
CoroutineScope(Dispatchers.IO).launch {
|
||||
WindowInfoTracker.getOrCreate(requireContext()).windowLayoutInfo(requireActivity()).collect { newLayoutInfo ->
|
||||
withContext(Dispatchers.Main) {
|
||||
findPreference<SwitchPreferenceCompat>("enable_foldable_layout")?.isVisible = newLayoutInfo.displayFeatures.find { it is FoldingFeature } != null
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Uncheck `disable_frame_throttling` if `force_triple_buffering` gets disabled
|
||||
val disableFrameThrottlingPref = findPreference<TwoStatePreference>("disable_frame_throttling")!!
|
||||
findPreference<TwoStatePreference>("force_triple_buffering")?.setOnPreferenceChangeListener { _, newValue ->
|
||||
|
@ -21,47 +21,54 @@
|
||||
android:layout_gravity="center" />
|
||||
</FrameLayout>
|
||||
|
||||
<emu.skyline.input.onscreen.OnScreenControllerView
|
||||
android:id="@+id/on_screen_controller_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/perf_stats"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|left"
|
||||
android:layout_marginLeft="@dimen/onScreenItemHorizontalMargin"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textColor="@color/colorPerfStatsPrimary"
|
||||
tools:text="60 FPS\n16.6±0.10ms" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/on_screen_pause_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|right"
|
||||
android:layout_marginRight="@dimen/onScreenItemHorizontalMargin"
|
||||
android:background="?android:attr/actionBarItemBackground"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_pause"
|
||||
app:tint="#40FFFFFF"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/on_screen_controller_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:layout_marginRight="@dimen/onScreenItemHorizontalMargin"
|
||||
android:background="?android:attr/actionBarItemBackground"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_show"
|
||||
app:tint="#40FFFFFF"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/emulation_fragment"
|
||||
android:id="@+id/controller_view_container"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
android:layout_height="match_parent"
|
||||
android:layout_gravity="bottom">
|
||||
|
||||
<emu.skyline.input.onscreen.OnScreenControllerView
|
||||
android:id="@+id/on_screen_controller_view"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
|
||||
<TextView
|
||||
android:id="@+id/perf_stats"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|left"
|
||||
android:layout_marginLeft="@dimen/onScreenItemHorizontalMargin"
|
||||
android:layout_marginTop="5dp"
|
||||
android:textColor="@color/colorPerfStatsPrimary"
|
||||
tools:text="60 FPS\n16.6±0.10ms" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/on_screen_pause_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="top|right"
|
||||
android:layout_marginRight="@dimen/onScreenItemHorizontalMargin"
|
||||
android:background="?android:attr/actionBarItemBackground"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_pause"
|
||||
app:tint="#40FFFFFF"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<ImageButton
|
||||
android:id="@+id/on_screen_controller_toggle"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="bottom|right"
|
||||
android:layout_marginRight="@dimen/onScreenItemHorizontalMargin"
|
||||
android:background="?android:attr/actionBarItemBackground"
|
||||
android:padding="8dp"
|
||||
android:src="@drawable/ic_show"
|
||||
app:tint="#40FFFFFF"
|
||||
tools:ignore="ContentDescription" />
|
||||
|
||||
<FrameLayout
|
||||
android:id="@+id/emulation_fragment"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="match_parent" />
|
||||
</FrameLayout>
|
||||
</FrameLayout>
|
||||
|
@ -96,9 +96,9 @@
|
||||
<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_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>
|
||||
<string name="enable_foldable_layout">Enable Foldable Layout</string>
|
||||
<string name="enable_foldable_layout_enabled">Folded devices will display game and controller separately</string>
|
||||
<string name="enable_foldable_layout_disabled">Display controller over games even when device is folded</string>
|
||||
<!-- Settings - Audio -->
|
||||
<string name="audio">Audio</string>
|
||||
<string name="disable_audio_output">Disable Audio Output</string>
|
||||
|
@ -74,10 +74,11 @@
|
||||
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" />
|
||||
android:summaryOff="@string/enable_foldable_layout_disabled"
|
||||
android:summaryOn="@string/enable_foldable_layout_enabled"
|
||||
app:key="enable_foldable_layout"
|
||||
app:title="@string/enable_foldable_layout"
|
||||
app:isPreferenceVisible="false"/>
|
||||
</PreferenceCategory>
|
||||
<PreferenceCategory
|
||||
android:key="category_audio"
|
||||
|
Reference in New Issue
Block a user