Android series twenty-four -- home screen

Source: Internet
Author: User
Tags home screen

Home screen is the most important application of a mobile phone, just like the homepage of a portal website, which directly determines the user's first impression. The following is a brief analysis of home screen.

The home screen code is located in the packages/apps/launcher directory. The UI structure of home screen can be learned from the launcher. xml and workspace_screen.xml files, as shown in:


The whole homescreen is a framelayout (COM. Android. launcher. draglayer) containing three child views ).

The first child is the desktop com. Android. launcher. workspace. The desktop contains three more children. Each child corresponds to a desktop. This is the three desktops you see on Android. You can place the following objects on each desktop: Application shortcuts, appwidgets, and folder.

The second child is an slidingdrawer control, which consists of two child controls. One is com. android. launcher. handleview is the handle under the android desktop. When you click this handle, another sub-control, Com. android. launcher. allcategory gridview will pop up. This sub-control lists all types currently installed in the system as category. launcher activity.

The third child is com. Android. launcher. deletezone. When you press a widget on the desktop, a control in the shape of a waste bin will appear in the hand position.

Four types of objects can be placed on a virtual desktop:
1. item_shortcut, application shortcut
2. item_appwidget, app widget
3. item_live_folder, folder
4. item_wallpaper, wallpaper.

Class favorites (launchersettings. Java) and Class launcherprovider define a content provider to store several objects that can be placed on the desktop, including shortcut, search, and clock.

The class addadapter (addadapter. Java) lists the four types of objects. When the user is blank on the desktop, the following function sequence is executed:
Launcher: onlongclick -->
Launcher: showadddialog -->
Launcher: showdialog (dialog_create_shortcut); -->
Launcher: oncreatedialog -->
Launcher: createshortcut: createdialog: This function creates a pop-up dialog box asking users what they want to add (shortcuts, appwidgets, folders, and wallpapers). The content of this dialog box comes from addadapter.

Class favorites (launchersettings. Java) and Class launcherprovider define a content provider to store several objects that can be placed on the desktop, including shortcut, search, and clock.

The topitemsloader class extracts all objects on the desktop from the content provider.

The thread private applicationsloader mapplicationsloader obtains the list of installed applications from the package manager. (Then displayed on allcategory gridview ). Applicationsloader: Run implementation:
1) Use the Package Manager to list all types of activities in the system that are launcher and action is main;
2) for each activity,
     A) cache metadata information related to the activity, such as title, icon, and intent, to appinfocache;
     B) Fill in applicationsadapter. Some tips are used in the filling process. Update the corresponding view for every 4 (ui_notification_rate) activities.

In Launcher: oncreate, The startloaders function is called. This function then calls loadapplications and loaduseritems to obtain the System Application List and the list of objects (shortcuts, appwidgets, folder, etc.) displayed on the desktop ).

All the application icons arranged on the launcher are displayed by the allcategory gridview object. This object is a gridview. The corresponding adapter is applicationsadapter, and the corresponding model is the applicationinfo array. The array content is loaded by applicationsloader.
Private class applicationsloader implements runnable.


Class introduction: 
Addadapter: the adapter for adding desktop elements.
Allcategory gridview: the main interface of the icon list, which inherits the gridview.
Deletezone: the deletion region of luancher, inheriting imageview.
Dragcontroller: Drag Control Interface.
Draglayer: the parent node of the entire launcher. It inherits framelayout and implements the interface draycontroller.
Dragsource: The Drag Source interface defines void ondropcompleted (view target, Boolean success ).
Droptarget: drag the target to define the methods required for many drag processes: ondrop, ondragenter, ondragover, ondragexit, and acceptdrop.
Handleview: the switch of the launcher drawer, but the drawer is no longer used in android2.2.
Launcher: the entry of the entire launcher program. It is a file with the largest amount of code.
Workspace: layout. Several windows are subnodes under the workspace.

The launcher implements the MVC mode (M: launchermode, V: draglayer, C: launcher). Based on this, you can obtain the details of the launcher's management of each component (such as the implementation of drag ).

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.