title: How do I correctly translate pixel coordinates to canvas coordinates in Android?
body: <p>I am capturing a <code>MotionEvent</code> for a long click in an Android <code>SurfaceView</code> using a <code>GestureListener</code>. I then need to translate the coordinates of the <code>MotionEvent</code> to canvas coordinates, from which I can generate custom map coordinates (not Google Maps). </p>
  
  <p>From what I have read, I take that given <code>MotionEvent e</code>, <code>e.getX()</code> and <code>e.getY()</code> get pixel coordinates. How can I convert these coordinates to the <code>SurfaceView</code>'s canvas coordinates?</p>
  
  <p>Here is my <code>GestureListener</code> for listening for long clicks:</p>
  
  <pre><code>/**
  * Overrides touch gestures not handled by the default touch listener
  */
  private class GestureListener extends GestureDetector.SimpleOnGestureListener {
  
    @Override
    public void onLongPress(MotionEvent e) {
       Point p = new Point();
       p.x =  (int) e.getX();
       p.y = (int) e.getY();
       //TODO translate p to canvas coordinates
    }
  }
  </code></pre>
  
  <p>Thanks in advance!</p>
  
  <p><strong>Edit:</strong>
  Does this have to do with screen size/resolution/depth and the canvas' Rect object? </p>