sartre's profileSartre·异教徒启事录PhotosBlogListsMore Tools Help

Blog


    July 16

    Android中的民国历史

    近日,研习Android代码时,发现一件惊人的巧合。

    事情是这样的:Android中的Touch event处理方式和其他系统不尽相同。在Android中,一个View加入到一个ViewGroup中,当发生一系列Touch event(即触摸屏幕事件)时,这些事件首先经由ViewGroup中的onInterceptTouchEvent()函数来分派。这个函数决定touch event到底由View处理,还是由ViewGroup处理。它有一个boolean型的返回值,当返回true的时候,则由ViewGroup处理;反之返回false,由View来处理。这本身没有问题。但是这个函数有个特点,那就是如果某一次返回的是true,则从这以后的所有touch event都不需要再经过onInterceptTouchEvent()的分配,而统一都交由ViewGroup处理;如果返回的是false,这次的事件交View处理,下次的event仍然需要由onInterceptTouchEvent()分配,以决定分配给谁。

    这样的叙述对于不熟悉Android系统的人来说,估计和天书无异,我不如讲个故事。从前,有二十个海盗组成的一个海贼团,经常掠夺海岸的村庄。每次得手之后,他们都会把所得的猎物堆在一起,一件一件的挑。在一次出海时,他们袭击了一艘由佛罗伦萨出海的商船,船长与船员都被俘虏。海贼提出一个条件:船长和海贼中最擅长赌博的一个人玩色子,如果船长赢一局,一个船员便能得救。船长无奈,只好答应。于是第一局,船长救出了一个同伴,第二局,又救出一个。到了第三局,海贼赢了,于是他们杀掉了剩下所有的人。

    这个故事里,ViewGroup就是海贼。

    其实这和中国历史上的一件事情有着惊人的相似。1913年,袁世凯召集民国众议员一起投票选举中华民国大总统。国民宪法规定,大总统须得票四分之三方可当选,但是投票的结果是,袁世凯没有足够的票数,无法当选。于是他宣布投票结果无效,重新选举,并调派军警围住国会,任何人不得出入。直至深夜,议员一个个饥肠辘辘,人困马乏,终于在某此投票中达到了宪法要求的票数,于是他很高兴的宣布他本人就任,众人在梦中高呼着“总统万岁”,一边直奔东来顺而去。

    在这个故事里,ViewGroup就是袁世凯。

    Android里的这段代码是何人所做暂时无法考证,但是为熟悉民国历史的人的可能性很高。在考察ViewGroup和View的关系时,我们可以隐隐的感觉到,他们的关系多少有一点上下级关系的影子。是否这段代码是在控诉公司高管层如袁世凯一般的霸权?这估计只有当事人才能知晓了。

    Comments (2)

    Please wait...
    Sorry, the comment you entered is too long. Please shorten it.
    You didn't enter anything. Please try again.
    Sorry, we can't add your comment right now. Please try again later.
    To add a comment, you need permission from your parent. Ask for permission
    Your parent has turned off comments.
    Sorry, we can't delete your comment right now. Please try again later.
    You've exceeded the maximum number of comments that can be left in one day. Please try again in 24 hours.
    Your account has had the ability to leave comments disabled because our systems indicate that you may be spamming other users. If you believe that your account has been disabled in error please contact Windows Live support.
    Complete the security check below to finish leaving your comment.
    The characters you type in the security check must match the characters in the picture or audio.

    To add a comment, sign in with your Windows Live ID (if you use Hotmail, Messenger, or Xbox LIVE, you have a Windows Live ID). Sign in


    Don't have a Windows Live ID? Sign up

    awrote:
    生动地解释和类比让不熟悉Android系统的人也窥见其海盗一般的精髓,高! o(∩_∩)o...哈哈
    Aug. 17
    瑞 端wrote:
    联想真是丰富。佩服佩服。
    July 20

    Trackbacks

    The trackback URL for this entry is:
    http://sartrev.spaces.live.com/blog/cns!5FAE339907E55A68!2034.trak
    Weblogs that reference this entry
    • None