0

I have a service that draws an overlay view over the system. It is an utility bar. When user clicks it, it shows up. My problem is that I don't want it showing up when user click, but when user swipe it. I have a logic that can distinguish a click from an drag/swipe using onTouchListener.

The problem is: when user click it, I want to ignore the touch and let the android system consumes it. When user swipe, I want to consume the event and dont let android consume it, because I will make my utility bar show up.

How to achieve this? I am on API 25(android N).

NameTopSecret
  • 310
  • 5
  • 15

1 Answers1

0

Simple answer: You can't.

Once overlay view receives touch event, its considered consumed and it's never propagated further.

This is mostly a security measure, since you can record and distunguish X, Y coordinates it would allow implementation of keyloggers or other click blocking/spoofing code.

Pawel
  • 15,548
  • 3
  • 36
  • 36
  • So what is the point of returning true/false in onTouchListener? Do you know another possible solution to my problem? – NameTopSecret Jun 23 '18 at 23:12
  • In case of root of overlay view it doesn't matter. It's a special case in which return value is ignored by window manager. I've written quite a few of overlays but never found any way to split touch/click. – Pawel Jun 23 '18 at 23:37
  • To split touch/click you can write your own logic in OnTouchListener using x and y positions of the touch. – NameTopSecret Jul 03 '18 at 13:59