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

Commit 72d90876 authored by Jonathan Miranda's avatar Jonathan Miranda Committed by Android (Google) Code Review
Browse files

Merge "Update PreviewLayoutRule API to prepare for new folder animation." into ub-launcher3-master

parents 00002d02 12b616c7
Loading
Loading
Loading
Loading
+31 −9
Original line number Diff line number Diff line
package com.android.launcher3.folder;

import android.graphics.Path;
import android.graphics.Point;
import android.view.View;

import com.android.launcher3.DeviceProfile;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.Utilities;
import com.android.launcher3.config.FeatureFlags;

import java.util.ArrayList;
import java.util.List;

public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {

    static final int MAX_NUM_ITEMS_IN_PREVIEW = 4;
    private static final int MIN_NUM_ITEMS_IN_PREVIEW = 2;
    private static final int MAX_NUM_ITEMS_PER_ROW = 2;

    final float MIN_SCALE = 0.48f;
    final float MAX_SCALE = 0.58f;
@@ -38,7 +39,7 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
    public FolderIcon.PreviewItemDrawingParams computePreviewItemDrawingParams(int index,
            int curNumItems, FolderIcon.PreviewItemDrawingParams params) {

        float totalScale = scaleForNumItems(curNumItems);
        float totalScale = scaleForItem(index, curNumItems);
        float transX;
        float transY;
        float overlayAlpha = 0;
@@ -94,7 +95,7 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
                MIN_NUM_ITEMS_IN_PREVIEW) / (MAX_NUM_ITEMS_IN_PREVIEW - MIN_NUM_ITEMS_IN_PREVIEW));
        double theta = theta0 + index * (2 * Math.PI / curNumItems) * direction;

        float halfIconSize = (mIconSize * scaleForNumItems(curNumItems)) / 2;
        float halfIconSize = (mIconSize * scaleForItem(index, curNumItems)) / 2;

        // Map the location along the circle, and offset the coordinates to represent the center
        // of the icon, and to be based from the top / left of the preview area. The y component
@@ -104,7 +105,9 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule

    }

    private float scaleForNumItems(int numItems) {
    @Override
    public float scaleForItem(int index, int numItems) {
        // Scale is determined by the number of items in the preview.
        float scale = 1f;
        if (numItems <= 2) {
            scale = MAX_SCALE;
@@ -118,7 +121,7 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
    }

    @Override
    public int numItems() {
    public int maxNumItems() {
        return MAX_NUM_ITEMS_IN_PREVIEW;
    }

@@ -127,4 +130,23 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule
        return true;
    }

    @Override
    public List<View> getItemsToDisplay(Folder folder) {
        List<View> items = new ArrayList<>(folder.getItemsInReadingOrder());
        int numItems = items.size();
        if (FeatureFlags.LAUNCHER3_NEW_FOLDER_ANIMATION && numItems > MAX_NUM_ITEMS_IN_PREVIEW) {
            // We match the icons in the preview with the layout of the opened folder (b/27944225),
            // but we still need to figure out how we want to handle updating the preview when the
            // upper left quadrant changes.
            int appsPerRow = folder.mContent.getPageAt(0).getCountX();
            int appsToDelete = appsPerRow - MAX_NUM_ITEMS_PER_ROW;

            // We only display the upper left quadrant.
            while (appsToDelete > 0) {
                items.remove(MAX_NUM_ITEMS_PER_ROW);
                appsToDelete--;
            }
        }
        return items.subList(0, Math.min(numItems, MAX_NUM_ITEMS_IN_PREVIEW));
    }
}
+9 −8
Original line number Diff line number Diff line
@@ -73,6 +73,7 @@ import com.android.launcher3.graphics.IconPalette;
import com.android.launcher3.util.Thunk;

import java.util.ArrayList;
import java.util.List;

/**
 * An icon that can appear on in the workspace representing an {@link Folder}.
@@ -327,7 +328,7 @@ public class FolderIcon extends FrameLayout implements FolderListener {
            to.offset(center[0] - animateView.getMeasuredWidth() / 2,
                      center[1] - animateView.getMeasuredHeight() / 2);

            float finalAlpha = index < mPreviewLayoutRule.numItems() ? 0.5f : 0f;
            float finalAlpha = index < mPreviewLayoutRule.maxNumItems() ? 0.5f : 0f;

            float finalScale = scale * scaleRelativeToDragLayer;
            dragLayer.animateView(animateView, from, to, finalAlpha,
@@ -425,8 +426,8 @@ public class FolderIcon extends FrameLayout implements FolderListener {
    }

    private float getLocalCenterForIndex(int index, int curNumItems, int[] center) {
        mTmpParams = computePreviewItemDrawingParams(Math.min(mPreviewLayoutRule.numItems(), index),
                curNumItems, mTmpParams);
        mTmpParams = computePreviewItemDrawingParams(
                Math.min(mPreviewLayoutRule.maxNumItems(), index), curNumItems, mTmpParams);

        mTmpParams.transX += mBackground.basePreviewOffsetX;
        mTmpParams.transY += mBackground.basePreviewOffsetY;
@@ -890,8 +891,8 @@ public class FolderIcon extends FrameLayout implements FolderListener {
    }

    private void updateItemDrawingParams(boolean animate) {
        ArrayList<View> items = mFolder.getItemsInReadingOrder();
        int nItemsInPreview = Math.min(items.size(), mPreviewLayoutRule.numItems());
        List<View> items = mPreviewLayoutRule.getItemsToDisplay(mFolder);
        int nItemsInPreview = items.size();

        int prevNumItems = mDrawingParams.size();

@@ -1062,10 +1063,10 @@ public class FolderIcon extends FrameLayout implements FolderListener {
    public interface PreviewLayoutRule {
        PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
            PreviewItemDrawingParams params);

        void init(int availableSpace, int intrinsicIconSize, boolean rtl);

        int numItems();
        float scaleForItem(int index, int totalNumItems);
        int maxNumItems();
        boolean clipToBackground();
        List<View> getItemsToDisplay(Folder folder);
    }
}
+19 −3
Original line number Diff line number Diff line
@@ -16,10 +16,12 @@

package com.android.launcher3.folder;

import android.graphics.Path;
import android.view.View;

import com.android.launcher3.folder.FolderIcon.PreviewItemDrawingParams;

import java.util.List;

public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {

    static final int MAX_NUM_ITEMS_IN_PREVIEW = 3;
@@ -54,10 +56,10 @@ public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {
    @Override
    public PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems,
            PreviewItemDrawingParams params) {
        float scale = scaleForItem(index, curNumItems);

        index = MAX_NUM_ITEMS_IN_PREVIEW - index - 1;
        float r = (index * 1.0f) / (MAX_NUM_ITEMS_IN_PREVIEW - 1);
        float scale = (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r));

        float offset = (1 - r) * mMaxPerspectiveShift;
        float scaledSize = scale * mBaselineIconSize;
@@ -80,12 +82,26 @@ public class StackFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule {
    }

    @Override
    public int numItems() {
    public int maxNumItems() {
        return MAX_NUM_ITEMS_IN_PREVIEW;
    }

    @Override
    public float scaleForItem(int index, int numItems) {
        // Scale is determined by the position of the icon in the preview.
        index = MAX_NUM_ITEMS_IN_PREVIEW - index - 1;
        float r = (index * 1.0f) / (MAX_NUM_ITEMS_IN_PREVIEW - 1);
        return (1 - PERSPECTIVE_SCALE_FACTOR * (1 - r));
    }

    @Override
    public boolean clipToBackground() {
        return false;
    }

    @Override
    public List<View> getItemsToDisplay(Folder folder) {
        List<View> items = folder.getItemsInReadingOrder();
        return items.subList(0, Math.min(items.size(), MAX_NUM_ITEMS_IN_PREVIEW));
    }
}
+1 −0
Original line number Diff line number Diff line
@@ -28,6 +28,7 @@ public final class FeatureFlags {
    public static boolean LAUNCHER3_USE_SYSTEM_DRAG_DRIVER = true;
    public static boolean LAUNCHER3_DISABLE_PINCH_TO_OVERVIEW = false;
    public static boolean LAUNCHER3_ALL_APPS_PULL_UP = true;
    public static boolean LAUNCHER3_NEW_FOLDER_ANIMATION = false;

    // Feature flag to enable moving the QSB on the 0th screen of the workspace.
    public static final boolean QSB_ON_FIRST_SCREEN = true;