mirror of
https://github.com/skyline-emu/skyline.git
synced 2025-01-15 07:27:54 +03:00
Add support for drawing inside the display cutout areas
This commit is contained in:
parent
6e929e6f6a
commit
08e24915d8
@ -17,6 +17,7 @@ import android.view.*
|
|||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.view.isGone
|
import androidx.core.view.isGone
|
||||||
import androidx.core.view.isInvisible
|
import androidx.core.view.isInvisible
|
||||||
|
import androidx.core.view.updateMargins
|
||||||
import dagger.hilt.android.AndroidEntryPoint
|
import dagger.hilt.android.AndroidEntryPoint
|
||||||
import emu.skyline.databinding.EmuActivityBinding
|
import emu.skyline.databinding.EmuActivityBinding
|
||||||
import emu.skyline.input.*
|
import emu.skyline.input.*
|
||||||
@ -232,15 +233,25 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
override fun onCreate(savedInstanceState : Bundle?) {
|
override fun onCreate(savedInstanceState : Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
requestedOrientation = settings.orientation
|
requestedOrientation = settings.orientation
|
||||||
|
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
// Android might not allow child views to overlap the system bars
|
||||||
|
// Override this behavior and force content to extend into the cutout area
|
||||||
|
window.setDecorFitsSystemWindows(false)
|
||||||
|
|
||||||
window.insetsController?.let {
|
window.insetsController?.let {
|
||||||
it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
it.hide(WindowInsets.Type.systemBars())
|
it.hide(WindowInsets.Type.systemBars())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (settings.respectDisplayCutout) {
|
||||||
|
binding.perfStats.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
|
||||||
|
binding.onScreenControllerToggle.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
|
||||||
|
}
|
||||||
|
|
||||||
binding.gameView.holder.addCallback(this)
|
binding.gameView.holder.addCallback(this)
|
||||||
|
|
||||||
binding.gameView.setAspectRatio(
|
binding.gameView.setAspectRatio(
|
||||||
@ -540,4 +551,17 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
val (major, minor, patch) = BuildConfig.VERSION_NAME.split('.').map { it.toUInt() }
|
val (major, minor, patch) = BuildConfig.VERSION_NAME.split('.').map { it.toUInt() }
|
||||||
return ((major shl 22) or (minor shl 12) or (patch)).toInt()
|
return ((major shl 22) or (minor shl 12) or (patch)).toInt()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val insetsOrMarginHandler = View.OnApplyWindowInsetsListener { view, insets ->
|
||||||
|
insets.displayCutout?.let {
|
||||||
|
val defaultHorizontalMargin = view.resources.getDimensionPixelSize(R.dimen.onScreenItemHorizontalMargin)
|
||||||
|
val left = if (it.safeInsetLeft == 0) defaultHorizontalMargin else it.safeInsetLeft
|
||||||
|
val right = if (it.safeInsetRight == 0) defaultHorizontalMargin else it.safeInsetRight
|
||||||
|
|
||||||
|
val params = view.layoutParams as ViewGroup.MarginLayoutParams
|
||||||
|
params.updateMargins(left = left, right = right)
|
||||||
|
view.layoutParams = params
|
||||||
|
}
|
||||||
|
insets
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,10 +7,7 @@ package emu.skyline.input.onscreen
|
|||||||
|
|
||||||
import android.os.Build
|
import android.os.Build
|
||||||
import android.os.Bundle
|
import android.os.Bundle
|
||||||
import android.view.LayoutInflater
|
import android.view.*
|
||||||
import android.view.View
|
|
||||||
import android.view.WindowInsets
|
|
||||||
import android.view.WindowInsetsController
|
|
||||||
import androidx.appcompat.app.AppCompatActivity
|
import androidx.appcompat.app.AppCompatActivity
|
||||||
import androidx.core.content.ContextCompat
|
import androidx.core.content.ContextCompat
|
||||||
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
import com.google.android.material.dialog.MaterialAlertDialogBuilder
|
||||||
@ -90,7 +87,20 @@ class OnScreenEditActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
override fun onCreate(savedInstanceState : Bundle?) {
|
override fun onCreate(savedInstanceState : Bundle?) {
|
||||||
super.onCreate(savedInstanceState)
|
super.onCreate(savedInstanceState)
|
||||||
|
window.attributes.layoutInDisplayCutoutMode = WindowManager.LayoutParams.LAYOUT_IN_DISPLAY_CUTOUT_MODE_SHORT_EDGES
|
||||||
setContentView(binding.root)
|
setContentView(binding.root)
|
||||||
|
|
||||||
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
||||||
|
// Android might not allow child views to overlap the system bars
|
||||||
|
// Override this behavior and force content to extend into the cutout area
|
||||||
|
window.setDecorFitsSystemWindows(false)
|
||||||
|
|
||||||
|
window.insetsController?.let {
|
||||||
|
it.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
||||||
|
it.hide(WindowInsets.Type.systemBars())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
binding.onScreenControllerView.recenterSticks = settings.onScreenControlRecenterSticks
|
binding.onScreenControllerView.recenterSticks = settings.onScreenControlRecenterSticks
|
||||||
|
|
||||||
actions.forEach { pair ->
|
actions.forEach { pair ->
|
||||||
@ -100,11 +110,6 @@ class OnScreenEditActivity : AppCompatActivity() {
|
|||||||
fabMapping[pair.first] = this
|
fabMapping[pair.first] = this
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.R) {
|
|
||||||
window.insetsController?.hide(WindowInsets.Type.navigationBars() or WindowInsets.Type.systemBars() or WindowInsets.Type.systemGestures() or WindowInsets.Type.statusBars())
|
|
||||||
window.insetsController?.systemBarsBehavior = WindowInsetsController.BEHAVIOR_SHOW_TRANSIENT_BARS_BY_SWIPE
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onResume() {
|
override fun onResume() {
|
||||||
|
@ -44,4 +44,6 @@ class Settings @Inject constructor(@ApplicationContext private val context : Con
|
|||||||
var systemLanguage by sharedPreferences(context, 1)
|
var systemLanguage by sharedPreferences(context, 1)
|
||||||
|
|
||||||
var orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
|
var orientation by sharedPreferences(context, ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE)
|
||||||
|
|
||||||
|
var respectDisplayCutout by sharedPreferences(context, false)
|
||||||
}
|
}
|
||||||
|
@ -4,9 +4,10 @@
|
|||||||
xmlns:tools="http://schemas.android.com/tools"
|
xmlns:tools="http://schemas.android.com/tools"
|
||||||
android:layout_width="match_parent"
|
android:layout_width="match_parent"
|
||||||
android:layout_height="match_parent"
|
android:layout_height="match_parent"
|
||||||
android:keepScreenOn="true"
|
|
||||||
android:background="@android:color/black"
|
android:background="@android:color/black"
|
||||||
tools:context=".EmulationActivity">
|
android:keepScreenOn="true"
|
||||||
|
tools:context=".EmulationActivity"
|
||||||
|
tools:ignore="RtlHardcoded">
|
||||||
|
|
||||||
<emu.skyline.views.FixedRatioSurfaceView
|
<emu.skyline.views.FixedRatioSurfaceView
|
||||||
android:id="@+id/game_view"
|
android:id="@+id/game_view"
|
||||||
@ -23,16 +24,18 @@
|
|||||||
android:id="@+id/perf_stats"
|
android:id="@+id/perf_stats"
|
||||||
android:layout_width="wrap_content"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:layout_marginStart="5dp"
|
android:layout_marginLeft="@dimen/onScreenItemHorizontalMargin"
|
||||||
android:layout_marginTop="5dp"
|
android:layout_marginTop="5dp"
|
||||||
android:textColor="#9fffff00" />
|
android:textColor="#9fffff00" />
|
||||||
|
|
||||||
<ImageButton
|
<ImageButton
|
||||||
android:id="@+id/on_screen_controller_toggle"
|
android:id="@+id/on_screen_controller_toggle"
|
||||||
android:layout_width="40dp"
|
android:layout_width="wrap_content"
|
||||||
android:layout_height="40dp"
|
android:layout_height="wrap_content"
|
||||||
android:layout_gravity="bottom|end"
|
android:layout_gravity="bottom|end"
|
||||||
android:background="?attr/selectableItemBackgroundBorderless"
|
android:layout_marginRight="@dimen/onScreenItemHorizontalMargin"
|
||||||
|
android:background="?android:attr/actionBarItemBackground"
|
||||||
|
android:padding="8dp"
|
||||||
android:src="@drawable/ic_show"
|
android:src="@drawable/ic_show"
|
||||||
app:tint="#40FFFFFF"
|
app:tint="#40FFFFFF"
|
||||||
tools:ignore="ContentDescription" />
|
tools:ignore="ContentDescription" />
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<resources>
|
<resources>
|
||||||
<dimen name="grid_padding">8dp</dimen>
|
<dimen name="grid_padding">8dp</dimen>
|
||||||
|
<dimen name="onScreenItemHorizontalMargin">10dp</dimen>
|
||||||
</resources>
|
</resources>
|
||||||
|
@ -63,6 +63,9 @@
|
|||||||
<string name="max_refresh_rate_enabled">Sets the display refresh rate as high as possible (Will break most games)</string>
|
<string name="max_refresh_rate_enabled">Sets the display refresh rate as high as possible (Will break most games)</string>
|
||||||
<string name="max_refresh_rate_disabled">Sets the display refresh rate to 60Hz</string>
|
<string name="max_refresh_rate_disabled">Sets the display refresh rate to 60Hz</string>
|
||||||
<string name="aspect_ratio">Aspect Ratio</string>
|
<string name="aspect_ratio">Aspect Ratio</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_disabled">Allow UI elements to be drawn in the cutout area</string>
|
||||||
<!-- Input -->
|
<!-- Input -->
|
||||||
<string name="input">Input</string>
|
<string name="input">Input</string>
|
||||||
<string name="osc">On-Screen Controls</string>
|
<string name="osc">On-Screen Controls</string>
|
||||||
|
@ -116,6 +116,12 @@
|
|||||||
app:key="aspect_ratio"
|
app:key="aspect_ratio"
|
||||||
app:title="@string/aspect_ratio"
|
app:title="@string/aspect_ratio"
|
||||||
app:useSimpleSummaryProvider="true" />
|
app:useSimpleSummaryProvider="true" />
|
||||||
|
<CheckBoxPreference
|
||||||
|
android:defaultValue="false"
|
||||||
|
android:summaryOff="@string/respect_display_cutout_disabled"
|
||||||
|
android:summaryOn="@string/respect_display_cutout_enabled"
|
||||||
|
app:key="respect_display_cutout"
|
||||||
|
app:title="@string/respect_display_cutout" />
|
||||||
</PreferenceCategory>
|
</PreferenceCategory>
|
||||||
<PreferenceCategory
|
<PreferenceCategory
|
||||||
android:key="category_input"
|
android:key="category_input"
|
||||||
|
Loading…
x
Reference in New Issue
Block a user