title: Get invalidated region in onDraw in EditText subclass
body: <p>I'm trying to override onDraw in an EditText subclass, to show a custom subtitle.
  I've got it working, but there are a few bugs.</p>
  
  <p>Basicall, all I need to do is draw StaticLayout at a certain offset from top left corner of the view.</p>
  
  <p>Unfortunantly, all I get in my onDraw method is canvas. The size of the canvas is equal to the size of the whole screen (320x480 on a device with 320x480 display) and its clip bounds can be pretty much anything - it can be the whole view; it can be only top or bottom part of the view if the view is inside scrollview and partially visible; it can even be same arbitrary rect inside the view, probably because superclass invalidates only some of its region.</p>
  
  <p>So if I have this view with size 320x48, I can get canvas with size 320x480 and clipping rect (200, 200, 300, 230) (left, top, right, bottom). I don't understand how this clipping rect maps to my view coordinates.</p>
  
  <p>I need to know where is top left corner of the clipping rect relative to the top left corner of the view. Unfortunantly, I cannot figure out how to get this.</p>
  
  <p><strong>Added:</strong><br>
  This code will work on all os versions that I've tested:</p>
  
  <pre><code>private int[] coordinates = new int[2];
  private Matrix identityMatrix = new Matrix();
  
  @Override
  protected void onDraw(Canvas canvas) {
      super.onDraw(canvas);
      canvas.save();
      getLocationInWindow(coordinates);
      canvas.setMatrix(identityMatrix);
      canvas.translate(coordinates[0], coordinates[1]);
      //do the drawing in EditText coordinate space
      canvas.restore();
  }
  </code></pre>
  
  <p>However, I still have one question: <strong>why does it work?</strong><br>
  I've trying overriding View class and  it's onDraw method will always recieve a canvas which size matches that of the View itself. Canvas for direct View subclass will have no clipping rect. Same for TextView (direct ancestor of the EditText class). But it's not the same for EditText. Canvas that gets passed to onDraw method of EditText will always (or not?) have the size of the screen, and a custom clipping rect. This whole "translate by view coordinates in window thing" seems very hacky. I don't understand why I should translate the coordinate space.</p>
  
  <p>I've tried hacking android source code for the answers, but found none. EditText has no onDraw of its own. Theoretically, there should be no difference between overriding TextView onDraw and EditText onDraw. But there is a difference. The canvas object passed to onDraw method will be different depending on whether its TextView or EditText. Why? <strong>How do I know when I should apply transformation to matrix, and when I shouldn't?</strong></p>