Loading src/com/android/launcher3/testing/TestInformationHandler.java +7 −0 Original line number Diff line number Diff line Loading @@ -201,6 +201,13 @@ public class TestInformationHandler implements ResourceBasedOverride { }); } case TestProtocol.REQUEST_WORKSPACE_COLUMNS_ROWS: { return getLauncherUIProperty(Bundle::putParcelable, launcher -> new Point( InvariantDeviceProfile.INSTANCE.get(mContext).numColumns, InvariantDeviceProfile.INSTANCE.get(mContext).numRows) ); } case TestProtocol.REQUEST_HOTSEAT_CELL_CENTER: { final HotseatCellCenterRequest request = extra.getParcelable( TestProtocol.TEST_INFO_REQUEST_FIELD); Loading src/com/android/launcher3/testing/shared/TestProtocol.java +1 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,7 @@ public final class TestProtocol { public static final String REQUEST_WORKSPACE_CELL_LAYOUT_SIZE = "workspace-cell-layout-size"; public static final String REQUEST_WORKSPACE_CELL_CENTER = "workspace-cell-center"; public static final String REQUEST_WORKSPACE_COLUMNS_ROWS = "workspace-columns-rows"; public static final String REQUEST_HOTSEAT_CELL_CENTER = "hotseat-cell-center"; Loading src/com/android/launcher3/testing/shared/WorkspaceCellCenterRequest.java +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ public class WorkspaceCellCenterRequest implements TestInformationRequest { * Set span Height in cells */ public WorkspaceCellCenterRequest.Builder setSpanY(int y) { this.mCellY = y; this.mSpanY = y; return this; } Loading tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java +105 −8 Original line number Diff line number Diff line Loading @@ -29,7 +29,73 @@ import java.util.Set; import java.util.stream.Collectors; public class CellLayoutBoard { public class CellLayoutBoard implements Comparable<CellLayoutBoard> { private boolean intersects(Rect r1, Rect r2) { // If one rectangle is on left side of other if (r1.left > r2.right || r2.left > r1.right) { return false; } // If one rectangle is above other if (r1.bottom > r2.top || r2.bottom > r1.top) { return false; } return true; } private boolean overlapsWithIgnored(Set<Rect> ignoredRectangles, Rect rect) { for (Rect ignoredRect : ignoredRectangles) { // Using the built in intersects doesn't work because it doesn't account for area 0 if (intersects(ignoredRect, rect)) { return true; } } return false; } @Override public int compareTo(CellLayoutBoard cellLayoutBoard) { // to be equal they need to have the same number of widgets and the same dimensions // their order can be different Set<Rect> widgetsSet = new HashSet<>(); Set<Rect> ignoredRectangles = new HashSet<>(); for (WidgetRect rect : mWidgetsRects) { if (rect.shouldIgnore()) { ignoredRectangles.add(rect.mBounds); } else { widgetsSet.add(rect.mBounds); } } for (WidgetRect rect : cellLayoutBoard.mWidgetsRects) { // ignore rectangles overlapping with the area marked by x if (overlapsWithIgnored(ignoredRectangles, rect.mBounds)) { continue; } if (!widgetsSet.contains(rect.mBounds)) { return -1; } widgetsSet.remove(rect.mBounds); } if (!widgetsSet.isEmpty()) { return 1; } // to be equal they need to have the same number of icons their order can be different Set<Point> iconsSet = new HashSet<>(); mIconPoints.forEach(icon -> iconsSet.add(icon.getCoord())); for (IconPoint icon : cellLayoutBoard.mIconPoints) { if (!iconsSet.contains(icon.getCoord())) { return -1; } iconsSet.remove(icon.getCoord()); } if (!iconsSet.isEmpty()) { return 1; } return 0; } public static class CellType { // The cells marked by this will be filled by 1x1 widgets and will be ignored when Loading Loading @@ -115,7 +181,7 @@ public class CellLayoutBoard { List<IconPoint> mIconPoints = new ArrayList<>(); Map<Character, IconPoint> mIconsMap = new HashMap<>(); Point mMain = new Point(); WidgetRect mMain = null; CellLayoutBoard() { for (int x = 0; x < mWidget.length; x++) { Loading @@ -133,7 +199,7 @@ public class CellLayoutBoard { return mIconPoints; } public Point getMain() { public WidgetRect getMain() { return mMain; } Loading Loading @@ -273,6 +339,16 @@ public class CellLayoutBoard { return iconPoints; } public static WidgetRect getMainFromList(List<CellLayoutBoard> boards) { for (CellLayoutBoard board : boards) { WidgetRect main = board.getMain(); if (main != null) { return main; } } return null; } public static CellLayoutBoard boardFromString(String boardStr) { String[] lines = boardStr.split("\n"); CellLayoutBoard board = new CellLayoutBoard(); Loading @@ -281,17 +357,18 @@ public class CellLayoutBoard { String line = lines[y]; for (int x = 0; x < line.length(); x++) { char c = line.charAt(x); if (c == CellType.MAIN_WIDGET) { board.mMain = new Point(x, y); } if (c != CellType.EMPTY) { board.mWidget[x][y] = line.charAt(x); } } } board.mWidgetsRects = getRects(board.mWidget); board.mWidgetsRects.forEach( widgetRect -> board.mWidgetsMap.put(widgetRect.mType, widgetRect)); board.mWidgetsRects.forEach(widgetRect -> { if (widgetRect.mType == CellType.MAIN_WIDGET) { board.mMain = widgetRect; } board.mWidgetsMap.put(widgetRect.mType, widgetRect); }); board.mIconPoints = getIconPoints(board.mWidget); return board; } Loading @@ -308,4 +385,24 @@ public class CellLayoutBoard { } return s.toString(); } public static List<CellLayoutBoard> boardListFromString(String boardsStr) { String[] lines = boardsStr.split("\n"); ArrayList<String> individualBoards = new ArrayList<>(); ArrayList<CellLayoutBoard> boards = new ArrayList<>(); for (String line : lines) { String[] boardSegment = line.split("\\|"); for (int i = 0; i < boardSegment.length; i++) { if (i >= individualBoards.size()) { individualBoards.add(boardSegment[i]); } else { individualBoards.set(i, individualBoards.get(i) + "\n" + boardSegment[i]); } } } for (String board : individualBoards) { boards.add(CellLayoutBoard.boardFromString(board)); } return boards; } } tests/src/com/android/launcher3/celllayout/MultipleCellLayoutsSimpleReorder.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * 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.testcases; import android.graphics.Point; import java.util.Map; /** * The grids represent the workspace to be build by TestWorkspaceBuilder, to see what each character * in the board mean refer to {@code CellType} */ public class MultipleCellLayoutsSimpleReorder { /** 5x5 Test **/ private static final String START_BOARD_STR_5x5 = "" + "xxxxx|-----\n" + "--mm-|-----\n" + "--mm-|-----\n" + "-----|-----\n" + "-----|-----"; private static final Point MOVE_TO_5x5 = new Point(8, 3); private static final String END_BOARD_STR_5x5 = "" + "xxxxx|-----\n" + "-----|-----\n" + "-----|-----\n" + "-----|---mm\n" + "-----|---mm"; private static final ReorderTestCase TEST_CASE_5x5 = new ReorderTestCase(START_BOARD_STR_5x5, MOVE_TO_5x5, END_BOARD_STR_5x5); /** 4x4 Test **/ private static final String START_BOARD_STR_4x4 = "" + "xxxx|----\n" + "--mm|----\n" + "--mm|----\n" + "----|----"; private static final Point MOVE_TO_4x4 = new Point(5, 3); private static final String END_BOARD_STR_4x4 = "" + "xxxx|----\n" + "----|----\n" + "----|-mm-\n" + "----|-mm-"; private static final ReorderTestCase TEST_CASE_4x4 = new ReorderTestCase(START_BOARD_STR_4x4, MOVE_TO_4x4, END_BOARD_STR_4x4); /** 6x5 Test **/ private static final String START_BOARD_STR_6x5 = "" + "xxxxxx|------\n" + "--m---|------\n" + "------|------\n" + "------|------\n" + "------|------"; private static final Point MOVE_TO_6x5 = new Point(10, 4); private static final String END_BOARD_STR_6x5 = "" + "xxxxxx|------\n" + "------|------\n" + "------|------\n" + "------|------\n" + "------|----m-"; private static final ReorderTestCase TEST_CASE_6x5 = new ReorderTestCase(START_BOARD_STR_6x5, MOVE_TO_6x5, END_BOARD_STR_6x5); public static final Map<Point, ReorderTestCase> TEST_BY_GRID_SIZE = Map.of(new Point(5, 5), TEST_CASE_5x5, new Point(4, 4), TEST_CASE_4x4, new Point(6, 5), TEST_CASE_6x5); } Loading
src/com/android/launcher3/testing/TestInformationHandler.java +7 −0 Original line number Diff line number Diff line Loading @@ -201,6 +201,13 @@ public class TestInformationHandler implements ResourceBasedOverride { }); } case TestProtocol.REQUEST_WORKSPACE_COLUMNS_ROWS: { return getLauncherUIProperty(Bundle::putParcelable, launcher -> new Point( InvariantDeviceProfile.INSTANCE.get(mContext).numColumns, InvariantDeviceProfile.INSTANCE.get(mContext).numRows) ); } case TestProtocol.REQUEST_HOTSEAT_CELL_CENTER: { final HotseatCellCenterRequest request = extra.getParcelable( TestProtocol.TEST_INFO_REQUEST_FIELD); Loading
src/com/android/launcher3/testing/shared/TestProtocol.java +1 −0 Original line number Diff line number Diff line Loading @@ -123,6 +123,7 @@ public final class TestProtocol { public static final String REQUEST_WORKSPACE_CELL_LAYOUT_SIZE = "workspace-cell-layout-size"; public static final String REQUEST_WORKSPACE_CELL_CENTER = "workspace-cell-center"; public static final String REQUEST_WORKSPACE_COLUMNS_ROWS = "workspace-columns-rows"; public static final String REQUEST_HOTSEAT_CELL_CENTER = "hotseat-cell-center"; Loading
src/com/android/launcher3/testing/shared/WorkspaceCellCenterRequest.java +1 −1 Original line number Diff line number Diff line Loading @@ -124,7 +124,7 @@ public class WorkspaceCellCenterRequest implements TestInformationRequest { * Set span Height in cells */ public WorkspaceCellCenterRequest.Builder setSpanY(int y) { this.mCellY = y; this.mSpanY = y; return this; } Loading
tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java +105 −8 Original line number Diff line number Diff line Loading @@ -29,7 +29,73 @@ import java.util.Set; import java.util.stream.Collectors; public class CellLayoutBoard { public class CellLayoutBoard implements Comparable<CellLayoutBoard> { private boolean intersects(Rect r1, Rect r2) { // If one rectangle is on left side of other if (r1.left > r2.right || r2.left > r1.right) { return false; } // If one rectangle is above other if (r1.bottom > r2.top || r2.bottom > r1.top) { return false; } return true; } private boolean overlapsWithIgnored(Set<Rect> ignoredRectangles, Rect rect) { for (Rect ignoredRect : ignoredRectangles) { // Using the built in intersects doesn't work because it doesn't account for area 0 if (intersects(ignoredRect, rect)) { return true; } } return false; } @Override public int compareTo(CellLayoutBoard cellLayoutBoard) { // to be equal they need to have the same number of widgets and the same dimensions // their order can be different Set<Rect> widgetsSet = new HashSet<>(); Set<Rect> ignoredRectangles = new HashSet<>(); for (WidgetRect rect : mWidgetsRects) { if (rect.shouldIgnore()) { ignoredRectangles.add(rect.mBounds); } else { widgetsSet.add(rect.mBounds); } } for (WidgetRect rect : cellLayoutBoard.mWidgetsRects) { // ignore rectangles overlapping with the area marked by x if (overlapsWithIgnored(ignoredRectangles, rect.mBounds)) { continue; } if (!widgetsSet.contains(rect.mBounds)) { return -1; } widgetsSet.remove(rect.mBounds); } if (!widgetsSet.isEmpty()) { return 1; } // to be equal they need to have the same number of icons their order can be different Set<Point> iconsSet = new HashSet<>(); mIconPoints.forEach(icon -> iconsSet.add(icon.getCoord())); for (IconPoint icon : cellLayoutBoard.mIconPoints) { if (!iconsSet.contains(icon.getCoord())) { return -1; } iconsSet.remove(icon.getCoord()); } if (!iconsSet.isEmpty()) { return 1; } return 0; } public static class CellType { // The cells marked by this will be filled by 1x1 widgets and will be ignored when Loading Loading @@ -115,7 +181,7 @@ public class CellLayoutBoard { List<IconPoint> mIconPoints = new ArrayList<>(); Map<Character, IconPoint> mIconsMap = new HashMap<>(); Point mMain = new Point(); WidgetRect mMain = null; CellLayoutBoard() { for (int x = 0; x < mWidget.length; x++) { Loading @@ -133,7 +199,7 @@ public class CellLayoutBoard { return mIconPoints; } public Point getMain() { public WidgetRect getMain() { return mMain; } Loading Loading @@ -273,6 +339,16 @@ public class CellLayoutBoard { return iconPoints; } public static WidgetRect getMainFromList(List<CellLayoutBoard> boards) { for (CellLayoutBoard board : boards) { WidgetRect main = board.getMain(); if (main != null) { return main; } } return null; } public static CellLayoutBoard boardFromString(String boardStr) { String[] lines = boardStr.split("\n"); CellLayoutBoard board = new CellLayoutBoard(); Loading @@ -281,17 +357,18 @@ public class CellLayoutBoard { String line = lines[y]; for (int x = 0; x < line.length(); x++) { char c = line.charAt(x); if (c == CellType.MAIN_WIDGET) { board.mMain = new Point(x, y); } if (c != CellType.EMPTY) { board.mWidget[x][y] = line.charAt(x); } } } board.mWidgetsRects = getRects(board.mWidget); board.mWidgetsRects.forEach( widgetRect -> board.mWidgetsMap.put(widgetRect.mType, widgetRect)); board.mWidgetsRects.forEach(widgetRect -> { if (widgetRect.mType == CellType.MAIN_WIDGET) { board.mMain = widgetRect; } board.mWidgetsMap.put(widgetRect.mType, widgetRect); }); board.mIconPoints = getIconPoints(board.mWidget); return board; } Loading @@ -308,4 +385,24 @@ public class CellLayoutBoard { } return s.toString(); } public static List<CellLayoutBoard> boardListFromString(String boardsStr) { String[] lines = boardsStr.split("\n"); ArrayList<String> individualBoards = new ArrayList<>(); ArrayList<CellLayoutBoard> boards = new ArrayList<>(); for (String line : lines) { String[] boardSegment = line.split("\\|"); for (int i = 0; i < boardSegment.length; i++) { if (i >= individualBoards.size()) { individualBoards.add(boardSegment[i]); } else { individualBoards.set(i, individualBoards.get(i) + "\n" + boardSegment[i]); } } } for (String board : individualBoards) { boards.add(CellLayoutBoard.boardFromString(board)); } return boards; } }
tests/src/com/android/launcher3/celllayout/MultipleCellLayoutsSimpleReorder.java 0 → 100644 +88 −0 Original line number Diff line number Diff line /* * 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.testcases; import android.graphics.Point; import java.util.Map; /** * The grids represent the workspace to be build by TestWorkspaceBuilder, to see what each character * in the board mean refer to {@code CellType} */ public class MultipleCellLayoutsSimpleReorder { /** 5x5 Test **/ private static final String START_BOARD_STR_5x5 = "" + "xxxxx|-----\n" + "--mm-|-----\n" + "--mm-|-----\n" + "-----|-----\n" + "-----|-----"; private static final Point MOVE_TO_5x5 = new Point(8, 3); private static final String END_BOARD_STR_5x5 = "" + "xxxxx|-----\n" + "-----|-----\n" + "-----|-----\n" + "-----|---mm\n" + "-----|---mm"; private static final ReorderTestCase TEST_CASE_5x5 = new ReorderTestCase(START_BOARD_STR_5x5, MOVE_TO_5x5, END_BOARD_STR_5x5); /** 4x4 Test **/ private static final String START_BOARD_STR_4x4 = "" + "xxxx|----\n" + "--mm|----\n" + "--mm|----\n" + "----|----"; private static final Point MOVE_TO_4x4 = new Point(5, 3); private static final String END_BOARD_STR_4x4 = "" + "xxxx|----\n" + "----|----\n" + "----|-mm-\n" + "----|-mm-"; private static final ReorderTestCase TEST_CASE_4x4 = new ReorderTestCase(START_BOARD_STR_4x4, MOVE_TO_4x4, END_BOARD_STR_4x4); /** 6x5 Test **/ private static final String START_BOARD_STR_6x5 = "" + "xxxxxx|------\n" + "--m---|------\n" + "------|------\n" + "------|------\n" + "------|------"; private static final Point MOVE_TO_6x5 = new Point(10, 4); private static final String END_BOARD_STR_6x5 = "" + "xxxxxx|------\n" + "------|------\n" + "------|------\n" + "------|------\n" + "------|----m-"; private static final ReorderTestCase TEST_CASE_6x5 = new ReorderTestCase(START_BOARD_STR_6x5, MOVE_TO_6x5, END_BOARD_STR_6x5); public static final Map<Point, ReorderTestCase> TEST_BY_GRID_SIZE = Map.of(new Point(5, 5), TEST_CASE_5x5, new Point(4, 4), TEST_CASE_4x4, new Point(6, 5), TEST_CASE_6x5); }