InputDispatcher向InputChannel使用socket写入输入事件,触发InputEventReceiver调用来接收输入事件。
ViewPostImeInputStage处理view控件的事件
@frameworks/base/core/java/android/view/InputEventReceiver.java dispatchInputEvent
@frameworks/base/core/java/android/view/ViewRootImpl.javaonInputEvent(event);enqueueInputEvent(event, this, 0, true);if (processImmediately) { doProcessInputEvents(); }deliverInputEvent(q); //在deliverInputEvent函数中做输入事件的实际分发stage = q.shouldSkipIme() ? mFirstPostImeInputStage : mFirstInputStage; //这里开始选择 责任链的入口,具体请看InputStage的处理流程stage.deliver(q); //这里主要调用InputStage的deliver方法进行分发,InputStage代表了输入事件的处理阶段,使用责任链模式设计模式。result = onProcess(q); // EarlyPostImeInputStage::onProcessapply(q, result);if (result == FORWARD) { forward(q); } onDeliverToNext(q);mNext.deliver(q);result = onProcess(q); //NativePostImeInputStage::onProcessmNext.deliver(q);result = onProcess(q); //ViewPostImeInputStage::onProcessif((source & InputDevice.SOURCE_CLASS_POINTER) != 0) { return processPointerEvent(q); }
@frameworks/base/core/java/android/view/View.javaboolean handled = mView.dispatchPointerEvent(event);//MotionEvent { action=ACTION_DOWN, actionButton=0, id[0]=0, x[0]=692.0, y[0]=993.0, toolType[0]=TOOL_TYPE_FINGER, displayId=0, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=455777, downTime=455777, deviceId=-1, source=0x5002, eventId=-701920562 }}dispatchTouchEvent(event); if (mInputEventConsistencyVerifier != null) { mInputEventConsistencyVerifier.onTouchEvent(event, 0); }
@XrView.java//调用app setOnTouchListener(mTouchListener)注册的Listenerif (li != null && li.mOnTouchListener != null && (mViewFlags & ENABLED_MASK) == ENABLED && li.mOnTouchListener.onTouch(this, event)) {result = true;} return true; //返回true表示已经处理完成,不往下走,fasle则相反if (!result && onTouchEvent(event)) { result = true;} //调用app的onTouchEvent或者View.java的onTouchEvent//MotionEvent { action=ACTION_HOVER_MOVE, actionButton=0, id[0]=0, x[0]=664.80475, y[0]=407.85626, toolType[0]=TOOL_TYPE_MOUSE, displayId=0, buttonState=0, classification=NONE, metaState=0, flags=0x0, edgeFlags=0x0, pointerCount=1, historySize=0, eventTime=284960, downTime=284790, deviceId=3, source=0x2002, eventId=1040558423 }dispatchGenericMotionEvent(event);if (action == MotionEvent.ACTION_HOVER_ENTER || action == MotionEvent.ACTION_HOVER_MOVE || action == MotionEvent.ACTION_HOVER_EXIT) { if (dispatchHoverEvent(event)) }li.mOnHoverListener.onHover(this, event))
@MyApplication/app/src/main/java/com/example/myapplication/MainActivity.javapublic boolean onHover(View view, MotionEvent motionEvent) { return false; } //回调Button控件的onHoverdispatchGenericMotionEventInternal(event)onGenericMotionEvent(event)maybeUpdatePointerIcon(event);if (event.getActionMasked() != MotionEvent.ACTION_HOVER_EXIT) { if (!updatePointerIcon(event) && }InputManager.getInstance().setPointerIconType(pointerType); // pointerType = 1002, 鼠标样式由箭头变成小手