/**
* Called to process touch screen events. You can override this to
* intercept all touch screen events before they are dispatched to the
* window. Be sure to call this implementation for touch screen events
* that should be handled normally.
*
* @param ev The touch screen event.
*
* @return boolean Return true if this event was consumed.
*/
// Activity 对于callBack 接口方法的实现
public boolean dispatchTouchEvent(MotionEvent ev) {
// down 事件 回调onUserInteraction() ,空方法
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
onUserInteraction();
}
// getWindoe() 返回的就是PhoneWindow 实例
// 直接调用PhoneWindow的方法
if (getWindow().superDispatchTouchEvent(ev)) {
return true;
}
// 如果前面分发过程中国呢的事件没有被处理,那么调用Activity自身的方法对事件进行处理
return onTouchEvent(ev);
}
/**
* Called when a touch screen event was not handled by any of the views
* under it. This is most useful to process touch events that happen
* outside of your window bounds, where there is no view to receive it.
*
* @param event The touch screen event being processed.
*
* @return Return true if you have consumed the event, false if you haven't.
* The default implementation always returns false.
*/
public boolean onTouchEvent(MotionEvent event) {
if (mWindow.shouldCloseOnTouch(this, event)) {
finish();
return true;
}
return false;
}
|