Android Wear Overlay Pass on Touch Events

谁都会走 提交于 2019-12-06 10:18:58

问题


I have an Android Wear app in which I use a transparent overlay view to recieve touch events. I need to be able to receive all touch events that happen anywhere on the screen, and also be able to see their coordinates.

All research I have found says that I cannot recieve all touch events and pass them on. However, Wear Mini Launcher and Swipify are both doing something like this.

Here is where I have looked:

  • Android overlay to grab ALL touch, and pass them on?
  • https://stackoverflow.com/questions/19356834/overlay-view-which-intercepts-some-events
  • Android - Intercept and pass on all touch events
  • Android : Multi touch and TYPE_SYSTEM_OVERLAY
  • Creating a system overlay window (always on top)
  • Getting the View that is receiving all the touch events
  • Android Jelly Bean service that receives all touch events
  • TYPE_SYSTEM_OVERLAY in ICS
  • Overlay App that reacts only on some touch events

This must be possible to do somehow. Maybe an overlay view is not the right way to approach this? Any pointers?


回答1:


I had quite a bit of trouble with this as well using the same links that you provided. But then I found this: http://www.piwai.info/chatheads-basics/

It's basically the same as the other solutions, except that the arguments to the WindowManager LayoutParams are TYPE_PHONE and FLAG_NOT_FOCUSABLE.

Not only did this solution work for me (I was testing on an LG Urbane), the onTouchEvent callback had all the actions (down, move, and up), which the other solutions said you wouldn't get.

Since all the touch events are passed through the view, in theory we can use gesture detectors to get callbacks for things like double taps and flings. I haven't tried this yet, though.

Regardless, the above link should get you past the initial problems you're facing.



来源:https://stackoverflow.com/questions/26496768/android-wear-overlay-pass-on-touch-events

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!