Android MotionEvent: find out if motion happened outside the view
The MotionEvent.ACTION_OUTSIDE does not works for View's.
One solution is get the X and Y touch position and verify if it is inside the bounds of the View. It can be done like that:
@Override
public boolean onTouchEvent(MotionEvent e) {
if (isInside())
Log.i(TAG, "TOUCH INSIDE");
else
Log.i(TAG, "TOUCH OUTSIDE");
return true;
}
private boolean isInside(View v, MotionEvent e) {
return !(e.getX() < 0 || e.getY() < 0
|| e.getX() > v.getMeasuredWidth()
|| e.getY() > v.getMeasuredHeight());
}
That flag only applies to Windows, not Views. You will get ACTION_MOVE
when you move your finger off the View, the event stays in the View it originated with. Look at the source code for SeekBar
if you need clarification: even if you move your finger off the bar, the thumb still drags!
For doing this at the Window level use FLAG_WATCH_OUTSIDE_TOUCH
, it works just fine.