preface

Nice to meet you 👋

I am not big, but I believe I am on the way to become a big | I combined with their own experience in Denver annual essay expounds his method of thinking and practice in learning. Simply put, I think learning needs to establish a set of systematic knowledge system (knowledge tree), on the basis of which learning can be divided into general learning and demand learning. This article will briefly discuss the process of knowledge acquisition and practice content creation based on each stage of the process.

Master the three stages of knowledge

In my opinion, the mastery of knowledge needs to go through the following process:

  • Stage of perceptual knowledge
  • Stage of rational knowledge
  • Practice stage

Perceptual knowledge can be regarded as a process from 0 to 1, which is the primary stage of knowledge. In this process, learners often seek out existing materials (such as books, forums, blogs, videos, etc.). Creating content about perceptual knowledge is deceptively simple, but it’s actually very difficult. Here are some of the best zero-to-one content creators:

Click for details
  • Throwing objects line

    The main output content includes HenCoder (custom View), code start (Kotlin foundation, advanced, coroutine), paid video course HenCoder Plus, etc. Its content form is article + video, super language expression ability and natural photogenic performance.

  • KunMinX

    The main output content is refreshing Jetpack MVVM. , you are not used to RxJava, because the lack of this key, re-learn android column, etc. Concise style, very “avenue to simple” feeling.

  • But the plum smell

    The main output content is reflection series, which gives deep thinking to the knowledge system from the perspective of designers.

Rational knowledge is established on the basis of perceptual knowledge. In this process, learners usually establish a corresponding knowledge system in their mind and expand their thinking from 1 to N. In particular, it is through reading source code and other means to analyze the principle and summarize the existing knowledge system. It is easy to fall into the trap of the creator “talking to himself”, and the reader will feel “confused”.

The practice stage is the end and starting point of the whole process. This is because the process is not a simple linear structure, but a cyclic process.

Through specific practice, not only can avoid the awkward situation of “a listen will be, a do all waste”, or the sublimation of the previous stage of understanding, is the starting point of entering a higher level of understanding.

Today I’m going to use my knowledge of View’s event distribution mechanism as a starting point for content creation. The orientation of this paper is the stage of building perceptual knowledge.

Our ancestors planted trees for shade

As for the event distribution mechanism of View, the two best articles I wrote are as follows:

  • KunMinX’s learning View event distribution is like an out-of-towner on a black car!

  • But the reflection of the qing mei olfactory | Android event dispatch mechanism design and implementation

KunMinX’s style is clean and concise, with a clear understanding of the nature of View event distribution and the concept of “consumption” in the process.

But qingmei smell is standing in the designer’s point of View, elaborated the whole picture of event distribution, which View event distribution mechanism is only a link of UI layer event distribution.

Based on the theory in the previous section, the process of mastering the event distribution of a View can be broken down like this:

Perceptual cognition stage:

  • Confirm the knowledge’s position in the “knowledge tree” : it is part of the UI layer event distribution in Android

  • Model the content in your mind:

    1. The view tree in Android is an n-fork tree model
    2. N The bottommost node in the tree is the view closest to the user and has a higher priority in responding to user operations
    3. Responding to a user action is essentially looking for a specific node in an N-fork tree
    4. A common way to traverse an n-fork tree is recursion
    5. To improve performance, you can end the recursion early based on termination conditions
    6. To improve performance, you can use interception to avoid traversing all nodes at once
    7. .

The depth of perceptual knowledge is related to the level of knowledge learners are in. Perceptual knowledge → rational knowledge → practice is a circular process, so the depth of perceptual knowledge of learners at different stages is different.

Stage of rational knowledge:

After the model is established in the brain, some details can be learned. In this process, learners will think and learn from 1 to N to expansion:

For example, before viewing the source code implementation, if you do not know the traversal way of n-tree or do not understand the flow of recursive algorithm, it is likely to be confused by “consumption”, “return true” and other descriptions.

  • Learn the concept of recursion and how to write it
  • Learn a common approach to interception: the chain of responsibility pattern
  • See the specific source code implementation

Similarly, learners at different levels of knowledge have different depths of rational understanding. As a result, the source code can be read first by filtering out the details, sorting out the core logic (simple distribution + blocking), and then focusing on details that were previously overlooked (such as multi-fingering).

Practical stage:

Practice the previous knowledge, for example, customize ViewGroup and View, verify the previous learning content through logging and other means, and deepen the previous understanding in this process and enter the next cycle.

This article is positioned as the perceptual cognition stage, suitable for readers who do not have a clear understanding of View event distribution mechanism or do not know this content before.

Begin the text.

It’s a big workplace PUA

Strict hierarchy

A company has a strict hierarchy, modeled like an N-tree:

The company’s employees can be divided into two positions: View and ViewGroup.

  • View employees belong to the lowest level and have the least authority
  • The employee in the ViewGroup position can manage other employees (some are miserable and have no employees, such as ViewGroup4)
    • From the perspective of permissions: ViewGroup has its own special permissions (to manage subordinates) and View permissions
    • From the perspective of roles: when a ViewGroup acts as a superior, it acts as a ViewGroup; when it acts as a subordinate, it acts as a View

In addition to the generic positions mentioned above, there are some special “boss-level” positions:

  • ViewRootImpl: The company’s external business position, only. When a task comes in, it is first handed to ViewRootImpl, subordinate to DecorView
  • DecorView: Promoted position from ViewGroup, only. The subordinate arranges the ContentView for the eldest Activity
  • Activity: The boss of the company, the only. Subordinates to DecorView

The company has a strict hierarchy and a strict system of secrecy.

Strict confidentiality

Each employee can only communicate with his/her superior/subordinate, and the superior does not know the ability of the subordinate and the direction of excellence.

So, when a task comes up, the superior doesn’t know if the subordinate can handle it.

There are several such companies in the Android app world.

The process of processing tasks

Due to the previous institutional constraints, the processing process of the company after receiving the task can be abstracted as follows:

Starting at the root of the n-tree, traverse the entire n-tree to find a node that can handle the task.

The specific process of the company to deal with tasks is as follows:

  • A task is split into multiple instructionsIn other words, task is an abstract concept, and the real carrier is task instruction one by one
    • “Task start” instruction means that this is the start of a new task, and subsequent instructions are the instructions of that task
    • During the process of task progress, there will be multiple “task progress” instructions
    • The final task ends with the “End of task” command
  • In order to train employees, tasks are given priority to lower-level employees
  • The ViewGroup’s job is to receive a task order from a superior and have two options:
    1. Process the command directly by oneself, without notifying the subordinate (i.e. intercept), or without subordinate, can only process by oneself, and feedback the processing result to the superior (processing result OK or not OK)
    2. Notify the subordinate to process the instruction:
      • If the subordinate feedback processing result is OK, then directly to the superior (feedback result is OK)
      • If the subordinate feedback is not OK, it handles it itself (acting as the View) and reports back to the superior (OK or not OK)
  • After receiving the instruction from the superior, the View will process and feedback the processing result to the superior (the processing result is OK or not OK).
  • If the result is still not OK after traversing through the DecorView, the DecorView reports the task instruction to the eldest Activity

Interception process

The ViewGroup has the permission to intercept task commands, which can be divided into the following situations:

  • When the intercepted task command is “task start”, subordinates do not know the existence of the task, so the subsequent instructions of the task will not be handed over to subordinates
  • The ViewGrroup will take over the task when it is “task in progress” and notify its subordinates with a “Task cancel” command (don’t bother, I handled the task).

The ViewGroup has the permission to block tasks, so subordinates have no chance to perform. Therefore, the company grants subordinates the permission to reject superior interception

  • When a superior intercepts a task with the command “mission start”, subordinates are unaware of the existence of the task and therefore have no chance to use “Reject superior interception”.
  • When the superior interception task command is “task”, subordinates can “volunteer” to the superior, using “reject superior interception”, so that the superior interception is invalid

To optimize the

A task is composed of multiple task instructions. If each task instruction comes, all employees in the whole company should be traversed once, which will take too long.

So some optimizations can be made to reduce the number of traversals.

As shown in the figure above, if the processing result of “task start” ViewGroup4 of a task is OK, the subsequent instructions of the task can be directly handed to the branch of ViewGroup1 → ViewGruop4 (marked in red) without traversing the entire tree.

The demo

The figure above illustrates the case of not intercepting and traversing all nodes.

DecorView -> Activity -> The PhoneWindow process can be seen in the Section designing the Android Event distribution mechanism and Implementing the Dual Responsibilities of DecorView.

conclusion

  • The core of the event distribution mechanism of a View is to start from the root node of the n-fork tree and traverse the entire n-fork tree to find a node that can handle the event
  • The task-task instruction model corresponds to the “sequence of events” model:
    • Task start — ACTION_DOWN
    • missions — ACTION_MOVE
    • End of the task — ACTION_UP
    • Task to cancel — ACTION_CANCEL
  • Return true/false means that the result is OK/not OK
  • The upper ViewGroup has the interception capability, and the lower ViewGroup/View has the interception capability
  • If the ViewGroupTask start — ACTION_DOWNIf the task/event is blocked, the subordinate ViewGroup/View has no chance for the superior to cancel the interception
  • In order to improve performance, subsequent instructions of a task will preferentially use the path where the last traversal result was OK, corresponding to the TouchTarget (memory processor model in chain of Responsibility mode).

The next phase will enter the stage of rational understanding, introducing the recursive traversal of the N-fork tree, the common implementation of the chain of responsibility pattern, and View event distribution of the source brief analysis.

About me

I am Flywith24, and my blog content has been classified here. You can click Watch in the upper right corner to get updates of my articles in time, oh 😉

                   

         

At present, I am focusing on building a systematic knowledge system, and the content is updated on the Language finch. Interested parties can add excellent resources and technical details in the comments section at the bottom of relevant documents. Click to check it out.

View event distribution mechanism, large workplace PUA site | creator training camp The campaign is under way…