diff --git a/tests/Android.bp b/tests/Android.bp index 8725b46f69..84c3951199 100644 --- a/tests/Android.bp +++ b/tests/Android.bp @@ -33,8 +33,8 @@ filegroup { filegroup { name: "launcher-image-tests-src", srcs: [ - "src/com/android/launcher3/celllayout/TestWorkspaceBuilder.java", - "src/com/android/launcher3/celllayout/CellLayoutBoard.java", + "src/com/android/launcher3/celllayout/board/*.java", + "src/com/android/launcher3/celllayout/board/*.kt", "src/com/android/launcher3/celllayout/FavoriteItemsTransaction.java", "src/com/android/launcher3/ui/AbstractLauncherUiTest.java", "src/com/android/launcher3/ui/PortraitLandscapeRunner.java", diff --git a/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java b/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java index 86a7bd3df0..1fe02b2058 100644 --- a/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java +++ b/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java @@ -21,6 +21,7 @@ import android.view.View; import com.android.launcher3.CellLayout; import com.android.launcher3.Launcher; +import com.android.launcher3.celllayout.board.CellLayoutBoard; import com.android.launcher3.views.DoubleShadowBubbleTextView; import java.util.ArrayList; diff --git a/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java b/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java index 91a0634f3d..2108eeefb8 100644 --- a/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java +++ b/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java @@ -31,6 +31,9 @@ import androidx.test.filters.SmallTest; import com.android.launcher3.CellLayout; import com.android.launcher3.DeviceProfile; import com.android.launcher3.InvariantDeviceProfile; +import com.android.launcher3.celllayout.board.CellLayoutBoard; +import com.android.launcher3.celllayout.board.IconPoint; +import com.android.launcher3.celllayout.board.WidgetRect; import com.android.launcher3.util.ActivityContextWrapper; import com.android.launcher3.views.DoubleShadowBubbleTextView; @@ -112,12 +115,12 @@ public class ReorderAlgorithmUnitTest { // The views have to be sorted or the result can vary board.getIcons() .stream() - .map(CellLayoutBoard.IconPoint::getCoord) + .map(IconPoint::getCoord) .sorted(Comparator.comparing(p -> ((Point) p).x).thenComparing(p -> ((Point) p).y)) .forEach(p -> addViewInCellLayout(cl, p.x, p.y, 1, 1, false)); board.getWidgets().stream() - .sorted(Comparator.comparing(CellLayoutBoard.WidgetRect::getCellX) - .thenComparing(CellLayoutBoard.WidgetRect::getCellY)) + .sorted(Comparator.comparing(WidgetRect::getCellX) + .thenComparing(WidgetRect::getCellY)) .forEach(widget -> addViewInCellLayout(cl, widget.getCellX(), widget.getCellY(), widget.getSpanX(), widget.getSpanY(), true)); diff --git a/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTestCase.java b/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTestCase.java index 4274130702..3dc503019d 100644 --- a/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTestCase.java +++ b/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTestCase.java @@ -15,6 +15,8 @@ */ package com.android.launcher3.celllayout; +import com.android.launcher3.celllayout.board.CellLayoutBoard; + import java.util.Iterator; /** diff --git a/tests/src/com/android/launcher3/celllayout/ReorderTestCase.java b/tests/src/com/android/launcher3/celllayout/ReorderTestCase.java index ed84a60fae..0c1403ff42 100644 --- a/tests/src/com/android/launcher3/celllayout/ReorderTestCase.java +++ b/tests/src/com/android/launcher3/celllayout/ReorderTestCase.java @@ -17,6 +17,8 @@ package com.android.launcher3.celllayout; import android.graphics.Point; +import com.android.launcher3.celllayout.board.CellLayoutBoard; + import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; diff --git a/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java b/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java index 3d388d6096..72de8858a2 100644 --- a/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java +++ b/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java @@ -32,6 +32,9 @@ import androidx.test.filters.SmallTest; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherAppState; import com.android.launcher3.MultipageCellLayout; +import com.android.launcher3.celllayout.board.CellLayoutBoard; +import com.android.launcher3.celllayout.board.TestWorkspaceBuilder; +import com.android.launcher3.celllayout.board.WidgetRect; import com.android.launcher3.tapl.Widget; import com.android.launcher3.tapl.WidgetResizeFrame; import com.android.launcher3.ui.AbstractLauncherUiTest; @@ -118,12 +121,12 @@ public class ReorderWidgets extends AbstractLauncherUiTest { return getFromLauncher(CellLayoutTestUtils::workspaceToBoards); } - private CellLayoutBoard.WidgetRect getWidgetClosestTo(Point point) { + private WidgetRect getWidgetClosestTo(Point point) { ArrayList workspaceBoards = workspaceToBoards(); int maxDistance = 9999; - CellLayoutBoard.WidgetRect bestRect = null; + WidgetRect bestRect = null; for (int i = 0; i < workspaceBoards.get(0).getWidgets().size(); i++) { - CellLayoutBoard.WidgetRect widget = workspaceBoards.get(0).getWidgets().get(i); + WidgetRect widget = workspaceBoards.get(0).getWidgets().get(i); if (widget.getCellX() == 0 && widget.getCellY() == 0) { continue; } @@ -146,7 +149,7 @@ public class ReorderWidgets extends AbstractLauncherUiTest { * underlying code does different things in that case */ private void triggerWidgetResize(ReorderTestCase testCase) { - CellLayoutBoard.WidgetRect widgetRect = getWidgetClosestTo(testCase.moveMainTo); + WidgetRect widgetRect = getWidgetClosestTo(testCase.moveMainTo); if (widgetRect == null) { // Some test doesn't have a widget in the final position, in those cases we will ignore // them @@ -160,7 +163,7 @@ public class ReorderWidgets extends AbstractLauncherUiTest { } private void runTestCase(ReorderTestCase testCase) { - CellLayoutBoard.WidgetRect mainWidgetCellPos = CellLayoutBoard.getMainFromList( + WidgetRect mainWidgetCellPos = CellLayoutBoard.getMainFromList( testCase.mStart); FavoriteItemsTransaction transaction = diff --git a/tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java b/tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java similarity index 84% rename from tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java rename to tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java index ff667e60bf..e90e14540e 100644 --- a/tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java +++ b/tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.launcher3.celllayout; +package com.android.launcher3.celllayout.board; import android.graphics.Point; import android.graphics.Rect; @@ -97,105 +97,6 @@ public class CellLayoutBoard implements Comparable { return 0; } - public static class CellType { - // The cells marked by this will be filled by 1x1 widgets and will be ignored when - // validating - public static final char IGNORE = 'x'; - // The cells marked by this will be filled by app icons - public static final char ICON = 'i'; - // The cells marked by FOLDER will be filled by folders with 27 app icons inside - public static final char FOLDER = 'Z'; - // Empty space - public static final char EMPTY = '-'; - // Widget that will be saved as "main widget" for easier retrieval - public static final char MAIN_WIDGET = 'm'; - // Everything else will be consider a widget - } - - public static class WidgetRect { - public char mType; - public Rect mBounds; - - WidgetRect(char type, Rect bounds) { - this.mType = type; - this.mBounds = bounds; - } - - int getSpanX() { - return mBounds.right - mBounds.left + 1; - } - - int getSpanY() { - return mBounds.top - mBounds.bottom + 1; - } - - int getCellX() { - return mBounds.left; - } - - int getCellY() { - return mBounds.bottom; - } - - boolean shouldIgnore() { - return this.mType == CellType.IGNORE; - } - - boolean contains(int x, int y) { - return mBounds.contains(x, y); - } - - @Override - public String toString() { - return "WidgetRect type = " + mType + " x = " + getCellX() + " | y " + getCellY() - + " xs = " + getSpanX() + " ys = " + getSpanY(); - } - } - - public static class IconPoint { - public Point coord; - public char mType; - - public IconPoint(Point coord, char type) { - this.coord = coord; - mType = type; - } - - public char getType() { - return mType; - } - - public void setType(char type) { - mType = type; - } - - public Point getCoord() { - return coord; - } - - public void setCoord(Point coord) { - this.coord = coord; - } - } - - public static class FolderPoint { - public Point coord; - public char mType; - - public FolderPoint(Point coord, char type) { - this.coord = coord; - mType = type; - } - - /** - * [A-Z]: Represents a folder and number of icons in the folder is represented by - * the order of letter in the alphabet, A=2, B=3, C=4 ... etc. - */ - public int getNumberIconsInside() { - return (mType - 'A') + 2; - } - } - private HashSet mUsedWidgetTypes = new HashSet<>(); @@ -211,9 +112,9 @@ public class CellLayoutBoard implements Comparable { WidgetRect mMain = null; - int mWidth, mHeight; + public int mWidth, mHeight; - CellLayoutBoard() { + public CellLayoutBoard() { for (int x = 0; x < mWidget.length; x++) { for (int y = 0; y < mWidget[0].length; y++) { mWidget[x][y] = CellType.EMPTY; @@ -221,7 +122,7 @@ public class CellLayoutBoard implements Comparable { } } - CellLayoutBoard(int width, int height) { + public CellLayoutBoard(int width, int height) { mWidget = new char[width][height]; this.mWidth = width; this.mHeight = height; diff --git a/tests/src/com/android/launcher3/celllayout/board/CellType.java b/tests/src/com/android/launcher3/celllayout/board/CellType.java new file mode 100644 index 0000000000..49c146b32a --- /dev/null +++ b/tests/src/com/android/launcher3/celllayout/board/CellType.java @@ -0,0 +1,32 @@ +/* + * 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.board; + +public class CellType { + // The cells marked by this will be filled by 1x1 widgets and will be ignored when + // validating + public static final char IGNORE = 'x'; + // The cells marked by this will be filled by app icons + public static final char ICON = 'i'; + // The cells marked by FOLDER will be filled by folders with 27 app icons inside + public static final char FOLDER = 'Z'; + // Empty space + public static final char EMPTY = '-'; + // Widget that will be saved as "main widget" for easier retrieval + public static final char MAIN_WIDGET = 'm'; + // Everything else will be consider a widget +} diff --git a/tests/src/com/android/launcher3/celllayout/board/FolderPoint.java b/tests/src/com/android/launcher3/celllayout/board/FolderPoint.java new file mode 100644 index 0000000000..39ba434dc0 --- /dev/null +++ b/tests/src/com/android/launcher3/celllayout/board/FolderPoint.java @@ -0,0 +1,37 @@ +/* + * 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.board; + +import android.graphics.Point; + +public class FolderPoint { + public Point coord; + public char mType; + + public FolderPoint(Point coord, char type) { + this.coord = coord; + mType = type; + } + + /** + * [A-Z]: Represents a folder and number of icons in the folder is represented by + * the order of letter in the alphabet, A=2, B=3, C=4 ... etc. + */ + public int getNumberIconsInside() { + return (mType - 'A') + 2; + } +} diff --git a/tests/src/com/android/launcher3/celllayout/TestBoardAppIcon.java b/tests/src/com/android/launcher3/celllayout/board/IconPoint.java similarity index 84% rename from tests/src/com/android/launcher3/celllayout/TestBoardAppIcon.java rename to tests/src/com/android/launcher3/celllayout/board/IconPoint.java index 04604d7735..d3d297003d 100644 --- a/tests/src/com/android/launcher3/celllayout/TestBoardAppIcon.java +++ b/tests/src/com/android/launcher3/celllayout/board/IconPoint.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * 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. @@ -13,15 +13,16 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.launcher3.celllayout; + +package com.android.launcher3.celllayout.board; import android.graphics.Point; -public class TestBoardAppIcon { +public class IconPoint { public Point coord; public char mType; - public TestBoardAppIcon(Point coord, char type) { + public IconPoint(Point coord, char type) { this.coord = coord; mType = type; } diff --git a/tests/src/com/android/launcher3/celllayout/TestWorkspaceBuilder.java b/tests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.java similarity index 89% rename from tests/src/com/android/launcher3/celllayout/TestWorkspaceBuilder.java rename to tests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.java index 6489bc1cfc..06a7db2ae0 100644 --- a/tests/src/com/android/launcher3/celllayout/TestWorkspaceBuilder.java +++ b/tests/src/com/android/launcher3/celllayout/board/TestWorkspaceBuilder.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * 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. @@ -13,7 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.launcher3.celllayout; +package com.android.launcher3.celllayout.board; import static androidx.test.core.app.ApplicationProvider.getApplicationContext; import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation; @@ -31,6 +31,12 @@ import android.util.Log; import com.android.launcher3.InvariantDeviceProfile; import com.android.launcher3.LauncherSettings; +import com.android.launcher3.celllayout.FavoriteItemsTransaction; +import com.android.launcher3.celllayout.board.CellLayoutBoard; +import com.android.launcher3.celllayout.board.CellType; +import com.android.launcher3.celllayout.board.FolderPoint; +import com.android.launcher3.celllayout.board.IconPoint; +import com.android.launcher3.celllayout.board.WidgetRect; import com.android.launcher3.model.data.AppInfo; import com.android.launcher3.model.data.FolderInfo; import com.android.launcher3.model.data.ItemInfo; @@ -61,7 +67,7 @@ public class TestWorkspaceBuilder { /** * Fills the given rect in WidgetRect with 1x1 widgets. This is useful to equalize cases. */ - private FavoriteItemsTransaction fillWithWidgets(CellLayoutBoard.WidgetRect widgetRect, + private FavoriteItemsTransaction fillWithWidgets(WidgetRect widgetRect, FavoriteItemsTransaction transaction, int screenId) { int initX = widgetRect.getCellX(); int initY = widgetRect.getCellY(); @@ -70,7 +76,7 @@ public class TestWorkspaceBuilder { try { // this widgets are filling, we don't care if we can't place them transaction.addItem(createWidgetInCell( - new CellLayoutBoard.WidgetRect(CellLayoutBoard.CellType.IGNORE, + new WidgetRect(CellType.IGNORE, new Rect(x, y, x, y)), screenId)); } catch (Exception e) { Log.d(TAG, "Unable to place filling widget at " + x + "," + y); @@ -97,7 +103,7 @@ public class TestWorkspaceBuilder { ); } - private void addCorrespondingWidgetRect(CellLayoutBoard.WidgetRect widgetRect, + private void addCorrespondingWidgetRect(WidgetRect widgetRect, FavoriteItemsTransaction transaction, int screenId) { if (widgetRect.mType == 'x') { fillWithWidgets(widgetRect, transaction, screenId); @@ -133,7 +139,7 @@ public class TestWorkspaceBuilder { } private Supplier createWidgetInCell( - CellLayoutBoard.WidgetRect widgetRect, int screenId) { + WidgetRect widgetRect, int screenId) { // Create the widget lazily since the appWidgetId can get lost during setup return () -> { LauncherAppWidgetProviderInfo info = findWidgetProvider(false); @@ -147,7 +153,7 @@ public class TestWorkspaceBuilder { }; } - public FolderInfo createFolderInCell(CellLayoutBoard.FolderPoint folderPoint, int screenId) { + public FolderInfo createFolderInCell(FolderPoint folderPoint, int screenId) { FolderInfo folderInfo = new FolderInfo(); folderInfo.screenId = screenId; folderInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP; @@ -171,7 +177,7 @@ public class TestWorkspaceBuilder { return item; } - private ItemInfo createIconInCell(CellLayoutBoard.IconPoint iconPoint, int screenId) { + private ItemInfo createIconInCell(IconPoint iconPoint, int screenId) { WorkspaceItemInfo item = new WorkspaceItemInfo(getApp()); item.screenId = screenId; item.cellX = iconPoint.getCoord().x; diff --git a/tests/src/com/android/launcher3/celllayout/TestBoardWidget.java b/tests/src/com/android/launcher3/celllayout/board/WidgetRect.java similarity index 59% rename from tests/src/com/android/launcher3/celllayout/TestBoardWidget.java rename to tests/src/com/android/launcher3/celllayout/board/WidgetRect.java index 7f9aa9516c..c90ce8504f 100644 --- a/tests/src/com/android/launcher3/celllayout/TestBoardWidget.java +++ b/tests/src/com/android/launcher3/celllayout/board/WidgetRect.java @@ -1,5 +1,5 @@ /* - * Copyright (C) 2022 The Android Open Source Project + * 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. @@ -13,36 +13,47 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -package com.android.launcher3.celllayout; + +package com.android.launcher3.celllayout.board; import android.graphics.Rect; -public class TestBoardWidget { +public class WidgetRect { public char mType; public Rect mBounds; - TestBoardWidget(char type, Rect bounds) { + public WidgetRect(char type, Rect bounds) { this.mType = type; this.mBounds = bounds; } - int getSpanX() { + public int getSpanX() { return mBounds.right - mBounds.left + 1; } - int getSpanY() { + public int getSpanY() { return mBounds.top - mBounds.bottom + 1; } - int getCellX() { + public int getCellX() { return mBounds.left; } - int getCellY() { + public int getCellY() { return mBounds.bottom; } boolean shouldIgnore() { - return this.mType == 'x'; + return this.mType == CellType.IGNORE; + } + + boolean contains(int x, int y) { + return mBounds.contains(x, y); + } + + @Override + public String toString() { + return "WidgetRect type = " + mType + " x = " + getCellX() + " | y " + getCellY() + + " xs = " + getSpanX() + " ys = " + getSpanY(); } }