-1
  private void dealEvent(int actionPointerIndex, MotioEvent event,
  View eventView, int actionresolved) {

  int rawX, rawY;
  int location[] = { 0, 0 };


  eventView.getLocationOnScreen(location);
rawX = (int) event.getX(actionIndex) + location[0];
rawY = (int) event.getY(actionIndex) + location[1];

ArrayList<View> views = getTouchedViews(rawX, rawY, actionresolved);

I don't understand these line, why do we do that?

rawX = (int) event.getX(actionIndex) + location[0];
rawY = (int) event.getY(actionIndex) + location[1];

ArrayList<View> views = getTouchedViews(rawX, rawY, actionresolved);
Franz Kafka
  • 10,623
  • 20
  • 93
  • 149

1 Answers1

1

This is mostly supposition since the code you provided isn't quite compilable (MotioEvent should be MotionEvent and you use actionPointerIndex in the function declaration and actionIndex in the body).

Based on this link, one of the features is that the events are automatically forwarded to the underlying view.

It looks like the return values from getX and getY are relative to some non-origin point (for example, the upper left corner of the object which captured the event).

The getLocationOnScreen call populates location with that point and you then use that to generate raw (probably screen) co-ordinates from the relative ones.

Most likely, that's because getTouchedViews requires raw co-ordinates to give you a list of views at that point. The code then goes through that list to figure out which view should receive the event.

paxdiablo
  • 854,327
  • 234
  • 1,573
  • 1,953