Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android: How to figure out what view is stealing my touch events?

Tags:

android

I have a bottom drawer - a view that is bottom aligned with the bottom of the screen and when dismissed animates itself down until it becomes invisible (in such state its top border is aligned with the bottom of the screen). I am trying to implement dismissing this view by vertical swipe down on it. To do it I attached a gesture detector in this method of the view:

  @Override
  public boolean onInterceptTouchEvent(MotionEvent event) {
    return mGestureDetector.onTouchEvent(event);
  }

I did it this way since this view contains a horizontal recycler view, so I do not want to intercept the child touches too early to make sure my view responds only to swipe down and does not steal horizontal touches from the recycler view (as described here: https://developer.android.com/training/gestures/viewgroup.html)

Now, my problem is that when I swipe on one area of this view, the fling recognition works, while when I swipe on another area ofthis view it does not work. In the first case I see in the debugger that onInterceptTouchEvent is called three times, the third call is recognized by the gesture recognizer as fling. In the second case I see that onInterceptTouchEvent is called only once.

It looks that some other view is stealing my touches, but I have no idea which one is that since my app is pretty complex and I am not the only author :). What is an easy way of debugging that in a general case? I would like to just know what view in the entire hierarchy of my activity consumed my event making onInterceptTouchEvent called only once - that would be a good start for the further investigation.

Thanks!

like image 883
Lukasz Indyk Avatar asked Sep 06 '25 08:09

Lukasz Indyk


1 Answers

The way I do it is using emulator with android source code downloaded.

I put a breakpoint in View.dispatchTouchEvent (all places that returns true). This will show me which view is handling the event.

If this does not help, you can also place various breakpoint log messages.

I hope this will help you solve the problem :D

like image 186
Kamen Dobrev Avatar answered Sep 10 '25 14:09

Kamen Dobrev