mirror of
https://github.com/SimpleMobileTools/Simple-Dialer.git
synced 2025-06-05 21:49:23 +02:00
Convert property to function
This commit is contained in:
@@ -9,13 +9,14 @@ class ToneGeneratorHelper(context: Context) {
|
||||
private val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
|
||||
private val toneGenerator = ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME)
|
||||
|
||||
private val isSilent: Boolean
|
||||
get() = audioManager.ringerMode in arrayOf(AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE)
|
||||
private fun isSilent(): Boolean {
|
||||
return audioManager.ringerMode in arrayOf(AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE)
|
||||
}
|
||||
|
||||
fun playTone(char: Char) = playTone(charToTone[char] ?: -1)
|
||||
|
||||
fun playTone(tone: Int, durationMs: Int = DIALPAD_TONE_LENGTH_MS.toInt()) {
|
||||
if (tone != -1 && !isSilent) {
|
||||
if (tone != -1 && !isSilent()) {
|
||||
toneGenerator.stopTone()
|
||||
toneGenerator.startTone(tone, durationMs)
|
||||
}
|
||||
@@ -25,8 +26,7 @@ class ToneGeneratorHelper(context: Context) {
|
||||
const val TONE_RELATIVE_VOLUME = 80 // The DTMF tone volume relative to other sounds in the stream
|
||||
const val DIAL_TONE_STREAM_TYPE = STREAM_DTMF
|
||||
|
||||
private val charToTone by lazy {
|
||||
HashMap<Char, Int>().apply {
|
||||
private val charToTone = HashMap<Char, Int>().apply {
|
||||
put('0', ToneGenerator.TONE_DTMF_0)
|
||||
put('1', ToneGenerator.TONE_DTMF_1)
|
||||
put('2', ToneGenerator.TONE_DTMF_2)
|
||||
@@ -41,5 +41,4 @@ class ToneGeneratorHelper(context: Context) {
|
||||
put('*', ToneGenerator.TONE_DTMF_S)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user