1

Part of my Android app uses speech-to-text, and I want to disable touch events while it does that because otherwise the user can accidentally touch their phone and stop the conversation.

I'm trying to use a ViewGroup that can be the parent for that Activity and absorb the touch events, but am having trouble with it.

I have an Activity, and from there I pull up a DialogFragment where the user can enter information using speech-to-text.

When I tried using an overlay to absorb the touch events from the dialog, it only covered the DialogFragment and not the whole screen. And when I added it to the Activity, I couldn't access it from the DialogFragment.

In any case, it never stopped the touch events anyways because my main problem is when the speech-to-text dialog is up and that would come up on top of the overlay and I don't know how to get the handle for that.

Anyone here done anything like this before? Thanks.

Nerdy Bunz
  • 6,040
  • 10
  • 41
  • 100
S T L
  • 23
  • 4
  • did yout try with the `onInterceptTouchEvent()` – Shay Kin Mar 10 '21 at 09:31
  • Yes, I created a ViewGroup that overrides that event, but it didn't work properly when I tried inflating it over the activity. Basically, I have an activity, and when the user pushes a button, a dialog pops up and they can enter information into the dialog box using text-to-speech. I tried making the ViewGroup part of the activity, but that didn't work and then I tried from the dialog but then it only covered the dialog box itself and not the whole screen. – S T L Mar 10 '21 at 09:39
  • In any case, whenever I touched the screen when the text-to-speech dialog was up, it always cancelled it, no matter what. I can't get the ViewGroup to go on top of the Text-To-Speech dialog that pops up. – S T L Mar 10 '21 at 09:41
  • 1
    it didn't work because when you call startActivity for result you are on another activity that's why your code doesn't work – Shay Kin Mar 10 '21 at 10:23
  • Any idea how to fix that? – S T L Mar 10 '21 at 10:33
  • I think use a custom dialog and use listnener like this example https://stackoverflow.com/q/44715624/7085389 – Shay Kin Mar 10 '21 at 12:21
  • I already implement a custom dialog and listener. You're saying I should implement something by onPartialResults? Something to block touch? – S T L Mar 11 '21 at 08:28
  • To block keys outside the dialog use this https://stackoverflow.com/a/20259882/7085389 – Shay Kin Mar 11 '21 at 08:58
  • onPartialResults you can use it to display text Dynamically – Shay Kin Mar 11 '21 at 09:10
  • I don't need to display text Dynamically, so I guess onPartialResults isn't what I'm looking for. I've tried both setCancelable and setCanceledOnTouchOutside but neither works because I'm trying to get them to work for the TextToSpeech box that comes up, and I don't know how to get a handle for that. – S T L Mar 11 '21 at 10:57
  • Please can you update your question and add some code so that I understand you what went wrong – Shay Kin Mar 11 '21 at 10:59
  • Updated. Thank you for all of your help! – S T L Mar 11 '21 at 17:56
  • 1
    Might as well just get it overwith and watch this: https://www.youtube.com/watch?v=EZAoJU-nUyI – Nerdy Bunz Mar 12 '21 at 02:24
  • @NerdyBunz Thanks, great video! He doesn't show how to access the Speech-To-Text dialog, though. It comes on top of the ViewGroup, so even if I interrupt events to the ViewGroup, it doesn't help. – S T L Mar 15 '21 at 22:29

0 Answers0