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

Commit 69c340a0 authored by Jon Miranda's avatar Jon Miranda
Browse files

Match items in icon preview with items in Folder using permutations.

Before, with the FolderIconPreviewVerifier, we would
adjust which items are displayed in the FolderIcon.
This caused some issues where the apps in the folder
icon would jump to whatever was in the upper left quadrant.

Now, we always display the 4 first items in the icon by
modifying the XY positions of the items within the Folder.

Bug: 27944225
Bug: 35064148
Change-Id: I46c0fbb064d4da4da155e29963bfb92b14e40f07
parent aa2272f8
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -3792,7 +3792,7 @@ public class Workspace extends PagedView
                ItemInfo info = (ItemInfo) item.getTag();
                if (recurse && info instanceof FolderInfo && item instanceof FolderIcon) {
                    FolderIcon folder = (FolderIcon) item;
                    ArrayList<View> folderChildren = folder.getFolder().getItemsInReadingOrder();
                    ArrayList<View> folderChildren = folder.getFolder().getItemsInRankOrder();
                    // map over all the children in the folder
                    final int childCount = folderChildren.size();
                    for (int childIdx = 0; childIdx < childCount; childIdx++) {
+1 −1
Original line number Diff line number Diff line
@@ -369,7 +369,7 @@ public class LauncherAccessibilityDelegate extends AccessibilityDelegate impleme

        Folder folder = Folder.getOpen(mLauncher);
        if (folder != null) {
            if (!folder.getItemsInReadingOrder().contains(item)) {
            if (!folder.getItemsInRankOrder().contains(item)) {
                folder.close(true);
                folder = null;
            }
+45 −35
Original line number Diff line number Diff line
@@ -133,7 +133,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
    private final Alarm mOnScrollHintAlarm = new Alarm();
    @Thunk final Alarm mScrollPauseAlarm = new Alarm();

    @Thunk final ArrayList<View> mItemsInReadingOrder = new ArrayList<View>();
    @Thunk final ArrayList<View> mItemsInRankOrder = new ArrayList<>();

    private AnimatorSet mCurrentAnimator;

@@ -284,7 +284,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
        if (tag instanceof ShortcutInfo) {
            ShortcutInfo item = (ShortcutInfo) tag;

            mEmptyCellRank = item.rank;
            mEmptyCellRank = mContent.getReadingOrderPosForRank(item.rank);
            mCurrentDragView = v;

            mDragController.addDragListener(this);
@@ -705,7 +705,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
    }

    public void beginExternalDrag() {
        mEmptyCellRank = mContent.allocateRankForNewItem();
        mEmptyCellRank = mContent.getReadingOrderPosForRank(mContent.allocateRankForNewItem());
        mIsExternalDrag = true;
        mDragInProgress = true;

@@ -997,7 +997,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
            ShortcutInfo info = (ShortcutInfo) d.dragInfo;
            View icon = (mCurrentDragView != null && mCurrentDragView.getTag() == info)
                    ? mCurrentDragView : mContent.createNewView(info);
            ArrayList<View> views = getItemsInReadingOrder();
            ArrayList<View> views = getItemsInRankOrder();
            views.add(info.rank, icon);
            mContent.arrangeChildren(views, views.size());
            mItemsInvalidated = true;
@@ -1072,7 +1072,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
    }

    private void updateItemLocationsInDatabaseBatch() {
        ArrayList<View> list = getItemsInReadingOrder();
        ArrayList<View> list = getItemsInRankOrder();
        ArrayList<ItemInfo> items = new ArrayList<ItemInfo>();
        for (int i = 0; i < list.size(); i++) {
            View v = list.get(i);
@@ -1231,7 +1231,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
     * otherwise it is ignored.
     */
    public void rearrangeChildren(int itemCount) {
        ArrayList<View> views = getItemsInReadingOrder();
        ArrayList<View> views = getItemsInRankOrder();
        mContent.arrangeChildren(views, Math.max(itemCount, views.size()));
        mItemsInvalidated = true;
    }
@@ -1376,23 +1376,19 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC

            View currentDragView;
            if (mIsExternalDrag) {
                currentDragView = mContent.createAndAddViewForRank(si, mEmptyCellRank);

                // Actually move the item in the database if it was an external drag. Call this
                // before creating the view, so that ShortcutInfo is updated appropriately.
                mLauncher.getModelWriter().addOrMoveItemInDatabase(
                        si, mInfo.id, 0, si.cellX, si.cellY);

                // We only need to update the locations if it doesn't get handled in
                // #onDropCompleted.
                if (d.dragSource != this) {
                    updateItemLocationsInDatabaseBatch();
                mLauncher.getModelWriter().addOrMoveItemInDatabase(si, mInfo.id, 0, si.cellX, si.cellY);
            }

            currentDragView = mIsExternalDrag
                    ? mContent.createNewView(si)
                    : mCurrentDragView;
            mIsExternalDrag = false;
            } else {
                currentDragView = mCurrentDragView;
                mContent.addViewForRank(currentDragView, si, mEmptyCellRank);
            }

            // Note: addViewForRankDuringDragAndDrop handles rearranging the children.
            mContent.addViewForRankDuringDragAndDrop(currentDragView, si, mEmptyCellRank);
            mItemsInvalidated = true;

            if (d.dragView.hasDrawn()) {
                // Temporarily reset the scale such that the animation target gets calculated
@@ -1410,9 +1406,6 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
                currentDragView.setVisibility(VISIBLE);
            }

            mItemsInvalidated = true;
            rearrangeChildren();

            // Temporarily suppress the listener, as we did all the work already here.
            try (SuppressInfoChanges s = new SuppressInfoChanges()) {
                mInfo.add(si, false);
@@ -1450,7 +1443,7 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
        mLauncher.getModelWriter().addOrMoveItemInDatabase(item, mInfo.id, 0, item.cellX,
                item.cellY);

        ArrayList<View> items = new ArrayList<>(getItemsInReadingOrder());
        ArrayList<View> items = new ArrayList<>(getItemsInRankOrder());
        items.add(rank, view);
        mContent.arrangeChildren(items, items.size());
        mItemsInvalidated = true;
@@ -1497,24 +1490,34 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
    public void onTitleChanged(CharSequence title) {
    }

    public ArrayList<View> getItemsInReadingOrder() {
    public ArrayList<View> getItemsInRankOrder() {
        if (mItemsInvalidated) {
            mItemsInReadingOrder.clear();
            mContent.iterateOverItems(new ItemOperator() {
            mItemsInRankOrder.clear();
            mItemsInRankOrder.addAll(getItemsInReadingOrder());
            mItemsInRankOrder.sort(VIEW_RANK_COMPARATOR);

            mItemsInvalidated = false;
        }
        return mItemsInRankOrder;
    }

    /**
     * This is an expensive call. Consider using {@link #getItemsInRankOrder()} instead.
     */
    public ArrayList<View> getItemsInReadingOrder() {
        final ArrayList<View> itemsInReadingOrder = new ArrayList<>();
        mContent.iterateOverItems(new ItemOperator() {
            @Override
            public boolean evaluate(ItemInfo info, View view) {
                    mItemsInReadingOrder.add(view);
                itemsInReadingOrder.add(view);
                return false;
            }
        });
            mItemsInvalidated = false;
        }
        return mItemsInReadingOrder;
        return itemsInReadingOrder;
    }

    public List<BubbleTextView> getItemsOnCurrentPage() {
        ArrayList<View> allItems = getItemsInReadingOrder();
        ArrayList<View> allItems = getItemsInRankOrder();
        int currentPage = mContent.getCurrentPage();
        int lastPage = mContent.getPageCount() - 1;
        int totalItemsInFolder = allItems.size();
@@ -1622,6 +1625,13 @@ public class Folder extends AbstractFloatingView implements DragSource, View.OnC
        }
    };

    public static final Comparator<View> VIEW_RANK_COMPARATOR = new Comparator<View>() {
        @Override
        public int compare(View lhs, View rhs) {
            return ITEM_POS_COMPARATOR.compare((ItemInfo) lhs.getTag(), (ItemInfo) rhs.getTag());
        }
    };

    /**
     * Temporary resource held while we don't want to handle info changes
     */
+1 −1
Original line number Diff line number Diff line
@@ -575,7 +575,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
        mPreviewVerifier.setFolderInfo(mFolder.getInfo());

        List<BubbleTextView> itemsToDisplay = new ArrayList<>();
        List<View> allItems = mFolder.getItemsInReadingOrder();
        List<View> allItems = mFolder.getItemsInRankOrder();
        int numItems = allItems.size();
        for (int rank = 0; rank < numItems; ++rank) {
            if (mPreviewVerifier.isItemInPreview(rank)) {
+2 −27
Original line number Diff line number Diff line
@@ -25,40 +25,15 @@ import com.android.launcher3.config.FeatureFlags;
 */
public class FolderIconPreviewVerifier {

    private final int mMaxGridCountX;
    private final int mMaxGridCountY;
    private final int mMaxItemsPerPage;
    private final int[] mGridSize = new int[2];

    private int mGridCountX;
    private boolean mDisplayingUpperLeftQuadrant = false;

    public FolderIconPreviewVerifier(InvariantDeviceProfile profile) {
        mMaxGridCountX = profile.numFolderColumns;
        mMaxGridCountY = profile.numFolderRows;
        mMaxItemsPerPage = mMaxGridCountX * mMaxGridCountY;
        // b/37570804
    }

    public void setFolderInfo(FolderInfo info) {
        int numItemsInFolder = info.contents.size();
        mDisplayingUpperLeftQuadrant = FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION
                && !FeatureFlags.LAUNCHER3_LEGACY_FOLDER_ICON
                && numItemsInFolder > FolderIcon.NUM_ITEMS_IN_PREVIEW;

        if (mDisplayingUpperLeftQuadrant) {
            FolderPagedView.calculateGridSize(info.contents.size(), 0, 0, mMaxGridCountX,
                    mMaxGridCountY, mMaxItemsPerPage, mGridSize);
            mGridCountX = mGridSize[0];
        }
        // b/37570804
    }

    public boolean isItemInPreview(int rank) {
        if (mDisplayingUpperLeftQuadrant) {
            // Returns true iff the icon is in the 2x2 upper left quadrant of the Folder.
            int col = rank % mGridCountX;
            int row = rank / mGridCountX;
            return col < 2 && row < 2;
        }
        return rank < FolderIcon.NUM_ITEMS_IN_PREVIEW;
    }
}
Loading