diff --git a/tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java b/tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java index 3c2b49ac3b..28899d9e02 100644 --- a/tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java +++ b/tests/src/com/android/launcher3/celllayout/CellLayoutBoard.java @@ -103,6 +103,8 @@ public class CellLayoutBoard implements Comparable { 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 { } } + 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<>(); static final int INFINITE = 99999; @@ -181,6 +202,7 @@ public class CellLayoutBoard implements Comparable { Map mWidgetsMap = new HashMap<>(); List mIconPoints = new ArrayList<>(); + List mFolderPoints = new ArrayList<>(); WidgetRect mMain = null; @@ -213,6 +235,10 @@ public class CellLayoutBoard implements Comparable { return mIconPoints; } + public List getFolders() { + return mFolderPoints; + } + public WidgetRect getMain() { return mMain; } @@ -248,6 +274,17 @@ public class CellLayoutBoard implements Comparable { } 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 { } 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 { return iconPoints; } + private static List getFolderPoints(char[][] board) { + List 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 boards) { for (CellLayoutBoard board : boards) { WidgetRect main = board.getMain(); @@ -406,6 +466,7 @@ public class CellLayoutBoard implements Comparable { board.mWidgetsMap.put(widgetRect.mType, widgetRect); }); board.mIconPoints = getIconPoints(board.mWidget); + board.mFolderPoints = getFolderPoints(board.mWidget); return board; } diff --git a/tests/src/com/android/launcher3/celllayout/FavoriteItemsTransaction.java b/tests/src/com/android/launcher3/celllayout/FavoriteItemsTransaction.java index 6f6a4439ba..bf7a21c32d 100644 --- a/tests/src/com/android/launcher3/celllayout/FavoriteItemsTransaction.java +++ b/tests/src/com/android/launcher3/celllayout/FavoriteItemsTransaction.java @@ -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 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(); } }); diff --git a/tests/src/com/android/launcher3/celllayout/TestWorkspaceBuilder.java b/tests/src/com/android/launcher3/celllayout/TestWorkspaceBuilder.java index 8d06e33d83..398bd82638 100644 --- a/tests/src/com/android/launcher3/celllayout/TestWorkspaceBuilder.java +++ b/tests/src/com/android/launcher3/celllayout/TestWorkspaceBuilder.java @@ -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;