mirror of
https://github.com/skyline-emu/skyline.git
synced 2024-11-23 00:59:17 +01:00
Add a mute button as a PiP window action
This commit is contained in:
parent
4298415134
commit
bdc368e039
@ -6,12 +6,17 @@
|
|||||||
package emu.skyline
|
package emu.skyline
|
||||||
|
|
||||||
import android.annotation.SuppressLint
|
import android.annotation.SuppressLint
|
||||||
|
import android.app.PendingIntent
|
||||||
import android.app.PictureInPictureParams
|
import android.app.PictureInPictureParams
|
||||||
|
import android.app.RemoteAction
|
||||||
|
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.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.hardware.display.DisplayManager
|
import android.hardware.display.DisplayManager
|
||||||
import android.os.*
|
import android.os.*
|
||||||
import android.util.Log
|
import android.util.Log
|
||||||
@ -79,12 +84,16 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
/**
|
/**
|
||||||
* If the activity should return to [MainActivity] or just call [finishAffinity]
|
* If the activity should return to [MainActivity] or just call [finishAffinity]
|
||||||
*/
|
*/
|
||||||
var returnToMain : Boolean = false
|
private var returnToMain : Boolean = false
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The desired refresh rate to present at in Hz
|
* The desired refresh rate to present at in Hz
|
||||||
*/
|
*/
|
||||||
var desiredRefreshRate = 60f
|
private var desiredRefreshRate = 60f
|
||||||
|
|
||||||
|
private val muteIntentAction = "$packageName.EMULATOR_MUTE"
|
||||||
|
private lateinit var pictureInPictureParamsBuilder : PictureInPictureParams.Builder
|
||||||
|
private lateinit var muteReceiver : BroadcastReceiver
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
lateinit var appSettings : AppSettings
|
lateinit var appSettings : AppSettings
|
||||||
@ -263,8 +272,15 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
binding.onScreenControllerToggle.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
|
binding.onScreenControllerToggle.setOnApplyWindowInsetsListener(insetsOrMarginHandler)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
val muteIcon = Icon.createWithResource(this, R.drawable.ic_volume_mute)
|
||||||
|
val mutePendingIntent = PendingIntent.getBroadcast(this, R.drawable.ic_volume_mute, Intent(muteIntentAction), PendingIntent.FLAG_UPDATE_CURRENT or PendingIntent.FLAG_IMMUTABLE)
|
||||||
|
val muteRemoteAction = RemoteAction(muteIcon, getString(R.string.mute), getString(R.string.disable_audio_output), mutePendingIntent)
|
||||||
|
|
||||||
|
pictureInPictureParamsBuilder = PictureInPictureParams.Builder().setActions(mutableListOf(muteRemoteAction))
|
||||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.S)
|
||||||
setPictureInPictureParams(PictureInPictureParams.Builder().setAutoEnterEnabled(true).build())
|
pictureInPictureParamsBuilder.setAutoEnterEnabled(true)
|
||||||
|
|
||||||
|
setPictureInPictureParams(pictureInPictureParamsBuilder.build())
|
||||||
|
|
||||||
binding.gameView.holder.addCallback(this)
|
binding.gameView.holder.addCallback(this)
|
||||||
|
|
||||||
@ -352,6 +368,17 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
|
override fun onPictureInPictureModeChanged(isInPictureInPictureMode: Boolean, newConfig: Configuration) {
|
||||||
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
|
super.onPictureInPictureModeChanged(isInPictureInPictureMode, newConfig)
|
||||||
if (isInPictureInPictureMode) {
|
if (isInPictureInPictureMode) {
|
||||||
|
muteReceiver = object : BroadcastReceiver() {
|
||||||
|
override fun onReceive(context: Context?, intent: Intent) {
|
||||||
|
if (intent.action == muteIntentAction)
|
||||||
|
changeAudioStatus(false)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
IntentFilter(muteIntentAction).also {
|
||||||
|
registerReceiver(muteReceiver, it)
|
||||||
|
}
|
||||||
|
|
||||||
binding.onScreenControllerView.isGone = true
|
binding.onScreenControllerView.isGone = true
|
||||||
binding.onScreenControllerToggle.isGone = true
|
binding.onScreenControllerToggle.isGone = true
|
||||||
} else {
|
} else {
|
||||||
@ -362,10 +389,16 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
binding.onScreenControllerToggle.apply {
|
binding.onScreenControllerToggle.apply {
|
||||||
isGone = binding.onScreenControllerView.isGone
|
isGone = binding.onScreenControllerView.isGone
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
if (this::muteReceiver.isInitialized)
|
||||||
|
unregisterReceiver(muteReceiver)
|
||||||
|
} catch (ignored: Exception) {
|
||||||
|
// Perfectly acceptable and should be ignored
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 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
|
||||||
*/
|
*/
|
||||||
@ -378,8 +411,8 @@ class EmulationActivity : AppCompatActivity(), SurfaceHolder.Callback, View.OnTo
|
|||||||
}
|
}
|
||||||
|
|
||||||
override fun onUserLeaveHint() {
|
override fun onUserLeaveHint() {
|
||||||
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S)
|
if (Build.VERSION.SDK_INT < Build.VERSION_CODES.S && !isInPictureInPictureMode)
|
||||||
enterPictureInPictureMode(PictureInPictureParams.Builder().build())
|
enterPictureInPictureMode(pictureInPictureParamsBuilder.build())
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun onDestroy() {
|
override fun onDestroy() {
|
||||||
|
5
app/src/main/res/drawable/ic_volume_mute.xml
Normal file
5
app/src/main/res/drawable/ic_volume_mute.xml
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
<vector android:autoMirrored="true" android:height="24dp"
|
||||||
|
android:tint="#000000" android:viewportHeight="24"
|
||||||
|
android:viewportWidth="24" android:width="24dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<path android:fillColor="@android:color/white" android:pathData="M7,9v6h4l5,5V4l-5,5H7z"/>
|
||||||
|
</vector>
|
@ -87,6 +87,7 @@
|
|||||||
<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>
|
||||||
<!-- Settings - Audio -->
|
<!-- Settings - Audio -->
|
||||||
<string name="audio">Audio</string>
|
<string name="audio">Audio</string>
|
||||||
|
<string name="mute">Mute</string>
|
||||||
<string name="disable_audio_output">Disable Audio Output</string>
|
<string name="disable_audio_output">Disable Audio Output</string>
|
||||||
<string name="disable_audio_output_enabled">Audio output is disabled</string>
|
<string name="disable_audio_output_enabled">Audio output is disabled</string>
|
||||||
<string name="disable_audio_output_disabled">Audio output is enabled</string>
|
<string name="disable_audio_output_disabled">Audio output is enabled</string>
|
||||||
|
Loading…
Reference in New Issue
Block a user