mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-03-19 21:00:11 +01:00
Make sure dialpad tone length is at least >150ms
This commit is contained in:
parent
46cc66466b
commit
f5b88a9ee5
@ -24,6 +24,7 @@ import com.simplemobiletools.commons.models.SimpleContact
|
||||
import com.simplemobiletools.dialer.R
|
||||
import com.simplemobiletools.dialer.adapters.ContactsAdapter
|
||||
import com.simplemobiletools.dialer.extensions.*
|
||||
import com.simplemobiletools.dialer.helpers.DIALPAD_TONE_LENGTH_MS
|
||||
import com.simplemobiletools.dialer.helpers.ToneGeneratorHelper
|
||||
import com.simplemobiletools.dialer.models.SpeedDial
|
||||
import kotlinx.android.synthetic.main.activity_dialpad.*
|
||||
@ -55,9 +56,9 @@ class DialpadActivity : SimpleActivity() {
|
||||
|
||||
setupOptionsMenu()
|
||||
speedDialValues = config.getSpeedDialValues()
|
||||
privateCursor = getMyContactsCursor(false, true)
|
||||
privateCursor = getMyContactsCursor(favoritesOnly = false, withPhoneNumbersOnly = true)
|
||||
|
||||
toneGeneratorHelper = ToneGeneratorHelper(this)
|
||||
toneGeneratorHelper = ToneGeneratorHelper(this, DIALPAD_TONE_LENGTH_MS)
|
||||
|
||||
if (hasRussianLocale) {
|
||||
initRussianChars()
|
||||
|
@ -4,16 +4,20 @@ import android.content.Context
|
||||
import android.media.AudioManager
|
||||
import android.media.AudioManager.STREAM_DTMF
|
||||
import android.media.ToneGenerator
|
||||
import android.os.Handler
|
||||
import android.os.Looper
|
||||
|
||||
class ToneGeneratorHelper(context: Context) {
|
||||
class ToneGeneratorHelper(context: Context, private val minToneLengthMs: Long) {
|
||||
private val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
private val toneGenerator = ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME)
|
||||
private var toneStartTimeMs = 0L
|
||||
|
||||
private fun isSilent(): Boolean {
|
||||
return audioManager.ringerMode in arrayOf(AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE)
|
||||
}
|
||||
|
||||
fun startTone(char: Char) {
|
||||
toneStartTimeMs = System.currentTimeMillis()
|
||||
startTone(charToTone[char] ?: -1)
|
||||
}
|
||||
|
||||
@ -23,7 +27,16 @@ class ToneGeneratorHelper(context: Context) {
|
||||
}
|
||||
}
|
||||
|
||||
fun stopTone() = toneGenerator.stopTone()
|
||||
fun stopTone() {
|
||||
val timeSinceStartMs = System.currentTimeMillis() - toneStartTimeMs
|
||||
if (timeSinceStartMs < minToneLengthMs) {
|
||||
Handler(Looper.getMainLooper()).postDelayed({
|
||||
toneGenerator.stopTone()
|
||||
}, minToneLengthMs - timeSinceStartMs)
|
||||
} else {
|
||||
toneGenerator.stopTone()
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
const val TONE_RELATIVE_VOLUME = 80 // The DTMF tone volume relative to other sounds in the stream
|
||||
|
Loading…
x
Reference in New Issue
Block a user