From 6ef7c6a05812457495feff977eb6efca02a94471 Mon Sep 17 00:00:00 2001 From: Juha Heinanen Date: Sun, 13 Dec 2020 11:56:34 +0200 Subject: [PATCH] Improved handling of speakerphone --- .../kotlin/com/tutpro/baresip/BaresipService.kt | 10 +--------- .../main/kotlin/com/tutpro/baresip/MainActivity.kt | 14 ++++++++------ 2 files changed, 9 insertions(+), 15 deletions(-) diff --git a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt index 3ff21006..8decae9b 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/BaresipService.kt @@ -362,11 +362,6 @@ class BaresipService: Service() { updateStatusNotification() } - "SetSpeaker" -> { - Log.d(LOG_TAG, "Set speakerphone $speakerPhone") - am.isSpeakerphoneOn = speakerPhone - } - "Stop", "Stop Force" -> { if (!isServiceClean) cleanService() if (isServiceRunning) baresipStop(action == "Stop Force") @@ -686,15 +681,13 @@ class BaresipService: Service() { resetCallVolume() if (am.mode != AudioManager.MODE_NORMAL) am.mode = AudioManager.MODE_NORMAL - if (am.isSpeakerphoneOn) am.isSpeakerphoneOn = false + am.isSpeakerphoneOn = false if (am.isBluetoothScoOn) { Log.d(LOG_TAG, "Stopping Bluetooth SCO") am.stopBluetoothSco() } else { abandonAudioFocus() } - speakerPhone = false - am.isSpeakerphoneOn = false proximitySensing(false) } if (ua.account.callHistory && !call.hasHistory) { @@ -1140,7 +1133,6 @@ class BaresipService: Service() { var isConfigInitialized = false var libraryLoaded = false var isServiceClean = false - var speakerPhone = false var callVolume = 0 var dynDns = false var netInterface = "" diff --git a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt index a60a1c87..21d549ea 100644 --- a/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt +++ b/app/src/main/kotlin/com/tutpro/baresip/MainActivity.kt @@ -902,6 +902,10 @@ class MainActivity : AppCompatActivity() { menuInflater.inflate(R.menu.main_menu, menu) menuInflater.inflate(R.menu.speaker_icon, menu) speakerIcon = menu.findItem(R.id.speakerIcon) + if (am.isSpeakerphoneOn) + speakerIcon.setIcon(R.drawable.speaker_on) + else + speakerIcon.setIcon(R.drawable.speaker_off) return true } @@ -912,13 +916,11 @@ class MainActivity : AppCompatActivity() { when (item.itemId) { R.id.speakerIcon -> { - if (BaresipService.speakerPhone) - item.setIcon(R.drawable.speaker_off) - else + am.isSpeakerphoneOn = !am.isSpeakerphoneOn + if (am.isSpeakerphoneOn) item.setIcon(R.drawable.speaker_on) - BaresipService.speakerPhone = !BaresipService.speakerPhone - baresipService.setAction("SetSpeaker") - startService(baresipService) + else + item.setIcon(R.drawable.speaker_off) } R.id.config -> {