Android 4.0 Launcher source code analysis series (1)

Source: Internet
Author: User

First, we will analyze the Launcher layout as a whole. Let's have an understanding of the overall structure of Launcher by viewing Launcher. xml and using the combination of hierarchyviewer layout viewing tool. Use hierarchyviewer to complete the entire desktop as follows:
 

Zoom in as follows: You can see the elements contained in the entire desktop. The top is the Google search box, the bottom is a always plug-in, the icon, a separator, And the dock. Please note that the desktop program does not actually contain desktop wallpapers. In fact, desktop wallpapers are provided by WallpaperManagerService. The whole desktop is actually a layer that is superimposed on the entire desktop wallpaper.

 

The entire Launcher. xml layout file is as follows:
1. <com. android. launcher2.DragLayer
2. xmlns: android = "http://schemas.android.com/apk/res/android"
3. xmlns: launcher = "http://schemas.android.com/apk/res/com.android.launcher"
4.
5. android: id = "@ + id/drag_layer"
6. android: layout_width = "match_parent"
7. android: layout_height = "match_parent">
8.
9. <! -- Keep these behind the workspace so that they are not visible when
10. we go into AllApps -->
11. <include
12. android: id = "@ + id/dock_divider"
13. layout = "@ layout/workspace_divider"
14. android: layout_width = "match_parent"
15. android: layout_height = "wrap_content"
16. android: layout_marginBottom = "@ dimen/button_bar_height"
17. android: layout_gravity = "bottom"/>
18. <include
19. android: id = "@ + id/paged_view_indicator"
20. layout = "@ layout/scroll_indicator"
21. android: layout_width = "wrap_content"
22. android: layout_height = "wrap_content"
23. android: layout_gravity = "bottom"
24. android: layout_marginBottom = "@ dimen/button_bar_height"/>
25.
26. <! -- The workspace contains 5 screens of cells -->
27. <com. android. launcher2.Workspace
28. android: id = "@ + id/workspace"
29. android: layout_width = "match_parent"
30. android: layout_height = "match_parent"
31. android: paddingTop = "@ dimen/qsb_bar_height_inset"
32. android: paddingBottom = "@ dimen/button_bar_height"
33. launcher: defaultScreen = "2"
34. launcher: cellCountX = "4"
35. launcher: cellCountY = "4"
36. launcher: pageSpacing = "@ dimen/workspace_page_spacing"
37. launcher: scrollIndicatorPaddingLeft = "@ dimen/workspace_divider_padding_left"
38. launcher: scrollIndicatorPaddingRight = "@ dimen/workspace_divider_padding_right">
39.
40. <include android: id = "@ + id/cell1" layout = "@ layout/workspace_screen"/>
41. <include android: id = "@ + id/cell2" layout = "@ layout/workspace_screen"/>
42. <include android: id = "@ + id/cell3" layout = "@ layout/workspace_screen"/>
43. <include android: id = "@ + id/cell4" layout = "@ layout/workspace_screen"/>
44. <include android: id = "@ + id/cell5" layout = "@ layout/workspace_screen"/>
45. </com. android. launcher2.Workspace>
46.
47. <include layout = "@ layout/hotseat"
48. android: id = "@ + id/hotseat"
49. android: layout_width = "match_parent"
50. android: layout_height = "@ dimen/button_bar_height_plus_padding"
51. android: layout_gravity = "bottom"/>
52.
53. <include
54. android: id = "@ + id/qsb_bar"
55. layout = "@ layout/qsb_bar"/>
56.
57. <include layout = "@ layout/pai_customize_pane"
58. android: id = "@ + id/apps_customize_pane"
59. android: layout_width = "match_parent"
60. android: layout_height = "match_parent"
61. android: visibility = "invisible"/>
62.
63. <include layout = "@ layout/workspace_cling"
64. android: id = "@ + id/workspace_cling"
65. android: layout_width = "match_parent"
66. android: layout_height = "match_parent"
67. android: visibility = "gone"/>
68.
69. <include layout = "@ layout/folder_cling"
70. android: id = "@ + id/folder_cling"
71. android: layout_width = "match_parent"
72. android: layout_height = "match_parent"
73. android: visibility = "gone"/>
74. </com. android. launcher2.DragLayer>
The root of the Launcher layout is DragLayer, which inherits FrameLayout. Therefore, DragLayer can be considered as a FrameLayout. The following is dock_divider. It uses the include keyword to include another layout file workspace_divider.xml, and this workspace_divider.xml contains an ImageView. In fact, dock_divider is the line above the dock area.
The following is paged_view_indicator, which also contains scroll_indicator.xml, which contains an ImageView and displays a. 9 png file. It is actually the blue page indicator when the Launcher rolls pages.
Then, the core container WorkSpace on the desktop, as shown in, of course, you only see a part of the Workspace, which is actually a workspace_screen, through Launcher. xml shows that the entire workspace is composed of five workspace_screens. Each workspace_screen is a page corresponding to the desktop. Each workspace_screen contains a CellLayout, which is a custom control inherited from the ViewGroup. Therefore, it is a layout control, it is mainly used to hold the desktop icons, widgets, and folders on each page.
 


By viewing the following layout structure (because the figure is too large, only a part is taken), we can see that the Workspace contains five CellLayout numbers ranging from 0 to 4.

 

Next is a Hotseat, which is actually the dock area. :
 


As shown in the following figure, this Hotseat actually contains a CellLayout, which is used to hold four icons and the buttons for starting all programs in the middle.

 

The qsb_bar is the top Google search box on the screen. The search box is independent of the icon interface, so when we flip the desktop, the search box will remain unchanged at the top, as shown below:
 

Then there are three hidden interfaces during initialization.
Apps_customize_pane: Click the show all applications button in the dock to switch from the hidden state to the display state, as shown in. The interface for all applications and all plug-ins is displayed.
 

By viewing pai_customize_pane.xml, we can see that pai_customize_pane is mainly composed of two parts: tabs_container and tabcontent. The tabs section is used to select whether to add an application or a widget, as shown in:
 
Tabcontent. After the corresponding tab is selected, the following section displays the application or widget, as shown in:
 

 
Workspace_cling and folder_cling are the wizard interface displayed when you enter the desktop after the machine is flushed. This shows how to use workspace and folder. They will not appear again after being skipped.
Author: LuoXianXion
 

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.