title: How do I differentiate between MotionEvent.ACTION_UP and dragging a finger off-screen in Android?
body: <p>My application is a grid of buttons, edge to edge.  I'm overriding all touch and motion events and controlling the behavior manually.  Everything is working fine, except for when a finger is dragged off-screen.  MotionEvent.ACTION_UP is triggered, and I don't want that.  I tried using getRawX() and getRawY() to determine if (for example, for the top and left edges) the coordinate is &lt; 1, but the value will be higher (as high as 20) if a finger is dragged quickly.  When ACTION_UP is triggered, the location values seem to lag behind a bit.  Is there a way around this?  ACTION_CANCEL doesn't seem to get triggered at all.</p>
  
  <pre><code>@Override
  public boolean onTouchEvent(MotionEvent event) {
      switch (event.getAction() &amp; MotionEvent.ACTION_MASK) {
      case (MotionEvent.ACTION_DOWN):
          Log.i(classID, "action down");
          return true;
      case (MotionEvent.ACTION_CANCEL):
          Log.i(classID, "action cancel");
          // never called
          return true;
      case (MotionEvent.ACTION_MOVE):
          Log.i(classID, "action move");
          return true;
      case (MotionEvent.ACTION_UP):
          Log.i(classID, "action up");
          Log.i(classID, "position: " + (int)event.getRawX() + "/" + (int)event.getRawY());
          return true;
      }
      return false;
  }
  </code></pre>