Implement screenshot tests for Folders on the workspace

Additional support to add folders in CellLayoutBoard using TestWorkspaceBuilder.

Bug: 274792950
Bug: 284155638
Flag: N/A
Test: HomeScreenFolderImageTest
Change-Id: I8a1be3e772cc2e2336dbe8276d22559239668232
This commit is contained in:
Jordan Silva
2023-06-15 02:57:38 +01:00
parent 296a9f3389
commit 83d3a0bcb7
3 changed files with 110 additions and 1 deletions

View File

@@ -103,6 +103,8 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
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
@@ -171,6 +173,25 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
}
}
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<>();
static final int INFINITE = 99999;
@@ -181,6 +202,7 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
Map<Character, WidgetRect> mWidgetsMap = new HashMap<>();
List<IconPoint> mIconPoints = new ArrayList<>();
List<FolderPoint> mFolderPoints = new ArrayList<>();
WidgetRect mMain = null;
@@ -213,6 +235,10 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
return mIconPoints;
}
public List<FolderPoint> getFolders() {
return mFolderPoints;
}
public WidgetRect getMain() {
return mMain;
}
@@ -248,6 +274,17 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
}
return true;
}).collect(Collectors.toList());
// Remove overlapping folders and remove them from the board
mFolderPoints = mFolderPoints.stream().filter(folderPoint -> {
int x = folderPoint.coord.x;
int y = folderPoint.coord.y;
if (rect.contains(x, y)) {
mWidget[x][y] = '-';
return false;
}
return true;
}).collect(Collectors.toList());
}
private void removeOverlappingItems(Point p) {
@@ -269,6 +306,17 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
}
return true;
}).collect(Collectors.toList());
// Remove overlapping folders and remove them from the board
mFolderPoints = mFolderPoints.stream().filter(folderPoint -> {
int x = folderPoint.coord.x;
int y = folderPoint.coord.y;
if (p.x == x && p.y == y) {
mWidget[x][y] = '-';
return false;
}
return true;
}).collect(Collectors.toList());
}
private char getNextWidgetType() {
@@ -373,6 +421,18 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
return iconPoints;
}
private static List<FolderPoint> getFolderPoints(char[][] board) {
List<FolderPoint> folderPoints = new ArrayList<>();
for (int x = 0; x < board.length; x++) {
for (int y = 0; y < board[0].length; y++) {
if (isFolder(board[x][y])) {
folderPoints.add(new FolderPoint(new Point(x, y), board[x][y]));
}
}
}
return folderPoints;
}
public static WidgetRect getMainFromList(List<CellLayoutBoard> boards) {
for (CellLayoutBoard board : boards) {
WidgetRect main = board.getMain();
@@ -406,6 +466,7 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
board.mWidgetsMap.put(widgetRect.mType, widgetRect);
});
board.mIconPoints = getIconPoints(board.mWidget);
board.mFolderPoints = getFolderPoints(board.mWidget);
return board;
}

View File

@@ -31,6 +31,7 @@ import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.ModelDbController;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
import com.android.launcher3.tapl.LauncherInstrumentation;
@@ -73,12 +74,31 @@ public class FavoriteItemsTransaction {
// Add new data
try (SQLiteTransaction transaction = controller.newTransaction()) {
int count = mItemsToSubmit.size();
ArrayList<ItemInfo> containerItems = new ArrayList<>();
for (int i = 0; i < count; i++) {
ContentWriter writer = new ContentWriter(mContext);
mItemsToSubmit.get(i).get().onAddToDatabase(writer);
ItemInfo item = mItemsToSubmit.get(i).get();
if (item.itemType == LauncherSettings.Favorites.ITEM_TYPE_FOLDER) {
FolderInfo folderInfo = (FolderInfo) item;
for (ItemInfo itemInfo : folderInfo.contents) {
itemInfo.container = i;
containerItems.add(itemInfo);
}
}
item.onAddToDatabase(writer);
writer.put(LauncherSettings.Favorites._ID, i);
controller.insert(TABLE_NAME, writer.getValues(mContext));
}
for (int i = 0; i < containerItems.size(); i++) {
ContentWriter writer = new ContentWriter(mContext);
ItemInfo item = containerItems.get(i);
item.onAddToDatabase(writer);
writer.put(LauncherSettings.Favorites._ID, count + i);
controller.insert(TABLE_NAME, writer.getValues(mContext));
}
transaction.commit();
}
});

View File

@@ -31,6 +31,7 @@ import android.util.Log;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.model.data.AppInfo;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -102,6 +103,9 @@ public class TestWorkspaceBuilder {
board.getIcons().forEach((iconPoint) ->
transaction.addItem(() -> createIconInCell(iconPoint, screenId))
);
board.getFolders().forEach((folderPoint) ->
transaction.addItem(() -> createFolderInCell(folderPoint, screenId))
);
return transaction;
}
@@ -130,6 +134,30 @@ public class TestWorkspaceBuilder {
};
}
public FolderInfo createFolderInCell(CellLayoutBoard.FolderPoint folderPoint, int screenId) {
FolderInfo folderInfo = new FolderInfo();
folderInfo.screenId = screenId;
folderInfo.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
folderInfo.cellX = folderPoint.coord.x;
folderInfo.cellY = folderPoint.coord.y;
folderInfo.minSpanY = folderInfo.minSpanX = folderInfo.spanX = folderInfo.spanY = 1;
folderInfo.setOption(FolderInfo.FLAG_MULTI_PAGE_ANIMATION, true, null);
for (int i = 0; i < folderPoint.getNumberIconsInside(); i++) {
folderInfo.add(getDefaultWorkspaceItem(screenId), false);
}
return folderInfo;
}
private WorkspaceItemInfo getDefaultWorkspaceItem(int screenId) {
WorkspaceItemInfo item = new WorkspaceItemInfo(getApp());
item.screenId = screenId;
item.minSpanY = item.minSpanX = item.spanX = item.spanY = 1;
item.container = LauncherSettings.Favorites.CONTAINER_DESKTOP;
return item;
}
private ItemInfo createIconInCell(CellLayoutBoard.IconPoint iconPoint, int screenId) {
WorkspaceItemInfo item = new WorkspaceItemInfo(getApp());
item.screenId = screenId;