=========================
UPDATE: After several days googling and experiments, I have found the answers for most of those dumb questions. See the answers I submitted. >
Is Window responsible for collecting and dispatching the input?
No. ViewRoot is responsible for this.
What is the relationship between the view and window? Same as the relationship between surface and window in DFB?
?
What is the relationship between an activity and window? Will each activity have a window?
Yes, most of the time. However, a SurfaceView has its own window. So, if an Activity has a SurfaceView it will have more than one Window.
Is it possible to create a window from application? And when it is necessary?
Not necessary.
Does Android support multi-window?
Sure. Using HierachyView you can clearly see that there is more than one Window exists in the system.
1.What are the responsibilities of various classes, such as
Window
,View
,Canvas
,Surface
, and how do they collaborate with each other? 2.How many windows usually an Activity have?
Usually one.
3.Will all the views in one Activity will be attached to a window? What does attach mean? 4.Does every window have a surface? Does every canvas have a surface?
Every Window has a surface and Surface
uses Canvas
to draw on the surface.
5.View is responsible for managing focus/key events, while Canvas is only responsible for "drawing" operation?
YES.
6.
WindowManager
is responsible for Window stacking? How does that relate toSurfaceFlinger
?
Not Sure of WindowManager's responsibility. (TODO)
SurfaceFlinger
is used to compose the Surface that is associated with different Window/Activity.
7.View doesn't own a Surface, the Window the view contained owns?
View will draw on surface using Canvas. The window the view is attached to owns the surface.
This could be understood by implement a customize view, when you should override the onDraw(Canvas)
method in your derived class.
8.The View draws itself using canvas got by calling surface.lockCanvas()?
YES.
9.When and how is
onDraw(Canvas)
called, and who passes the canvas parameters?
onDraw()
will be called by the RootView
and when invalidate is called. The canvas parameter is passed from the RootView.
10.Does Canvas have a size? Will a Window's surface always be full screen?
I cannot say for sure. But when I create a customize view, the size of the canvas got from onDraw(Canvas) is full screen.
However, in my understanding, for performance sake, the Surface for the window should not always be full screen. But this assumption has not been verified. For example, the statusBar window should not be full screen.
1.Will every
Activity
have oneViewRoot
and thus oneWindow
?
YES.
2.Is there any need to create a window explicitly? Will the surface for the window always be full screen?
No need to create the Window explicitly per se.
3.Will status bar be in another Window?
YES.
4.What is the size of the surface? Will that always be full screen?