Move classes inside of CellLayoutBoard to their own file
Previous step for adding unit testing for MultipageCellLayout.
Flag: LEGACY FOLDABLE_SINGLE_PAGE DISABLED
Bug: 270395274
Test: ReorderAlgorithmUnitTest
Change-Id: Ia5ca0b10481d7a21883594434b3406fb3a5ccf0b
diff --git a/tests/Android.bp b/tests/Android.bp
index 8725b46..84c3951 100644
--- a/tests/Android.bp
+++ b/tests/Android.bp
@@ -33,8 +33,8 @@
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 86a7bd3..1fe02b2 100644
--- a/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java
+++ b/tests/src/com/android/launcher3/celllayout/CellLayoutTestUtils.java
@@ -21,6 +21,7 @@
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 91a0634..2108eee 100644
--- a/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java
+++ b/tests/src/com/android/launcher3/celllayout/ReorderAlgorithmUnitTest.java
@@ -31,6 +31,9 @@
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 @@
// 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 4274130..3dc5030 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 ed84a60..0c1403f 100644
--- a/tests/src/com/android/launcher3/celllayout/ReorderTestCase.java
+++ b/tests/src/com/android/launcher3/celllayout/ReorderTestCase.java
@@ -17,6 +17,8 @@
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 3d388d60..72de885 100644
--- a/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java
+++ b/tests/src/com/android/launcher3/celllayout/ReorderWidgets.java
@@ -32,6 +32,9 @@
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 @@
return getFromLauncher(CellLayoutTestUtils::workspaceToBoards);
}
- private CellLayoutBoard.WidgetRect getWidgetClosestTo(Point point) {
+ private WidgetRect getWidgetClosestTo(Point point) {
ArrayList<CellLayoutBoard> 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 @@
* 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 @@
}
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/TestBoardWidget.java b/tests/src/com/android/launcher3/celllayout/TestBoardWidget.java
deleted file mode 100644
index 7f9aa95..0000000
--- a/tests/src/com/android/launcher3/celllayout/TestBoardWidget.java
+++ /dev/null
@@ -1,48 +0,0 @@
-/*
- * Copyright (C) 2022 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;
-
-import android.graphics.Rect;
-
-public class TestBoardWidget {
- public char mType;
- public Rect mBounds;
-
- TestBoardWidget(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 == 'x';
- }
-}
diff --git a/tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java b/tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java
similarity index 83%
rename from tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java
rename to tests/src/com/android/launcher3/celllayout/board/CellLayoutBoard.java
index ff667e6..e90e145 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 @@
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<Character> mUsedWidgetTypes = new HashSet<>();
@@ -211,9 +112,9 @@
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 @@
}
}
- 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 0000000..49c146b
--- /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/TestBoardAppIcon.java b/tests/src/com/android/launcher3/celllayout/board/FolderPoint.java
similarity index 62%
copy from tests/src/com/android/launcher3/celllayout/TestBoardAppIcon.java
copy to tests/src/com/android/launcher3/celllayout/board/FolderPoint.java
index 04604d7..39ba434 100644
--- a/tests/src/com/android/launcher3/celllayout/TestBoardAppIcon.java
+++ b/tests/src/com/android/launcher3/celllayout/board/FolderPoint.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,32 +13,25 @@
* 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 FolderPoint {
public Point coord;
public char mType;
- public TestBoardAppIcon(Point coord, char type) {
+ public FolderPoint(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;
+ /**
+ * [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 83%
rename from tests/src/com/android/launcher3/celllayout/TestBoardAppIcon.java
rename to tests/src/com/android/launcher3/celllayout/board/IconPoint.java
index 04604d7..d3d2970 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 6489bc1..06a7db2 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 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 @@
/**
* 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 @@
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 @@
);
}
- 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 @@
}
private Supplier<ItemInfo> 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 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 @@
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/board/WidgetRect.java b/tests/src/com/android/launcher3/celllayout/board/WidgetRect.java
new file mode 100644
index 0000000..c90ce85
--- /dev/null
+++ b/tests/src/com/android/launcher3/celllayout/board/WidgetRect.java
@@ -0,0 +1,59 @@
+/*
+ * 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.Rect;
+
+public class WidgetRect {
+ public char mType;
+ public Rect mBounds;
+
+ public WidgetRect(char type, Rect bounds) {
+ this.mType = type;
+ this.mBounds = bounds;
+ }
+
+ public int getSpanX() {
+ return mBounds.right - mBounds.left + 1;
+ }
+
+ public int getSpanY() {
+ return mBounds.top - mBounds.bottom + 1;
+ }
+
+ public int getCellX() {
+ return mBounds.left;
+ }
+
+ public 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();
+ }
+}