public boolean dispatchTouchEvent(MotionEvent ev) {
if (ev.getAction() == MotionEvent.ACTION_DOWN) {
onUserInteraction();
}
if (getWindow().superDispatchTouchEvent(ev)) {
return true;
}
return onTouchEvent(ev);
}
public boolean superDispatchTouchEvent(MotionEvent ev) {
return mDecor.superDispatchTouchEvent(event);
}
//Handle an initial down.
if (actionMasked == MotionEvent.ACTION_DOWN) {
//Throw away all previous state when starting a new touch gesture.
//The framework may have dropped the up or cancel event for the previous gesture due to an app switch, ANR, or some other state change.
cancelAndClearTouchTargets(ev);
resetTouchState();
}
//Check for interception.
final boolean intercepted;
if (actionMasked == MotionEvent.ACTION_DOWM || mFirstTouchTarget != null) {
final boolean disallowIntercept = (mGroupFlags & FLAG_DISALLOW_INTERCEPT) != 0;
if (!disallowIntercept) {
intercepted = onInterceptTouchEvent(ev);
ev.setAction(action); //restore action in case it was changed
} else {
intercepted = false;
}
} else {
//There are no touch targets and this action is not an initial down so this view group continues to intercept touches.
intercept =true;
}
final boolean canceled = resetCancelNextUpFlag(this) || actionMasked == MotionEvent.ACTION_CANCEL;
final boolean split = (mGroupFlags & FLAG_SPLIT_MOTION_EVENTS) != 0;
TouchTarget newTouchTarget = null;
boolean alreadyDispatchedToNewTouchTarget = false;
if (!canceled && !intercepted) {
// 不是ACTION_CANCEL并且不拦截
if (actionMasked == MotionEvent.ACTION_DOWN) {
// 若当前事件为ACTION_DOWN则去寻找这次事件新出现的touch target
final int actionIndex = ev.getActionIndex(); // always 0 for down
...
final int childrenCount = mChildrenCount;
if (newTouchTarget == null && childrenCount != 0) {
// 根据触摸的坐标寻找能够接收这个事件的touch target
final float x = ev.getX(actionIndex);
final float y = ev.getY(actionIndex);
final View[] children = mChildren;
// 遍历所有子View
for (int i = childrenCount - 1; i >= 0; i--) {
final int childIndex = i;
final View child = children[childIndex];
// 寻找可接收这个事件并且touch事件坐标在其区域内的子View
if (!canViewReceivePointerEvents(child) || !isTransformedTouchPointInView(x, y, child, null)) {
continue;
}
newTouchTarget = getTouchTarget(child); // 找到了符合条件的子View,赋值给newTouchTarget
if (newTouchTarget != null) {
//Child is already receiving touch within its bounds.
//Give it the new pointer in addition to ones it is handling.
newTouchTarget.pointerIdBits |= idBitsToAssign;
break;
}
resetCancelNextUpFlag(child);
// 把ACTION_DOWN事件传递给子组件进行处理
if (dispatchTransformedTouchEvent(ev, false, child, idBitsToAssign)) {
//Child wants to receive touch within its bounds.
mLastTouchDownTime = ev.getDownTime();
if (preorderedList != null) {
//childIndex points into presorted list, find original index
for (int j=0;j<childrenCount;j++) {
if (children[childIndex]==mChildren[j]) {
mLastTouchDownIndex=j;
break;
}
}
} else {
mLastTouchDownIndex = childIndex;
}
mLastTouchDownX = ev.getX();
mLastTouchDownY = ev.getY();
//把mFirstTouchTarget赋值为newTouchTarget,此子View成为新的touch事件的起点
newTouchTarget = addTouchTarget(child, idBitsToAssign);
alreadyDispatchedToNewTouchTarget = true;
break;
}
}
}
}
}
if (child == null) {
handled = super.dispatchTouchEvent(event);
} else {
handled = child.dispatchTouchEvent(event);
}
if (mFirstTouchTarget == null) {
handled = dispatchTransformedTouchEvent(ev, canceled, null, TouchTarget.ALL_POINTER_IDS);
}
public boolean dispatchTouchEvent(MotionEvent event) {
boolean result = false;
. . .
if (onFilterTouchEventForSecurity(event)) {
//noinspection SimplifiableIfStatement
ListenerInfo li = mListenerInfo;
if (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED
&& li.mOnTouchListener.onTouch(this, event)) {
result = true;
}
if (!result && onTouchEvent(event)) {
result = true;
}
. . .
return result;
}
if (((viewFlags & CLICKABLE) == CLICKABLE || (viewFlags & LONG_CLICKABLE) == LONG_CLICKABLE)) {
switch (event.getAction()) {
case MotionEvent.ACTION_UP:
boolean prepressed = (mPrivateFlags & PFLAG_PREPRESSED) != 0;
if ((mPrivateFlags & PFLAG_PRESSED) != 0 || prepressed) {
. . .
if (!mHasPerformedLongPress) {
//This is a tap, so remove the longpress check
removeLongPressCallback();
//Only perform take click actions if we were in the pressed state
if (!focusTaken) {
//Use a Runnable and post this rather than calling performClick directly.
//This lets other visual state of the view update before click actions start.
if (mPerformClick == null) {
mPerformClck = new PeformClick();
}
if (!post(mPerformClick)) {
performClick();
}
}
}
. . .
}
break;
}
. . .
return true;
}
public boolean performClick() {
final boolean result;
final ListenerInfo li = mListenerInfo;
if (li != null && li.mOnClickListener != null) {
playSoundEffect(SoundEffectConstants.CLICK);
li.mOnClickListener.onClick(this);
result = true;
} else {
result = false;
}
sendAccessibilityEvent(AccessibilityEvent.TYPE_VIEW_CLICKED);
return result;
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2025 源码网商城 (www.ymwmall.com) 版权所有