вторник, 28 октября 2008 г.

Views & Windows

Finally, I sorted out relations between View, IWindow (and other IWindow* interfaces) and Window.
Assorted facts:
  • Window (and its descendant, PhoneWindow) is just fancy way to control decor view of main 'window'. Decor view consists of title, progress, frame, etc.
  • IWindow, despite its apparent relation to Window, has nothing to do with it. It is (IPC) callback from WindowManagerService (accessible via IWindowManager/IWindowSession).
  • IWindow is used in ViewRoot (which is a hidden class implementing ViewParent). It is ViewRoot, not Window, that receives key events and draws views.
  • When activity starts it creates Window, loads appropriate decor view, and adds decor view to WindowManagerService (via WindowManager).
  • WindowManager. Uh oh. Not related to IWindowManager. Despite being ViewManager descendant, expects WindowManager.LayoutAttributes as parameters to its methods. WindowManager creates ViewRoot for each added view. ViewRoot communicates with WindowManagerService and adds new 'window' to it.
  • You can add your own top-level view (see Toast widget code).
I think windowing part of Android is a total mess. They should have named classes more carefully.

And it gets even worse for me, as I need to name a class which is neither Window, nor IWindow, nor View. This class will be *real* window, much like WindowManagerService.WindowState. It named ViewRoot2 for now :)

Комментариев нет: