Replaced speaker drawables with Material Design icon
This commit is contained in:
@@ -138,11 +138,6 @@ class MainActivity : ComponentActivity() {
|
|||||||
comDevChangedListener = AudioManager.OnCommunicationDeviceChangedListener { device ->
|
comDevChangedListener = AudioManager.OnCommunicationDeviceChangedListener { device ->
|
||||||
if (device != null) {
|
if (device != null) {
|
||||||
Log.d(TAG, "Com device changed to type ${device.type} in mode ${am.mode}")
|
Log.d(TAG, "Com device changed to type ${device.type} in mode ${am.mode}")
|
||||||
val speakerIcon = if (Utils.isSpeakerPhoneOn(am))
|
|
||||||
R.drawable.speaker_on
|
|
||||||
else
|
|
||||||
R.drawable.speaker_off
|
|
||||||
viewModel.updateSpeakerIcon(speakerIcon)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
am.addOnCommunicationDeviceChangedListener(mainExecutor, comDevChangedListener)
|
am.addOnCommunicationDeviceChangedListener(mainExecutor, comDevChangedListener)
|
||||||
|
|||||||
@@ -61,6 +61,7 @@ import androidx.compose.material.icons.filled.Menu
|
|||||||
import androidx.compose.material.icons.filled.Mic
|
import androidx.compose.material.icons.filled.Mic
|
||||||
import androidx.compose.material.icons.filled.MicOff
|
import androidx.compose.material.icons.filled.MicOff
|
||||||
import androidx.compose.material.icons.filled.RecordVoiceOver
|
import androidx.compose.material.icons.filled.RecordVoiceOver
|
||||||
|
import androidx.compose.material.icons.filled.SpeakerPhone
|
||||||
import androidx.compose.material.icons.filled.VoiceOverOff
|
import androidx.compose.material.icons.filled.VoiceOverOff
|
||||||
import androidx.compose.material.icons.outlined.Clear
|
import androidx.compose.material.icons.outlined.Clear
|
||||||
import androidx.compose.material3.BasicAlertDialog
|
import androidx.compose.material3.BasicAlertDialog
|
||||||
@@ -499,7 +500,6 @@ private fun TopAppBar(
|
|||||||
onQuitClick: () -> Unit
|
onQuitClick: () -> Unit
|
||||||
) {
|
) {
|
||||||
val ctx = LocalContext.current
|
val ctx = LocalContext.current
|
||||||
val currentSpeakerIcon by viewModel.speakerIcon.collectAsState()
|
|
||||||
val currentMicIcon by viewModel.micIcon.collectAsState()
|
val currentMicIcon by viewModel.micIcon.collectAsState()
|
||||||
|
|
||||||
val am = ctx.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
val am = ctx.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||||
@@ -507,6 +507,7 @@ private fun TopAppBar(
|
|||||||
val recOffImage = Icons.Filled.VoiceOverOff
|
val recOffImage = Icons.Filled.VoiceOverOff
|
||||||
val recOnImage = Icons.Filled.RecordVoiceOver
|
val recOnImage = Icons.Filled.RecordVoiceOver
|
||||||
var recImage by remember { mutableStateOf(recOffImage) }
|
var recImage by remember { mutableStateOf(recOffImage) }
|
||||||
|
val isSpeakerOn = remember { mutableStateOf(Utils.isSpeakerPhoneOn(am)) }
|
||||||
|
|
||||||
var menuExpanded by remember { mutableStateOf(false) }
|
var menuExpanded by remember { mutableStateOf(false) }
|
||||||
|
|
||||||
@@ -605,23 +606,17 @@ private fun TopAppBar(
|
|||||||
Spacer(modifier = Modifier.width(16.dp))
|
Spacer(modifier = Modifier.width(16.dp))
|
||||||
|
|
||||||
Icon(
|
Icon(
|
||||||
imageVector = ImageVector.vectorResource(currentSpeakerIcon),
|
imageVector = Icons.Filled.SpeakerPhone,
|
||||||
modifier = Modifier
|
modifier = Modifier
|
||||||
.size(40.dp)
|
.size(40.dp)
|
||||||
.combinedClickable(
|
.combinedClickable(
|
||||||
onClick = {
|
onClick = {
|
||||||
if (Build.VERSION.SDK_INT >= 31)
|
if (Build.VERSION.SDK_INT >= 31)
|
||||||
Log.d(
|
Log.d(TAG, "Toggling speakerphone when dev/mode is " +
|
||||||
TAG, "Toggling speakerphone when dev/mode is " +
|
|
||||||
"${am.communicationDevice!!.type}/${am.mode}"
|
"${am.communicationDevice!!.type}/${am.mode}"
|
||||||
)
|
)
|
||||||
|
isSpeakerOn.value = !Utils.isSpeakerPhoneOn(am)
|
||||||
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(ctx), am)
|
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(ctx), am)
|
||||||
viewModel.updateSpeakerIcon(
|
|
||||||
if (Utils.isSpeakerPhoneOn(am))
|
|
||||||
R.drawable.speaker_on
|
|
||||||
else
|
|
||||||
R.drawable.speaker_off
|
|
||||||
)
|
|
||||||
},
|
},
|
||||||
onLongClick = {
|
onLongClick = {
|
||||||
alertTitle.value = ctx.getString(R.string.speakerphone_title)
|
alertTitle.value = ctx.getString(R.string.speakerphone_title)
|
||||||
@@ -629,7 +624,7 @@ private fun TopAppBar(
|
|||||||
showAlert.value = true
|
showAlert.value = true
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
tint = if (Utils.isSpeakerPhoneOn(am))
|
tint = if (isSpeakerOn.value)
|
||||||
MaterialTheme.colorScheme.error
|
MaterialTheme.colorScheme.error
|
||||||
else
|
else
|
||||||
MaterialTheme.colorScheme.onPrimary,
|
MaterialTheme.colorScheme.onPrimary,
|
||||||
|
|||||||
@@ -69,13 +69,6 @@ class ViewModel(application: Application) : AndroidViewModel(application) {
|
|||||||
_hideKeyboard.intValue++
|
_hideKeyboard.intValue++
|
||||||
}
|
}
|
||||||
|
|
||||||
private val _speakerIcon = MutableStateFlow(R.drawable.speaker_off)
|
|
||||||
val speakerIcon: StateFlow<Int> = _speakerIcon.asStateFlow()
|
|
||||||
|
|
||||||
fun updateSpeakerIcon(iconResId: Int) {
|
|
||||||
_speakerIcon.value = iconResId
|
|
||||||
}
|
|
||||||
|
|
||||||
private val _micIcon = MutableStateFlow(Icons.Filled.Mic)
|
private val _micIcon = MutableStateFlow(Icons.Filled.Mic)
|
||||||
val micIcon: StateFlow<ImageVector> = _micIcon.asStateFlow()
|
val micIcon: StateFlow<ImageVector> = _micIcon.asStateFlow()
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +0,0 @@
|
|||||||
<vector android:height="48dp"
|
|
||||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
|
||||||
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="#FF000000" android:pathData="M7,7.07L8.43,8.5c0.91,-0.91 2.18,-1.48 3.57,-1.48s2.66,0.57 3.57,1.48L17,7.07C15.72,5.79 13.95,5 12,5s-3.72,0.79 -5,2.07zM12,1C8.98,1 6.24,2.23 4.25,4.21l1.41,1.41C7.28,4 9.53,3 12,3s4.72,1 6.34,2.62l1.41,-1.41C17.76,2.23 15.02,1 12,1zM14.86,10.01L9.14,10C8.51,10 8,10.51 8,11.14v9.71c0,0.63 0.51,1.14 1.14,1.14h5.71c0.63,0 1.14,-0.51 1.14,-1.14v-9.71c0.01,-0.63 -0.5,-1.13 -1.13,-1.13zM15,20L9,20v-8h6v8z"/>
|
|
||||||
</vector>
|
|
||||||
@@ -1,5 +0,0 @@
|
|||||||
<vector android:height="48dp"
|
|
||||||
android:viewportHeight="24.0" android:viewportWidth="24.0"
|
|
||||||
android:width="48dp" xmlns:android="http://schemas.android.com/apk/res/android">
|
|
||||||
<path android:fillColor="#FF000000" android:pathData="M7,7.07L8.43,8.5c0.91,-0.91 2.18,-1.48 3.57,-1.48s2.66,0.57 3.57,1.48L17,7.07C15.72,5.79 13.95,5 12,5s-3.72,0.79 -5,2.07zM12,1C8.98,1 6.24,2.23 4.25,4.21l1.41,1.41C7.28,4 9.53,3 12,3s4.72,1 6.34,2.62l1.41,-1.41C17.76,2.23 15.02,1 12,1zM14.86,10.01L9.14,10C8.51,10 8,10.51 8,11.14v9.71c0,0.63 0.51,1.14 1.14,1.14h5.71c0.63,0 1.14,-0.51 1.14,-1.14v-9.71c0.01,-0.63 -0.5,-1.13 -1.13,-1.13zM15,20L9,20v-8h6v8z"/>
|
|
||||||
</vector>
|
|
||||||
Reference in New Issue
Block a user