Added setSpeakerIcon function
This commit is contained in:
@@ -197,12 +197,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
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}")
|
||||||
if (speakerIcon != null) {
|
setSpeakerIcon()
|
||||||
if (Utils.isSpeakerPhoneOn(am))
|
|
||||||
speakerIcon!!.setIcon(R.drawable.speaker_on)
|
|
||||||
else
|
|
||||||
speakerIcon!!.setIcon(R.drawable.speaker_off)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
am.addOnCommunicationDeviceChangedListener(mainExecutor, comDevChangedListener)
|
am.addOnCommunicationDeviceChangedListener(mainExecutor, comDevChangedListener)
|
||||||
@@ -722,6 +717,15 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
} // OnCreate
|
} // OnCreate
|
||||||
|
|
||||||
|
private fun setSpeakerIcon() {
|
||||||
|
if (speakerIcon != null) {
|
||||||
|
if (Utils.isSpeakerPhoneOn(am))
|
||||||
|
speakerIcon!!.setIcon(R.drawable.speaker_on)
|
||||||
|
else
|
||||||
|
speakerIcon!!.setIcon(R.drawable.speaker_off)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
override fun onStart() {
|
override fun onStart() {
|
||||||
super.onStart()
|
super.onStart()
|
||||||
Log.e(TAG, "Main onStart")
|
Log.e(TAG, "Main onStart")
|
||||||
@@ -1301,10 +1305,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
menuInflater.inflate(R.menu.speaker_icon, menu)
|
menuInflater.inflate(R.menu.speaker_icon, menu)
|
||||||
speakerIcon = menu.findItem(R.id.speakerIcon)
|
speakerIcon = menu.findItem(R.id.speakerIcon)
|
||||||
if (Utils.isSpeakerPhoneOn(am))
|
setSpeakerIcon()
|
||||||
speakerIcon!!.setIcon(R.drawable.speaker_on)
|
|
||||||
else
|
|
||||||
speakerIcon!!.setIcon(R.drawable.speaker_off)
|
|
||||||
|
|
||||||
return super.onCreateOptionsMenu(menu)
|
return super.onCreateOptionsMenu(menu)
|
||||||
}
|
}
|
||||||
@@ -1352,12 +1353,7 @@ class MainActivity : AppCompatActivity() {
|
|||||||
"${am.communicationDevice!!.type}/${am.mode}"
|
"${am.communicationDevice!!.type}/${am.mode}"
|
||||||
)
|
)
|
||||||
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(this), am)
|
Utils.toggleSpeakerPhone(ContextCompat.getMainExecutor(this), am)
|
||||||
if (speakerIcon != null) {
|
setSpeakerIcon()
|
||||||
if (Utils.isSpeakerPhoneOn(am))
|
|
||||||
speakerIcon!!.setIcon(R.drawable.speaker_on)
|
|
||||||
else
|
|
||||||
speakerIcon!!.setIcon(R.drawable.speaker_off)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
R.id.config -> {
|
R.id.config -> {
|
||||||
|
|||||||
Reference in New Issue
Block a user