mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-23 00:59:17 +01:00
Allow the options, even if they're useless
Since this is instantiated in `onCreate` and may be recycled with different settings, relying on the audio to be disabled to determine if a mute action is available seems like a risky gamble.
This commit is contained in:
parent
39393ec310
commit
905c0a47fa
@ -52,6 +52,9 @@ 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 ActionMute = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_MUTE"
|
||||||
|
|
||||||
@AndroidEntryPoint
|
@AndroidEntryPoint
|
||||||
class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTouchListener, DisplayManager.DisplayListener {
|
class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTouchListener, DisplayManager.DisplayListener {
|
||||||
companion object {
|
companion object {
|
||||||
@ -95,9 +98,6 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
private var isEmulatorPaused = false
|
private var isEmulatorPaused = false
|
||||||
|
|
||||||
private lateinit var pictureInPictureParamsBuilder : PictureInPictureParams.Builder
|
private lateinit var pictureInPictureParamsBuilder : PictureInPictureParams.Builder
|
||||||
private val intentActionPause = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_PAUSE"
|
|
||||||
private val intentActionMute = "${BuildConfig.APPLICATION_ID}.ACTION_EMULATOR_MUTE"
|
|
||||||
private lateinit var pictureInPictureReceiver : BroadcastReceiver
|
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var appSettings : AppSettings
|
lateinit var appSettings : AppSettings
|
||||||
@ -401,16 +401,14 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
val pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
val pendingFlags = PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE
|
||||||
|
|
||||||
val pauseIcon = Icon.createWithResource(this, R.drawable.ic_pause)
|
val pauseIcon = Icon.createWithResource(this, R.drawable.ic_pause)
|
||||||
val pausePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_pause, Intent(intentActionPause), pendingFlags)
|
val pausePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_pause, Intent(ActionPause), pendingFlags)
|
||||||
val pauseRemoteAction = RemoteAction(pauseIcon, getString(R.string.pause), getString(R.string.pause_emulator), pausePendingIntent)
|
val pauseRemoteAction = RemoteAction(pauseIcon, getString(R.string.pause), getString(R.string.pause), pausePendingIntent)
|
||||||
pictureInPictureActions.add(pauseRemoteAction)
|
pictureInPictureActions.add(pauseRemoteAction)
|
||||||
|
|
||||||
if (!emulationSettings.isAudioOutputDisabled) {
|
|
||||||
val muteIcon = Icon.createWithResource(this, R.drawable.ic_volume_mute)
|
val muteIcon = Icon.createWithResource(this, R.drawable.ic_volume_mute)
|
||||||
val mutePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_volume_mute, Intent(intentActionMute), pendingFlags)
|
val mutePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_volume_mute, Intent(ActionMute), pendingFlags)
|
||||||
val muteRemoteAction = RemoteAction(muteIcon, getString(R.string.mute), getString(R.string.disable_audio_output), mutePendingIntent)
|
val muteRemoteAction = RemoteAction(muteIcon, getString(R.string.mute), getString(R.string.mute), mutePendingIntent)
|
||||||
pictureInPictureActions.add(muteRemoteAction)
|
pictureInPictureActions.add(muteRemoteAction)
|
||||||
}
|
|
||||||
|
|
||||||
pictureInPictureParamsBuilder.setActions(pictureInPictureActions)
|
pictureInPictureParamsBuilder.setActions(pictureInPictureActions)
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||||
@ -421,22 +419,22 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
return pictureInPictureParamsBuilder
|
return pictureInPictureParamsBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
|
private var pictureInPictureReceiver = object : BroadcastReceiver() {
|
||||||
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
|
|
||||||
if (isInPictureInPictureMode) {
|
|
||||||
pictureInPictureReceiver = object : BroadcastReceiver() {
|
|
||||||
override fun onReceive(context : Context?, intent : Intent) {
|
override fun onReceive(context : Context?, intent : Intent) {
|
||||||
if (intent.action == intentActionPause)
|
if (intent.action == ActionPause)
|
||||||
pauseEmulator()
|
pauseEmulator()
|
||||||
else if (intent.action == intentActionMute)
|
else if (intent.action == ActionMute)
|
||||||
changeAudioStatus(false)
|
changeAudioStatus(false)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
|
||||||
|
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
|
||||||
|
if (isInPictureInPictureMode) {
|
||||||
|
|
||||||
IntentFilter().apply {
|
IntentFilter().apply {
|
||||||
addAction(intentActionPause)
|
addAction(ActionPause)
|
||||||
if (!emulationSettings.isAudioOutputDisabled)
|
addAction(ActionMute)
|
||||||
addAction(intentActionMute)
|
|
||||||
}.also {
|
}.also {
|
||||||
registerReceiver(pictureInPictureReceiver, it)
|
registerReceiver(pictureInPictureReceiver, it)
|
||||||
}
|
}
|
||||||
@ -446,11 +444,8 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
binding.onScreenPauseToggle.isGone = true
|
binding.onScreenPauseToggle.isGone = true
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
if (this::pictureInPictureReceiver.isInitialized)
|
|
||||||
unregisterReceiver(pictureInPictureReceiver)
|
unregisterReceiver(pictureInPictureReceiver)
|
||||||
} catch (ignored : Exception) {
|
} catch (ignored : Exception) { }
|
||||||
// Perfectly acceptable and should be ignored
|
|
||||||
}
|
|
||||||
|
|
||||||
resumeEmulator()
|
resumeEmulator()
|
||||||
|
|
||||||
|
@ -25,7 +25,6 @@
|
|||||||
<string name="incomplete_prod_keys">Incomplete production keys</string>
|
<string name="incomplete_prod_keys">Incomplete production keys</string>
|
||||||
<!-- Picture-In-Picture -->
|
<!-- Picture-In-Picture -->
|
||||||
<string name="pause">Pause</string>
|
<string name="pause">Pause</string>
|
||||||
<string name="pause_emulator">Pause emulator process</string>
|
|
||||||
<string name="mute">Mute</string>
|
<string name="mute">Mute</string>
|
||||||
<!-- Settings - Content -->
|
<!-- Settings - Content -->
|
||||||
<string name="content">Content</string>
|
<string name="content">Content</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user