2

Is there any way to get all touch points on Android screen? I am using MotionEvent to get coordinates when I touch parent layout and onTouchEvents when I touch some of the child elements. But I would like to use some third party library (if exist), that can return all touchings on screen without knowing what activity contains. I only need to get coordinates of all touchings on screen, but that library should impact the existing application functionalities. Is there any way to achieve this. Thanks!!!

Ram
  • 3,887
  • 4
  • 27
  • 49
Matej Košút
  • 590
  • 2
  • 10
  • 27

1 Answers1

1

You don't need any toolkit or library to get the coordinates. To get the coordinates of touch point on the screen, all you have to do is- getting X and Y value using MotionEvent object. I have used this code in my project for Camera focus and zooming purpose.

Just copy and paste below code in your activity code (Outside of onCreate() method) and check logcat:

@Override
public void onTouchEvent(MotionEvent event) {
    int pointerId = event.getPointerId(0);
    int pointerIndex = event.findPointerIndex(pointerId);
    // Get the pointer's current position
    float x = event.getX(pointerIndex);
    float y = event.getY(pointerIndex);
    System.out.println("X:"+x);
    System.out.println("Y:"+y);
}
halfer
  • 19,824
  • 17
  • 99
  • 186
Ram
  • 3,887
  • 4
  • 27
  • 49
  • Thanks, but that is exactly what I am doing now. I want to avoid using MotionEvent and I want to get all touchings without knowing what activity looks like. Something like there would be something over the application and it would not limit the functionality. If it is possible... – Matej Košút Feb 17 '16 at 12:47
  • Correct me If I am wrong, all you want is to get all touch coordinates without touching the screen. – Ram Feb 17 '16 at 12:57
  • If so, This might help you. http://stackoverflow.com/questions/11832333/how-to-get-screen-cordinates-corresponding-to-the-whole-screen-and-not-the-view – Ram Feb 17 '16 at 13:04
  • Not exactly. I want something that would be "above" the activity a it would get all the touchings and it would not matter what is under it (what activity looks like). But I do not even know, if it is possible to do somehow. However thank you for your answers. – Matej Košút Feb 17 '16 at 15:18