Celllayout Class Analysis of Android Launcher

Source: Internet
Author: User

1) We all know that the workspace is composed of celllayout. Celllayout is divided into four rows and four columns. A boolean moccupied two-dimensional array is used to mark whether each cell is occupied. In attrs. XML, shortaxiscells and longaxiscells are defined to store the number of cells in the X axis and Y axis respectively. Initialize in the celllayout constructor.
2) The internal class cellinfo is a static class and implements the contextmenu. contextmenuinfo interface. The object is used to store basic cell information.
The vacantcell class is used to store idle cells and the synchronization mechanism is used to manage operations on idle locations. All empty cells are stored in vacantcells.
Cellx and celly are used to record the location of the cell. the start position is 0. For example: (0, 0) (0, 1). Each page is numbered from the beginning.
Clearvacantcells is used to clear vacant: release each cell and clear the list.
Findvacantcellsfromoccupied finds the idle cell from the cell value. Call the restorestate method in launcher. java.
3) mportrait indicates whether the screen is landscape or landscape. False indicates landscape. The default value is false.
4) modify the Cell Layout on the celllayout page:
The default number of cells on the celllayout page is 4x4 = 16. You can modify the configuration file.
In the celllayout (context, attributeset attrs, int defstyle) Construction Method of the celllayout. Java class, the mshortaxiscells and mlongaxiscells variables are used to store rows and columns.
The value is defined in the custom configuration file attrs. xml and assigned the initial value in workspace_screen.xml. The initial values are 4, that is, 4 rows and 4 columns. You can modify the corresponding value in workspace_screen.xml.
Note: In the celllayout constructor. the definition obtained in XML is as follows: mshortaxiscells =. getint (R. styleable. celllayout_shortaxiscells, 4); When workspace_screen.xml does not assign values to the defined variables, the above 4 takes effect.
5) The following analysis Reprinted from: http://blog.csdn.net/netpirate/archive/2009/06/05/4245445.aspx

Launcher (Main Screen/standby) app BUG: No Boolean parameter is initialized to define the screen direction in celllayout
Launcher app: \ cupcake \ packages \ apps \ Launcher
The standby screen is divided into multiple layers. The desktop items is set in \ res \ Layout-* \ workspace_screen.xml:
<Com. Android. launcher. celllayout
......
Launcher: shortaxiscells = "4"
Launcher: longaxiscells = "4"
......
/>
4 rows and 4 columns
Let's take a look at com. Android. launcher. celllayout, which has parameters defining the screen direction,
Private Boolean mportrait;
However, initialization has not been performed, that is, mportrait = false. Cell settings on the desktop are always initialized Based on Non-portrait (landscape) settings.
Let's take a look at the initialization differences between the landscape screen and the landscape screen to see the bug.
Boolean [] [] moccupied; // array of Boolean values of binary Cells
If (mportrait ){
Moccupied = new Boolean [mshortaxiscells] [mlongaxiscells];
} Else {
Moccupied = new Boolean [mlongaxiscells] [mshortaxiscells];
}
If the desktop is displayed on the full screen (the number of cells in the horizontal and vertical directions is different), instead of only four rows and four columns by default, mshortaxiscells = 4, mlongaxiscells = 5, array initialization should be: new Boolean [4] [5], but it is actually processed according to non-Portrait screen, initialized to new Boolean [5] [4], will generate an array out-of-bounds exception.
You can add mportrait initialization through the screen direction in the constructor. The Code is as follows:
Public celllayout (context, attributeset attrs, int defstyle)
{
Super (context, attrs, defstyle );
Mportrait = This. getresources (). getconfiguration (). Orientation = configuration. orientation_portrait; // Add code

 

 

 

 

Http://gqdy365.iteye.com/blog/875001

Http://www.cnblogs.com/mengshu-lbq/category/226349.html

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.