PopupWindow is notified of external touch events in the same way as all other touch events. When the flag is set outside the events redirected to the popup, and you can handle them the same way you handle touches. There is no special method for checking this external event or a set of listeners for such events. If you check the source code:
1341 @Override 1342 public boolean dispatchTouchEvent(MotionEvent ev) { 1343 if (mTouchInterceptor != null && mTouchInterceptor.onTouch(this, ev)) { 1344 return true; 1345 } 1346 return super.dispatchTouchEvent(ev); 1347 } 1348 1349 @Override 1350 public boolean onTouchEvent(MotionEvent event) { 1351 final int x = (int) event.getX(); 1352 final int y = (int) event.getY(); 1353 1354 if ((event.getAction() == MotionEvent.ACTION_DOWN) 1355 && ((x < 0) || (x >= getWidth()) || (y < 0) || (y >= getHeight()))) { 1356 dismiss(); 1357 return true; 1358 } else if (event.getAction() == MotionEvent.ACTION_OUTSIDE) { 1359 dismiss(); 1360 return true; 1361 } else { 1362 return super.onTouchEvent(event); 1363 } 1364 }
Now you can see that PopupWindow itself checks that the X / Y event is outside and is rejected. That way, you can set the TouchInterceptor to capture the event before or instead of the default handler. Or you can override onTouchEvent to do your own event handling and call super if that makes sense to you.
source share