0

I'm currently trying to make a utility overlay similar to Facebook Messenger chatheads in which you can move the view around the screen. When you click the view, it expands into a more complex layout. However, the problem is if I set the LayoutParams' flag to WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, the apps behind receive the touch events while my overlay doesn't receive any touch events at all. But if I remove that flag, the overlay receives the touches but it blocks the touch. Meaning I can't even open the app drawer since the touches are being blocked.

I am using a fullscreen transparent Activity as background so I can move my overlay "widget" around it.

Is there any way I can make it so that it doesn't block touch events. Even if I don't set it to fullscreen, as long as I don't have the FLAG_NOT_TOUCHABLE flag, my overlay completely blocks all screen touches.

leondzn
  • 97
  • 9
  • It will not work with a transparent Activity. The way bubbles have been implemented (before the [Bubbles API](https://developer.android.com/guide/topics/ui/bubbles) in Android Q) is by attaching views directly to the `WindowManager`. See [this answer](https://stackoverflow.com/a/10267371/356629) and [this repo](https://github.com/mollyIV/ChatHeads) – kenny_k Sep 23 '19 at 07:22
  • A touch walks through every function override some touch event. It begins in the top layer and walks through to bottom layer. If you want to block the touch you can use `return false;` in any of these functions. If you don't want to block it, use `return true;` in these functions. – Alpha-Centauri Sep 23 '19 at 07:33
  • @kenny_k so If I attach the view directly to WindowManager, will I still be able to move it around? By the way the problem still remains. I ditched the full screen transparent activity but I still get the same results. This is how I made my layout params: WindowManager.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.TYPE_APPLICATION_OVERLAY, WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE, PixelFormat.TRANSLUCENT) – leondzn Sep 23 '19 at 09:55
  • I guess you should remove `WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE` - as with this it would clearly not be touchable. Since you don't have an activity anymore, any TouchEvents outside your view will be handling by whatever is beneath the touch. – kenny_k Sep 23 '19 at 10:01
  • @kenny_k same results. If I remove the not touchable flag, the view becomes clickable but the apps beneath cannot receive touch events again – leondzn Sep 23 '19 at 10:07
  • Are you sure your view is not bigger than the rendered element? Enable draw overlays, etc to validate that you're indeed only showing the bubble and not anything else. If your transparent activity is still open, you will keep having this problem. – kenny_k Sep 23 '19 at 10:09

1 Answers1

2

Please Remove this flag

WindowManager.LayoutParams.FLAG_NOT_TOUCHABLE 

with this flag

WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE

see this link https://medium.com/@kevalpatel2106/create-chat-heads-like-facebook-messenger-32f7f1a62064

Kundan Singh
  • 91
  • 1
  • 6