1 /* 2 * Copyright (C) 2023 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 package com.android.launcher3.celllayout; 17 18 import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP; 19 20 import android.view.View; 21 22 import com.android.launcher3.CellLayout; 23 import com.android.launcher3.Launcher; 24 import com.android.launcher3.celllayout.board.CellLayoutBoard; 25 import com.android.launcher3.views.DoubleShadowBubbleTextView; 26 27 import java.util.ArrayList; 28 import java.util.List; 29 30 public class CellLayoutTestUtils { 31 workspaceToBoards(Launcher launcher)32 public static ArrayList<CellLayoutBoard> workspaceToBoards(Launcher launcher) { 33 ArrayList<CellLayoutBoard> boards = new ArrayList<>(); 34 for (CellLayout cellLayout : launcher.getWorkspace().mWorkspaceScreens) { 35 36 int count = cellLayout.getShortcutsAndWidgets().getChildCount(); 37 for (int i = 0; i < count; i++) { 38 View callView = cellLayout.getShortcutsAndWidgets().getChildAt(i); 39 CellLayoutLayoutParams params = 40 (CellLayoutLayoutParams) callView.getLayoutParams(); 41 42 CellPosMapper.CellPos pos = launcher.getCellPosMapper().mapPresenterToModel( 43 params.getCellX(), params.getCellY(), 44 launcher.getWorkspace().getCellLayoutId(cellLayout), CONTAINER_DESKTOP); 45 int screenId = pos.screenId; 46 for (int j = boards.size(); j <= screenId; j++) { 47 boards.add(new CellLayoutBoard(cellLayout.getCountX(), cellLayout.getCountY())); 48 } 49 CellLayoutBoard board = boards.get(screenId); 50 // is icon 51 if (callView instanceof DoubleShadowBubbleTextView) { 52 board.addIcon(pos.cellX, pos.cellY); 53 } else { 54 // is widget 55 board.addWidget(pos.cellX, pos.cellY, params.cellHSpan, 56 params.cellVSpan); 57 } 58 } 59 } 60 return boards; 61 } 62 viewsToBoard(List<View> views, int width, int height)63 public static CellLayoutBoard viewsToBoard(List<View> views, int width, int height) { 64 CellLayoutBoard board = new CellLayoutBoard(width, height); 65 66 for (View callView : views) { 67 CellLayoutLayoutParams params = (CellLayoutLayoutParams) callView.getLayoutParams(); 68 // is icon 69 if (callView instanceof DoubleShadowBubbleTextView) { 70 board.addIcon(params.getCellX(), params.getCellY()); 71 } else { 72 // is widget 73 board.addWidget(params.getCellX(), params.getCellY(), params.cellHSpan, 74 params.cellVSpan); 75 } 76 } 77 return board; 78 } 79 } 80