Add an emulator pause button to the OSC

This commit is contained in:
Abandoned Cart 2023-02-15 14:11:31 -05:00 committed by Billy Laws
parent 69e322b76b
commit bd9050f6c7
2 changed files with 37 additions and 0 deletions

View File

@ -91,6 +91,8 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
*/ */
private var desiredRefreshRate = 60f private var desiredRefreshRate = 60f
private var isEmulatorPaused = false
private lateinit var pictureInPictureParamsBuilder : PictureInPictureParams.Builder private lateinit var pictureInPictureParamsBuilder : PictureInPictureParams.Builder
private val pauseIntentAction = "$packageName.EMULATOR_PAUSE" private val pauseIntentAction = "$packageName.EMULATOR_PAUSE"
private val muteIntentAction = "$packageName.EMULATOR_MUTE" private val muteIntentAction = "$packageName.EMULATOR_MUTE"
@ -343,18 +345,37 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
setOnClickListener { binding.onScreenControllerView.isInvisible = !binding.onScreenControllerView.isInvisible } setOnClickListener { binding.onScreenControllerView.isInvisible = !binding.onScreenControllerView.isInvisible }
} }
binding.onScreenPauseToggle.apply {
isGone = binding.onScreenControllerView.isGone
setOnClickListener {
if (isEmulatorPaused) {
resumeEmulator()
binding.onScreenPauseToggle.setImageResource(R.drawable.ic_pause)
} else {
pauseEmulator()
binding.onScreenPauseToggle.setImageResource(R.drawable.ic_play)
}
}
}
executeApplication(intent!!) executeApplication(intent!!)
} }
@SuppressWarnings("WeakerAccess")
fun pauseEmulator() { fun pauseEmulator() {
if (isEmulatorPaused) return
setSurface(null) setSurface(null)
changeAudioStatus(false) changeAudioStatus(false)
isEmulatorPaused = true
} }
@SuppressWarnings("WeakerAccess")
fun resumeEmulator() { fun resumeEmulator() {
if (!isEmulatorPaused) return
gameSurface?.let { setSurface(it) } gameSurface?.let { setSurface(it) }
if (!emulationSettings.isAudioOutputDisabled) if (!emulationSettings.isAudioOutputDisabled)
changeAudioStatus(true) changeAudioStatus(true)
isEmulatorPaused = false
} }
override fun onPause() { override fun onPause() {
@ -414,6 +435,7 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
binding.onScreenControllerView.isGone = true binding.onScreenControllerView.isGone = true
binding.onScreenControllerToggle.isGone = true binding.onScreenControllerToggle.isGone = true
binding.onScreenPauseToggle.isGone = true
} else { } else {
try { try {
if (this::pictureInPictureReceiver.isInitialized) if (this::pictureInPictureReceiver.isInitialized)
@ -431,6 +453,9 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
binding.onScreenControllerToggle.apply { binding.onScreenControllerToggle.apply {
isGone = binding.onScreenControllerView.isGone isGone = binding.onScreenControllerView.isGone
} }
binding.onScreenPauseToggle.apply {
isGone = binding.onScreenControllerView.isGone
}
} }
} }

View File

@ -30,6 +30,18 @@
tools:text="60 FPS\n16.6±0.10ms" tools:text="60 FPS\n16.6±0.10ms"
android:textColor="@color/colorPerfStatsPrimary" /> android:textColor="@color/colorPerfStatsPrimary" />
<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 <ImageButton
android:id="@+id/on_screen_controller_toggle" android:id="@+id/on_screen_controller_toggle"
android:layout_width="wrap_content" android:layout_width="wrap_content"