Launcher图标排列方式改成4*5时候,旋转时的图标排列

旋转后图标从0*0开始重新排列:

        int layoutcount = mWorkspace.getChildCount();
        
        for (int i=0; i < layoutcount; i++) {
            CellLayout layout = (CellLayout)mWorkspace.getChildAt(i);
            
            boolean[][] occupied = layout.getOccupiedCell();
            boolean[][] tmpoccupied = new boolean[5][5];
            for (int tmpi =0; tmpi < 4; tmpi++)
                for (int tmpj = 0; tmpj < 4; tmpj++) {
                	tmpoccupied[tmpi][tmpj] = occupied[tmpi][tmpj];
                }
            tmpoccupied[0][4] = tmpoccupied[1][4] = tmpoccupied[2][4] = tmpoccupied[3][4] = false;
            tmpoccupied[4][0] = tmpoccupied[4][1] = tmpoccupied[4][2] = tmpoccupied[4][3] = false;
            
            int viewcount = layout.getChildCount();
            for (int j=0; j < viewcount; j++) {
                View cell = layout.getChildAt(j);
                final ItemInfo info = (ItemInfo) cell.getTag();
                if (!(info instanceof LauncherAppWidgetInfo)) {
                    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
                    tmpoccupied[lp.cellX][lp.cellY] = false;
                }
            }
            
            //int viewcount = layout.getChildCount();
            for (int j=0; j < viewcount; j++) {
                View cell = layout.getChildAt(j);
                final ItemInfo info = (ItemInfo) cell.getTag();
                if (!(info instanceof LauncherAppWidgetInfo)) {
                    CellLayout.LayoutParams lp = (CellLayout.LayoutParams) cell.getLayoutParams();
out:                {
                    	if (NUMBER_CELLS_X == 5) {
	                    	for (int tmpi = 0; tmpi < 5; tmpi++)
		                        for (int tmpj = 0; tmpj < 4; tmpj++) {
		                            if (tmpoccupied[tmpj][tmpi] == false) {
		                            	//tmpoccupied[lp.cellX][lp.cellY] = false;
		                            	LauncherModel.moveItemInDatabase(this, info,
		                                          LauncherSettings.Favorites.CONTAINER_DESKTOP, i, tmpj, tmpi);
		                                tmpoccupied[tmpj][tmpi] = true;
		                                
		                                break out;
		                            }
		                        }
	                    }else if(NUMBER_CELLS_Y == 5) {
	                    	for (int tmpi = 0; tmpi < 4; tmpi++)
		                        for (int tmpj = 0; tmpj < 5; tmpj++) {
		                            if (tmpoccupied[tmpj][tmpi] == false) {
		                                LauncherModel.moveItemInDatabase(this, info,
		                                          LauncherSettings.Favorites.CONTAINER_DESKTOP, i, tmpj, tmpi);
		                                tmpoccupied[tmpj][tmpi] = true;
		                                //tmpoccupied[lp.cellX][lp.cellY] = false;
		                                break out;
		                            }
		                        }
	                    }
                    }
                }

posted on 2011-01-13 10:18  鲸鱼  阅读(1214)  评论(0)    收藏  举报

导航