diff options
Diffstat (limited to 'src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java')
-rw-r--r-- | src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java | 69 |
1 files changed, 58 insertions, 11 deletions
diff --git a/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java b/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java index ff357c0bc..f25345ee8 100644 --- a/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java +++ b/src/com/android/launcher3/folder/ClippedFolderIconLayoutRule.java @@ -1,15 +1,18 @@ package com.android.launcher3.folder; + 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; - final float MAX_RADIUS_DILATION = 0.15f; - final float ITEM_RADIUS_SCALE_FACTOR = 1.33f; + private static final float MIN_SCALE = 0.48f; + private static final float MAX_SCALE = 0.58f; + private static final float MAX_RADIUS_DILATION = 0.15f; + private static final float ITEM_RADIUS_SCALE_FACTOR = 1.33f; + + private static final int EXIT_INDEX = -2; + private static final int ENTER_INDEX = -3; private float[] mTmpPoint = new float[2]; @@ -31,21 +34,29 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule @Override public PreviewItemDrawingParams computePreviewItemDrawingParams(int index, int curNumItems, PreviewItemDrawingParams params) { - float totalScale = scaleForItem(index, curNumItems); float transX; float transY; float overlayAlpha = 0; - // Items beyond those displayed in the preview are animated to the center - if (index >= MAX_NUM_ITEMS_IN_PREVIEW) { - transX = transY = mAvailableSpace / 2 - (mIconSize * totalScale) / 2; + if (index == getExitIndex()) { + // 0 1 * <-- Exit position (row 0, col 2) + // 2 3 + getGridPosition(0, 2, mTmpPoint); + } else if (index == getEnterIndex()) { + // 0 1 + // 2 3 * <-- Enter position (row 1, col 2) + getGridPosition(1, 2, mTmpPoint); + } else if (index >= MAX_NUM_ITEMS_IN_PREVIEW) { + // Items beyond those displayed in the preview are animated to the center + mTmpPoint[0] = mTmpPoint[1] = mAvailableSpace / 2 - (mIconSize * totalScale) / 2; } else { getPosition(index, curNumItems, mTmpPoint); - transX = mTmpPoint[0]; - transY = mTmpPoint[1]; } + transX = mTmpPoint[0]; + transY = mTmpPoint[1]; + if (params == null) { params = new PreviewItemDrawingParams(transX, transY, totalScale, overlayAlpha); } else { @@ -55,6 +66,27 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule return params; } + /** + * Builds a grid based on the positioning of the items when there are + * {@link #MAX_NUM_ITEMS_IN_PREVIEW} in the preview. + * + * Positions in the grid: 0 1 // 0 is row 0, col 1 + * 2 3 // 3 is row 1, col 1 + */ + private void getGridPosition(int row, int col, float[] result) { + // We use position 0 and 3 to calculate the x and y distances between items. + getPosition(0, 4, result); + float left = result[0]; + float top = result[1]; + + getPosition(3, 4, result); + float dx = result[0] - left; + float dy = result[1] - top; + + result[0] = left + (col * dx); + result[1] = top + (row * dy); + } + private void getPosition(int index, int curNumItems, float[] result) { // The case of two items is homomorphic to the case of one. curNumItems = Math.max(curNumItems, 2); @@ -127,4 +159,19 @@ public class ClippedFolderIconLayoutRule implements FolderIcon.PreviewLayoutRule public boolean clipToBackground() { return true; } + + @Override + public boolean hasEnterExitIndices() { + return true; + } + + @Override + public int getExitIndex() { + return EXIT_INDEX; + } + + @Override + public int getEnterIndex() { + return ENTER_INDEX; + } } |