Convert property to function

This commit is contained in:
Naveen
2022-08-29 00:57:48 +05:30
parent 091c4d9d9b
commit 21c6c3c835

View File

@@ -9,13 +9,14 @@ class ToneGeneratorHelper(context: Context) {
private val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager private val audioManager = context.getSystemService(Context.AUDIO_SERVICE) as AudioManager
private val toneGenerator = ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME) private val toneGenerator = ToneGenerator(DIAL_TONE_STREAM_TYPE, TONE_RELATIVE_VOLUME)
private val isSilent: Boolean private fun isSilent(): Boolean {
get() = audioManager.ringerMode in arrayOf(AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE) return audioManager.ringerMode in arrayOf(AudioManager.RINGER_MODE_SILENT, AudioManager.RINGER_MODE_VIBRATE)
}
fun playTone(char: Char) = playTone(charToTone[char] ?: -1) fun playTone(char: Char) = playTone(charToTone[char] ?: -1)
fun playTone(tone: Int, durationMs: Int = DIALPAD_TONE_LENGTH_MS.toInt()) { fun playTone(tone: Int, durationMs: Int = DIALPAD_TONE_LENGTH_MS.toInt()) {
if (tone != -1 && !isSilent) { if (tone != -1 && !isSilent()) {
toneGenerator.stopTone() toneGenerator.stopTone()
toneGenerator.startTone(tone, durationMs) 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 TONE_RELATIVE_VOLUME = 80 // The DTMF tone volume relative to other sounds in the stream
const val DIAL_TONE_STREAM_TYPE = STREAM_DTMF const val DIAL_TONE_STREAM_TYPE = STREAM_DTMF
private val charToTone by lazy { private val charToTone = HashMap<Char, Int>().apply {
HashMap<Char, Int>().apply {
put('0', ToneGenerator.TONE_DTMF_0) put('0', ToneGenerator.TONE_DTMF_0)
put('1', ToneGenerator.TONE_DTMF_1) put('1', ToneGenerator.TONE_DTMF_1)
put('2', ToneGenerator.TONE_DTMF_2) put('2', ToneGenerator.TONE_DTMF_2)
@@ -41,5 +41,4 @@ class ToneGeneratorHelper(context: Context) {
put('*', ToneGenerator.TONE_DTMF_S) put('*', ToneGenerator.TONE_DTMF_S)
} }
} }
}
} }