mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 03:08:19 +00:00
Add new motion for when Folder preview changes due to onDrop.
Instead of changing the display order of the Folder to preserve the upper left quadrant, we are opting to change the Folder Icon preview to always show the upper left quadrant. This means that when adding items to a Folder, the preview items may change. (They will change when the column size increases). Bug: 27944225 Bug: 63140071 Change-Id: I863c2479469d68559cab2878030c2087d48217d6
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user