- Added Tone Country Audio Configuration option

- Fixed checking of DNS Servers config value
This commit is contained in:
Juha Heinanen
2023-09-21 08:43:18 +03:00
parent b140163c6b
commit 63e1bcb298
53 changed files with 115 additions and 18 deletions

View File

@ -27,6 +27,7 @@ class AudioActivity : AppCompatActivity() {
private var oldOpusBitrate = ""
private var oldOpusPacketLoss = ""
private var oldAec = false
private var toneCountry = BaresipService.toneCountry
private val onBackPressedCallback = object : OnBackPressedCallback(true) {
override fun handleOnBackPressed() {
@ -123,6 +124,27 @@ class AudioActivity : AppCompatActivity() {
audioDelay = binding.AudioDelay
audioDelay.setText(BaresipService.audioDelay.toString())
val toneCountrySpinner = binding.ToneCountrySpinner
val toneCountryKeys = arrayListOf("bg", "br", "de", "cz", "es", "fi", "fr", "uk", "jp", "no", "nz", "se", "ru", "us")
val toneCountryVals = arrayListOf("BG", "BR", "DE", "CZ", "ES", "FI", "FR", "GB", "JP", "NO", "NZ", "SE", "RU", "US")
val keyIx = toneCountryKeys.indexOf(toneCountry)
val keyVal = toneCountryVals.elementAt(keyIx)
toneCountryKeys.removeAt(keyIx)
toneCountryVals.removeAt(keyIx)
toneCountryKeys.add(0, toneCountry)
toneCountryVals.add(0, keyVal)
val toneCountryAdapter = ArrayAdapter(this,android.R.layout.simple_spinner_item,
toneCountryVals)
toneCountryAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item)
toneCountrySpinner.adapter = toneCountryAdapter
toneCountrySpinner.onItemSelectedListener = object : AdapterView.OnItemSelectedListener {
override fun onItemSelected(parent: AdapterView<*>, view: View, position: Int, id: Long) {
toneCountry = toneCountryKeys[toneCountryVals.indexOf(parent.selectedItem.toString())]
}
override fun onNothingSelected(parent: AdapterView<*>) {
}
}
bindTitles()
onBackPressedDispatcher.addCallback(this, onBackPressedCallback)
@ -228,6 +250,12 @@ class AudioActivity : AppCompatActivity() {
save = true
}
if (BaresipService.toneCountry != toneCountry) {
BaresipService.toneCountry = toneCountry
Config.replaceVariable("tone_country", toneCountry)
save = true
}
if (save)
Config.save()
@ -279,6 +307,10 @@ class AudioActivity : AppCompatActivity() {
Utils.alertView(this, getString(R.string.audio_delay),
getString(R.string.audio_delay_help))
}
binding.ToneCountryTitle.setOnClickListener {
Utils.alertView(this, getString(R.string.tone_country),
getString(R.string.tone_country_help))
}
}
private fun checkOpusBitRate(opusBitRate: String): Boolean {

View File

@ -564,7 +564,7 @@ class BaresipService: Service() {
sendBroadcast(Intent("com.tutpro.baresip.Restart"))
}
@SuppressLint("UnspecifiedImmutableFlag")
@SuppressLint("UnspecifiedImmutableFlag", "DiscouragedApi")
@Keep
fun uaEvent(event: String, uap: Long, callp: Long) {
@ -698,7 +698,16 @@ class BaresipService: Service() {
Log.d(TAG, "Auto-rejecting incoming call $uap/$callp/$peerUri")
Api.ua_hangup(uap, callp, 486, "Busy Here")
toast(toastMsg)
playUnInterrupted(R.raw.callwaiting, 1)
val name = "callwaiting_$toneCountry"
val resourceId = applicationContext.resources.getIdentifier(
name,
"raw",
applicationContext.packageName)
if (resourceId != 0) {
playUnInterrupted(resourceId, 1)
} else {
Log.e(TAG, "Callwaiting tone $name.wav not found\")")
}
if (ua.account.callHistory) {
CallHistoryNew.add(CallHistoryNew(aor, peerUri, "in"))
CallHistoryNew.save()
@ -1255,26 +1264,46 @@ class BaresipService: Service() {
}
}
@SuppressLint("DiscouragedApi")
private fun playRingBack() {
if (mediaPlayer == null) {
mediaPlayer = MediaPlayer.create(this, R.raw.ringback)
mediaPlayer?.isLooping = true
mediaPlayer?.start()
val name = "ringback_$toneCountry"
val resourceId = applicationContext.resources.getIdentifier(
name,
"raw",
applicationContext.packageName)
if (resourceId != 0) {
mediaPlayer = MediaPlayer.create(this, resourceId)
mediaPlayer?.isLooping = true
mediaPlayer?.start()
} else {
Log.e(TAG, "Ringback tone $name.wav not found")
}
}
}
@SuppressLint("DiscouragedApi")
private fun playBusy() {
if (mediaPlayer == null ) {
mediaPlayer = MediaPlayer.create(applicationContext, R.raw.busy)
mediaPlayer?.setOnCompletionListener {
stopMediaPlayer()
if (!Call.inCall()) {
resetCallVolume()
abandonAudioFocus(applicationContext)
proximitySensing(false)
val name = "busy_$toneCountry"
val resourceId = applicationContext.resources.getIdentifier(
name,
"raw",
applicationContext.packageName)
if (resourceId != 0) {
mediaPlayer = MediaPlayer.create(this, resourceId)
mediaPlayer?.setOnCompletionListener {
stopMediaPlayer()
if (!Call.inCall()) {
resetCallVolume()
abandonAudioFocus(applicationContext)
proximitySensing(false)
}
}
mediaPlayer?.start()
} else {
Log.e(TAG, "Busy tone $name.wav not found")
}
mediaPlayer?.start()
}
}
@ -1506,6 +1535,7 @@ class BaresipService: Service() {
var isMainVisible = false
var isMicMuted = false
var isRecOn = false
var toneCountry = "us"
val uas = ArrayList<UserAgent>()
val calls = ArrayList<Call>()

View File

@ -129,6 +129,11 @@ object Config {
config = "${config}audio_delay ${BaresipService.audioDelay}\n"
}
val toneCountry = previousVariable("tone_country")
if (toneCountry != "")
BaresipService.toneCountry = toneCountry
config = "${config}tone_country ${BaresipService.toneCountry}\n"
save()
BaresipService.isConfigInitialized = true

View File

@ -535,9 +535,10 @@ class ConfigActivity : AppCompatActivity() {
restart = true
}
val dnsServers = addMissingPorts(
dnsServers.text.toString().trim().lowercase(Locale.ROOT))
if (dnsServers != oldDnsServers) {
var dnsServers = dnsServers.text.toString().lowercase(Locale.ROOT)
.replace(" ", "")
dnsServers = addMissingPorts(dnsServers)
if (dnsServers != oldDnsServers.replace(" ", "")) {
if (!checkDnsServers(dnsServers)) {
Utils.alertView(this, getString(R.string.notice),
"${getString(R.string.invalid_dns_servers)}: $dnsServers")

View File

@ -1037,3 +1037,4 @@ object Utils {
}
}
.

View File

@ -176,6 +176,31 @@
</EditText>
</RelativeLayout>
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginBottom="12dp"
android:orientation="horizontal" >
<TextView
android:id="@+id/ToneCountryTitle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentStart="true"
android:layout_centerVertical="true"
android:layout_toStartOf="@id/ToneCountrySpinner"
android:textSize="18sp"
android:text="@string/tone_country" >
</TextView>
<Spinner
android:id="@+id/ToneCountrySpinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_centerVertical="true"
android:layout_gravity="end" >
</Spinner>
</RelativeLayout>
</LinearLayout>
</ScrollView>

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -383,8 +383,9 @@
<string name="invalid_audio_delay">Virheellinen audioviive \'%1$s\'. Sallittu arvo on välillä 1003000.</string>
<string name="default_call_volume">Oletus äänen voimakkuus</string>
<string name="default_call_volume_help">Jos valittu, puhelun äänen voimakkuus
asteikolla 110.
</string>
asteikolla 110.</string>
<string name="tone_country">Puheluäänien maa</string>
<string name="tone_country_help">Soitto-, odotus- ja varattuäänien maa</string>
<string name="dark_theme">Tumma teema</string>
<string name="dark_theme_help">Käytä aina tummaa näyttöteemaa</string>
<string name="video_size">Videon kehyskoko</string>

View File

@ -359,6 +359,8 @@
<string name="invalid_audio_delay">Invalid Audio Delay \'%1$s\'. Valid values are from 100 to 3000.</string>
<string name="default_call_volume">Default Call Volume</string>
<string name="default_call_volume_help">If set, default call audio volume at scale 110.</string>
<string name="tone_country">Tone Country</string>
<string name="tone_country_help">Country of call ringing, waiting, and callee busy tones</string>
<string name="dark_theme">Dark Theme</string>
<string name="dark_theme_help">Force dark display theme</string>
<string name="video_size">Video Frame Size</string>