listen to switch swap

This commit is contained in:
adrienmalin 2018-12-05 17:27:55 +01:00
parent bc7472cd95
commit 8d0cadaf88

View File

@ -69,8 +69,8 @@ class StarterNameActivity : AppCompatActivity() {
} }
// Check if function is available on switch checked or swapped // Check if function is available on switch checked or swapped
enableTtsSwitch?.setOnTouchListener { view, event -> enableTtsSwitch?.setOnCheckedChangeListener { _, isChecked ->
if ((event.action == MotionEvent.ACTION_DOWN) and (enableTtsSwitch?.isChecked == false)) { if (isChecked) {
Intent().apply { Intent().apply {
action = TextToSpeech.Engine.ACTION_CHECK_TTS_DATA action = TextToSpeech.Engine.ACTION_CHECK_TTS_DATA
startActivityForResult(this, CHECK_TTS) startActivityForResult(this, CHECK_TTS)
@ -79,8 +79,8 @@ class StarterNameActivity : AppCompatActivity() {
false false
} }
enableSttSwitch?.setOnTouchListener { view, event -> enableSttSwitch?.setOnCheckedChangeListener { _, isChecked ->
if ((event.action == MotionEvent.ACTION_DOWN) and (enableSttSwitch?.isChecked == false)) { if (isChecked) {
if (SpeechRecognizer.isRecognitionAvailable(this@StarterNameActivity)) { if (SpeechRecognizer.isRecognitionAvailable(this@StarterNameActivity)) {
// Ask for record audio permission // Ask for record audio permission
if (ContextCompat.checkSelfPermission( if (ContextCompat.checkSelfPermission(