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 context, AttributeSet attrs, int defStyle)
{
Super (context, attrs, defStyle );
MPortrait = this. getResources (). getConfiguration (). orientation = Configuration. ORIENTATION_PORTRAIT; // Add code
......
}