Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 715c2ae0 authored by Thales Lima's avatar Thales Lima Committed by Android (Google) Code Review
Browse files

Merge "Implement screenshot tests for Folders on the workspace" into udc-qpr-dev

parents af1932eb 83d3a0bc
Loading
Loading
Loading
Loading
+61 −0
Original line number Original line Diff line number Diff line
@@ -103,6 +103,8 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
        public static final char IGNORE = 'x';
        public static final char IGNORE = 'x';
        // The cells marked by this will be filled by app icons
        // The cells marked by this will be filled by app icons
        public static final char ICON = 'i';
        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
        // Empty space
        public static final char EMPTY = '-';
        public static final char EMPTY = '-';
        // Widget that will be saved as "main widget" for easier retrieval
        // 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<>();
    private HashSet<Character> mUsedWidgetTypes = new HashSet<>();


    static final int INFINITE = 99999;
    static final int INFINITE = 99999;
@@ -181,6 +202,7 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
    Map<Character, WidgetRect> mWidgetsMap = new HashMap<>();
    Map<Character, WidgetRect> mWidgetsMap = new HashMap<>();


    List<IconPoint> mIconPoints = new ArrayList<>();
    List<IconPoint> mIconPoints = new ArrayList<>();
    List<FolderPoint> mFolderPoints = new ArrayList<>();


    WidgetRect mMain = null;
    WidgetRect mMain = null;


@@ -213,6 +235,10 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
        return mIconPoints;
        return mIconPoints;
    }
    }


    public List<FolderPoint> getFolders() {
        return mFolderPoints;
    }

    public WidgetRect getMain() {
    public WidgetRect getMain() {
        return mMain;
        return mMain;
    }
    }
@@ -248,6 +274,17 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
            }
            }
            return true;
            return true;
        }).collect(Collectors.toList());
        }).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) {
    private void removeOverlappingItems(Point p) {
@@ -269,6 +306,17 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
            }
            }
            return true;
            return true;
        }).collect(Collectors.toList());
        }).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() {
    private char getNextWidgetType() {
@@ -373,6 +421,18 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
        return iconPoints;
        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) {
    public static WidgetRect getMainFromList(List<CellLayoutBoard> boards) {
        for (CellLayoutBoard board : boards) {
        for (CellLayoutBoard board : boards) {
            WidgetRect main = board.getMain();
            WidgetRect main = board.getMain();
@@ -406,6 +466,7 @@ public class CellLayoutBoard implements Comparable<CellLayoutBoard> {
            board.mWidgetsMap.put(widgetRect.mType, widgetRect);
            board.mWidgetsMap.put(widgetRect.mType, widgetRect);
        });
        });
        board.mIconPoints = getIconPoints(board.mWidget);
        board.mIconPoints = getIconPoints(board.mWidget);
        board.mFolderPoints = getFolderPoints(board.mWidget);
        return board;
        return board;
    }
    }


+21 −1
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.BgDataModel.Callbacks;
import com.android.launcher3.model.ModelDbController;
import com.android.launcher3.model.ModelDbController;
import com.android.launcher3.model.data.FolderInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.model.data.ItemInfo;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
import com.android.launcher3.provider.LauncherDbUtils.SQLiteTransaction;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.LauncherInstrumentation;
@@ -73,12 +74,31 @@ public class FavoriteItemsTransaction {
            // Add new data
            // Add new data
            try (SQLiteTransaction transaction = controller.newTransaction()) {
            try (SQLiteTransaction transaction = controller.newTransaction()) {
                int count = mItemsToSubmit.size();
                int count = mItemsToSubmit.size();
                ArrayList<ItemInfo> containerItems = new ArrayList<>();
                for (int i = 0; i < count; i++) {
                for (int i = 0; i < count; i++) {
                    ContentWriter writer = new ContentWriter(mContext);
                    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);
                    writer.put(LauncherSettings.Favorites._ID, i);
                    controller.insert(TABLE_NAME, writer.getValues(mContext));
                    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();
                transaction.commit();
            }
            }
        });
        });
+28 −0
Original line number Original line Diff line number Diff line
@@ -31,6 +31,7 @@ import android.util.Log;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.InvariantDeviceProfile;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.model.data.AppInfo;
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.ItemInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.LauncherAppWidgetInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
import com.android.launcher3.model.data.WorkspaceItemInfo;
@@ -102,6 +103,9 @@ public class TestWorkspaceBuilder {
        board.getIcons().forEach((iconPoint) ->
        board.getIcons().forEach((iconPoint) ->
                transaction.addItem(() -> createIconInCell(iconPoint, screenId))
                transaction.addItem(() -> createIconInCell(iconPoint, screenId))
        );
        );
        board.getFolders().forEach((folderPoint) ->
                transaction.addItem(() -> createFolderInCell(folderPoint, screenId))
        );
        return transaction;
        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) {
    private ItemInfo createIconInCell(CellLayoutBoard.IconPoint iconPoint, int screenId) {
        WorkspaceItemInfo item = new WorkspaceItemInfo(getApp());
        WorkspaceItemInfo item = new WorkspaceItemInfo(getApp());
        item.screenId = screenId;
        item.screenId = screenId;