Android4.4 Input module notes, android4.4input

Source: Internet
Author: User

Android4.4 Input module notes, android4.4input

InputReader obtains input events from EventHub, including touch screen events and physical key events, and then transfers them to the InputDispatcher thread. InputDispatcher filters input events. For a touch event, call the findTouchedWindowTargetsLocked () function to find the appropriate InputTarget, and then use dispatchEventLocked ()-> preparedispatchreceivelocked ()-> unlock ()-> enqueueDispatchEntryLocked () -> connection-> outboundQueue. enqueueAtTail (dispatchEntry) is added to a queue in the connection that corresponds to InputTarget one by one. If no data exists in the queue and the current touch event has been successfully added to the queue, call the startdispatchreceivelocked () function for distribution. In startDispatchCycleLocked (), there is a while loop that extracts the input event from the connection-> outboundQueue queue. If the input event is a key event, call connection-> inputPublisher. publishKeyEvent () function. If it is a touch event, call connection-> inputPublisher. publishMotionEvent (). Both publishKeyEvent () and publishMotionEvent () call mChannel-> sendMessage () to send the input event. MChannel is a C ++ layer InputChannel object. The assignment process of this object is as follows: registerInputChannel ()-> new Connection-> Connection () constructor-> InputPublisher () constructor. In fact, before registerInputChannel () is called, ViewRootImple calls ViewRootImpl when adding a window. setView ()-> mWindowSession. addToDisplay ()-WindowManagerService. addWindow (): In addWindow (), a pair of InputChannel (Nativie layer) will be created. In fact, a pair of sockets will be created. The InputChanel on the server is registered by WMS to InputDispatcher, And the InputChannel on the client is returned to view, viewRootImpl uses the InputChannel client as the new InputEventReceiver object and continues to call the nativeInit () function in the InputEventReceiver () constructor to create a native layer NativeInputEventR Eceiver object. The client InputChannel created earlier is saved in this object.

Summary: WMS calls the native layer interface to create a pair of sockets. The server is saved in InputDispatcher, and the client is saved in nativeinputeventventer (android_view_inputEventReceiver.cpp ).

It is easy to think that the input event flows from InputDispatcher to NativeInputEventReceiver. After creating a native layer NativeInputEventReceiver object, NativeInputEventReceiver-> initialize () is called immediately. this function calls mMessageQueue-> getloaliz()-> addFd (fd, 0, events, this, NULL) Add the client socket handle to The logoff polling queue. The parameter this points to the nativeinputeventventer itself, meaning that as long as the server InputDispatcher sends an input event and the client receives the event, it calls a function of NativeInputEventReceiver, which of the following functions is called? NativeInputEventReceiver implements the LooperCallback interface function handleEvent (). However, the received event only indicates that the socket Client has an event and does not read the specific event.

Conclusion: when the client receives an input event, it calls the NativeInputEventReceiver-> handleEvent () function.

In the handleEvent () function, continue to call consumeEvents ()-> mInputConsumer. consume ()-> mChannel-> receiveMessage (& mMsg) read the specific input event, and then call env-> CallVoidMethod (receiverObj. get (), gInputEventReceiverClassInfo. dispatchInputEvent, seq, inputEventObj), you can know that the native layer reads the input event, and then calls back the java layer InputEventReceiver. the dispatchInputEvent () function in java. In fact,

DispatchInputEvent continues to call onInputEvent (event). At this time, it may not call the onininputevent () method in the InputEventReceiver class, but call the onInputEvent () method of the subclass. ViewRootImpl contains the mInputEventReceiver variable of the windowinputeventventer type. The WindowInputEventReceiver class inherits the inputeventventer class and implements the onInputEvent () method to conclude that the native layer socket Client reads the input event, finally, the onInputEvent () method of the InputEventReceiver class subclass is called, and ViewRootImpl inherits InputEventReceiver. onInputEvent () will be called.

Summary: for general touch screen events, the final handler is the ViewRootImpl class, and for the input rule processor is the IInputMethodSessionWrapper class. Of course, WMS will not process these input events.

Continue to study ViewRootImpl. the onInputEvent () function, onInputEvent ()-> doProcessInputEvents ()-> deliverInputEvent (), deliverInputEvent () function calls stage. deliver (q), stage is mFirstPostImeInputStage or mFirstInputStage. The two InputStage objects are assigned values in setView. The InputStage class design is the responsibility chain mode. Because touch events are distributed to specific views, the general touch events are finally transmitted to the ViewPostImeInputStage class for processing. The processing function is processPointerEvent (q). This function calls mView. dispatchPointerEvent (event) distributes events. What is mView? MView is actually a DecorView. Each window has only one DecorView, which is at the top layer. Because DecorView does not overwrite dispatchPointerEvent (), the dispatchPointerEvent () method of the View class of the parent class is called.

public final boolean dispatchPointerEvent(MotionEvent event) {        if (event.isTouchEvent()) {            return dispatchTouchEvent(event);        } else {            return dispatchGenericMotionEvent(event);        }    }
This method continues to call dispatchTouchEvent (event), and DecorView re-calls this method:

<span style="font-family:Microsoft YaHei;font-size:18px;">@Override        public boolean dispatchTouchEvent(MotionEvent ev) {            final Callback cb = getCallback();            return cb != null && !isDestroyed() && mFeatureId < 0 ? cb.dispatchTouchEvent(ev)                    : super.dispatchTouchEvent(ev);        }</span>

The getCallback () function gets the callback function registered with the apk to intercept events such as buttons and touch. Generally, window does not intercept and process touch events, so it will continue to call super. dispatchTouchEvent (ev), that is, the dispatchTouchEvent () function of the parent ViewGroup. In this function, find the corresponding View and call dispatchTransformedTouchEvent ()

<span style="font-family:Microsoft YaHei;font-size:18px;">                   for (int i = childrenCount - 1; i >= 0; i--) {                            final int childIndex = customOrder ?                                    getChildDrawingOrder(childrenCount, i) : i;                            final View child = children[childIndex];                            if (!canViewReceivePointerEvents(child)                                    || !isTransformedTouchPointInView(x, y, child, null)) {                                continue;                            }                            newTouchTarget = getTouchTarget(child);                            if (newTouchTarget != null) {                                // Child is already receiving touch within its bounds.                                // Give it the new pointer in addition to the ones it is handling.                                newTouchTarget.pointerIdBits |= idBitsToAssign;                                break;                            }                            resetCancelNextUpFlag(child);                            if (dispatchTransformedTouchEvent(ev, false, child, idBitsToAssign)) {                                // Child wants to receive touch within its bounds.                                mLastTouchDownTime = ev.getDownTime();                                mLastTouchDownIndex = childIndex;                                mLastTouchDownX = ev.getX();                                mLastTouchDownY = ev.getY();                                newTouchTarget = addTouchTarget(child, idBitsToAssign);                                alreadyDispatchedToNewTouchTarget = true;                                break;                            }                       }</span>
Specific Distribution Rules can be researched on your own.


After all the android development environments are built, why does AVD's target only support android44 and cannot select other

Open your sdkManage and download the sdks of other versions. It is estimated that you only downloaded the 4.4
 
Input type in android Development

Originally, positive and negative numbers are supported.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.