2023-01-26 17:13:03 -08:00
|
|
|
/*
|
|
|
|
|
* Copyright (C) 2023 The Android Open Source Project
|
|
|
|
|
*
|
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
|
*
|
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
|
*
|
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
|
* limitations under the License.
|
|
|
|
|
*/
|
|
|
|
|
package com.android.launcher3.celllayout;
|
|
|
|
|
|
2023-03-10 10:50:37 -08:00
|
|
|
import static com.android.launcher3.LauncherSettings.Favorites.CONTAINER_DESKTOP;
|
|
|
|
|
|
2023-01-26 17:13:03 -08:00
|
|
|
import android.view.View;
|
|
|
|
|
|
|
|
|
|
import com.android.launcher3.CellLayout;
|
|
|
|
|
import com.android.launcher3.Launcher;
|
|
|
|
|
import com.android.launcher3.views.DoubleShadowBubbleTextView;
|
|
|
|
|
|
|
|
|
|
import java.util.ArrayList;
|
2023-01-10 10:47:46 -06:00
|
|
|
import java.util.List;
|
2023-01-26 17:13:03 -08:00
|
|
|
|
|
|
|
|
public class CellLayoutTestUtils {
|
|
|
|
|
|
|
|
|
|
public static ArrayList<CellLayoutBoard> workspaceToBoards(Launcher launcher) {
|
|
|
|
|
ArrayList<CellLayoutBoard> boards = new ArrayList<>();
|
|
|
|
|
for (CellLayout cellLayout : launcher.getWorkspace().mWorkspaceScreens) {
|
2023-03-10 10:50:37 -08:00
|
|
|
|
2023-01-26 17:13:03 -08:00
|
|
|
int count = cellLayout.getShortcutsAndWidgets().getChildCount();
|
|
|
|
|
for (int i = 0; i < count; i++) {
|
|
|
|
|
View callView = cellLayout.getShortcutsAndWidgets().getChildAt(i);
|
|
|
|
|
CellLayoutLayoutParams params =
|
|
|
|
|
(CellLayoutLayoutParams) callView.getLayoutParams();
|
2023-03-10 10:50:37 -08:00
|
|
|
|
|
|
|
|
CellPosMapper.CellPos pos = launcher.getCellPosMapper().mapPresenterToModel(
|
|
|
|
|
params.getCellX(), params.getCellY(),
|
|
|
|
|
launcher.getWorkspace().getIdForScreen(cellLayout), CONTAINER_DESKTOP);
|
|
|
|
|
int screenId = pos.screenId;
|
2023-07-26 15:09:10 -07:00
|
|
|
for (int j = boards.size(); j <= screenId; j++) {
|
2023-07-10 10:57:23 -07:00
|
|
|
boards.add(new CellLayoutBoard(cellLayout.getCountX(), cellLayout.getCountY()));
|
2023-03-10 10:50:37 -08:00
|
|
|
}
|
|
|
|
|
CellLayoutBoard board = boards.get(screenId);
|
2023-01-26 17:13:03 -08:00
|
|
|
// is icon
|
|
|
|
|
if (callView instanceof DoubleShadowBubbleTextView) {
|
2023-03-10 10:50:37 -08:00
|
|
|
board.addIcon(pos.cellX, pos.cellY);
|
2023-01-26 17:13:03 -08:00
|
|
|
} else {
|
|
|
|
|
// is widget
|
2023-07-10 10:57:23 -07:00
|
|
|
board.addWidget(pos.cellX, pos.cellY, params.cellHSpan,
|
2023-01-10 10:47:46 -06:00
|
|
|
params.cellVSpan);
|
2023-01-26 17:13:03 -08:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return boards;
|
|
|
|
|
}
|
2023-01-10 10:47:46 -06:00
|
|
|
|
|
|
|
|
public static CellLayoutBoard viewsToBoard(List<View> views, int width, int height) {
|
|
|
|
|
CellLayoutBoard board = new CellLayoutBoard();
|
|
|
|
|
board.mWidth = width;
|
|
|
|
|
board.mHeight = height;
|
|
|
|
|
|
|
|
|
|
for (View callView : views) {
|
|
|
|
|
CellLayoutLayoutParams params = (CellLayoutLayoutParams) callView.getLayoutParams();
|
|
|
|
|
// is icon
|
|
|
|
|
if (callView instanceof DoubleShadowBubbleTextView) {
|
|
|
|
|
board.addIcon(params.getCellX(), params.getCellY());
|
|
|
|
|
} else {
|
|
|
|
|
// is widget
|
|
|
|
|
board.addWidget(params.getCellX(), params.getCellY(), params.cellHSpan,
|
|
|
|
|
params.cellVSpan);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
return board;
|
|
|
|
|
}
|
2023-01-26 17:13:03 -08:00
|
|
|
}
|