Android launcher-UI framework

Source: Internet
Author: User

Starting with laucher development, I personally think that we should first start with the UI framework, understand the UI framework and have a general understanding of laucher, and know where the key classes are, we will pave the way for further in-depth research. If you don't talk much about it, go to the topic:

1. first look at the figure

This is a 800*480 launcher UI framework that I am studying. The corresponding desktop display effect is as follows:

The following line of application is the result of my desktop modification, which is not shown in the previous UI framework diagram.
I will explain it one by one.
1. draglayer -- draglayer inherits framelayout and combines dragcontroller to implement drag and drop functions. draglayer monitors the following two user events.
Onintercepttouchevent
Ontouchevent
It is handed over to dragcontroller for processing. dragcontroller controls the drag-and-drop process of the control based on whether the control is in the drag-and-drop medium information.
Draglayer is the top-level view of the launcher activity. The launcher2 application only has one activity, that is, laucher. java.

 

2. deletezone -- enable launcher. xml. By default, deletezone is not displayed for Android: visibility = "invisible"
But every time we start to drag and drop the icon, deletezone is displayed. How is it implemented? Deletezone implements the dragcontroller. draglistener interface. draglistener provides two interface methods,
Ondragstart: Hide the handle and display deletezone
Ondragend: display the handle and hide deletezone.
It is called when dragcontroller starts drag-and-drop and ends the drag-and-drop respectively.
In addition, deletezone implements the droptarget interface. Once you drag the icon to deletezone, deletezone is called.
The ondrop method is used to delete the application icon.

 

3. clippedimageview-move the button between the left and right sides of the screen. The normal icon is very small and you can only see small points. I set the view background to non-transparent green as in front of my
Pay attention to three points for clippedimageview,
-- 1. The drawable transformation when the desktop moves left and right. You can view home_arrows_right.xml in the conversion icon list.
Clippedimageview transmits drawable to worksapce. When the desktop is switched, different icons are displayed by calling the drawable. setlevel function.
-- 2. Click clippedimageview to switch between left and right desktops and view the layout file of clippedimageview.
Android: onclick = "previusscreen", which defines a clippedimageview onclick event response function. The function is defined in the activity corresponding to the layout file.
That is, defined in launcher. java.
/**
* @ Description: Click the previous desktop button.
* @ Param v
* @ Others:
*/
@ Suppresswarnings ({"unuseddeclaration "})
Public void previusscreen (view v ){
If (! Isallpolicvisible ()){
Mworkspace. scrollleft ();
}
}
-- 3. added the long-press event onlongclicklistener to the clippedimageview initialization (launcher. setupviews). When the long-press clippedimageview, it will execute
Launcher. onlongclick method. The method execution shows the preview thumbnail display of five desktops. The specific implementation is not described in detail and will be further studied later.

 

4. relativelayout -- Android: Id = "@ + ID/all_assist_button_cluster", such as the gray vertical bar on the right side of the front, which is a relative layout object with three views
In the middle is a handleview, which is a button to enter the allappview. The top and bottom of the handleview are an imageview to enter the Google search.
-- Handleview
-- 1. Click the event to pass it to launcher. onclick to process and display the application menu view.
-- 2. The long-press event is passed to launcher. onlongclick for processing. The method execution displays the preview thumbnail of five desktops.
-- Google search imageview
-- Onclick response: Android: onclick = "launchhotseat"

 

5. allcategory 2D -- menu view, which is referenced in launcher. xml:
<Include
Layout = "@ layout/all_apps"/>
All_cmd.xml is defined as follows:
<Merge xmlns: Android = "http://schemas.android.com/apk/res/android">
<Include layout = "@ layout/all_assist_2d"/>
<! -- Include layout = "@ layout/all_assist_3d"/-->
</Merge>
A hierarchy is added in the middle. If necessary, you can define your own apps_3d layout.
All1_2d includes two views
-- 1. gridview Android: Id = "@ + ID/all_apps_2d_grid" Application menu grid view, which is a grid view used to place application icons
The implementation class of the adapter corresponding to the gridview is the external adapter, and the layout file of the adapter is application_boxed.xml.
-- 2. View Android: Id = "@ + ID/all_apps_2d_home" click the Home button on the right of the Application menu view and click hide all1_2d

 

6. Workspace-the user desktop includes five workspace_screens. The default display is Launcher: defaultscreen = "0"
Workspace inherits the viewgroup, and five workspace_screen are its child. It is worth noting that it only receives child of the celllayout type, and workspace overrides the addview function,
Adding a child with a non-celllayout will throw an exception.
-- The workspace long-press event is still monitored by launcher. onlongclick.
-- Workspace implements droptarget and dragsource interfaces, which means that workspace is both a drag-and-drop source and a drag-and-drop destination.
-- Workspace implements the dragscroller interface, which provides two methods
Void scrollleft ();
Void scrollright ();
Dragcontroller calls the drag-and-drop process to scroll left and right of the desktop.
-- A desktop layout in celllayout workspace. celllayout is also a subclass of viewgroup. The red area of my desktop above is celllayout.
Five celllayout files are arranged sequentially in the workspace. The layout file: Android: scrollbars = "horizontal" determines whether the five celllayout files are arranged horizontally or vertically.
Celllayout is divided into different cell spaces, and Boolean [] [] moccupied; is used to identify whether each cell is occupied. Check the layout file workspace_screen.xml of celllayout first:
<Com. Android. launcher2.celllayout
Xmlns: Android = "http://schemas.android.com/apk/res/android"
Xmlns: launcher = "http://schemas.android.com/apk/res/com.android.launcher"
Android: layout_width = "match_parent"
Android: layout_height = "match_parent"
Android: hapticfeedbackenabled = "true"
Launcher: cellwidth = "115dip" // The width of each cell
Launcher: cellheight = "100dip" // height of each cell
Launcher: longaxisstartpadding = "0dip" // The left margin of the cell from the parent view celllayout
Launcher: longaxisendpadding = "0dip" // cell to the right of the parent view celllayout
Launcher: shortaxisstartpadding = "0dip" // The upper margin of the cell from the parent view celllayout.
Launcher: shortaxisendpadding = "80dip" // cell distance from parent view celllayout bottom margin
Launcher: shortaxiscells = "3" // The number of celllayout cells rows for the horizontal screen
Launcher: longaxiscells = "5" // indicates the number of celllayout cells columns for the horizontal screen.
Android: Background = "# ff0000">
</COM. Android. launcher2.celllayout>
When the longitudinal controls are not arranged in cells, cells overlap and do not overlap horizontally. Each Horizontal Cell interval must be at least 0.
-- Celllayout overwrites the onmeasure method and the onlayout method. It limits the layout parameter type used by the Child view to celllayout. layoutparams. Therefore, it attempts to modify
Workspace_screen.xml cannot be used to change its desktop layout. You must modify the celllayout class.
-- Celllayout. layoutparams Description: Several members in celllayout. layoutparams need to describe it.
-- Cellx: the number of cells occupied by the Child view (if multiple cells are used horizontally, cellx on the leftmost side is used)
-- Celly: the number of rows of cells occupied by the Child view (if multiple cells are occupied vertically, the top celly is occupied)
-- Cellhspan: Number of columns that span horizontally
-- Cellvspan: the number of vertically crossed rows.
-- Isdragging: indicates whether the child is being dragged.
-- Regenerateid: whether to regenerate view ID

 

7. Four types of desktop icons
Iteminfo -- all types of parent classes
-- Applicationinfo: data representation of all application icons in the Application menu View
-- Folderinfo Desktop Folder
-- Userfolderinfo corresponds to the layout file R. layout. folder_icon
-- Livefolderinfo corresponds to the layout file R. layout. live_folder_icon
-- Launcherappwidgetinfo Desktop component
-- The shortcutinfo application shortcut corresponds to the layout file R. layout. Application

Original article: http://blog.csdn.net/stonecao/article/details/6462357

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.