mirror of
https://github.com/LawnchairLauncher/lawnchair.git
synced 2026-02-20 11:18:21 +00:00
Merge "New folder icon style (uncropped icons)." into sc-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
93c0cfadb1
@@ -18,7 +18,6 @@
|
||||
xmlns:launcher="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/round_rect_folder"
|
||||
android:orientation="vertical" >
|
||||
|
||||
<com.android.launcher3.folder.FolderPagedView
|
||||
|
||||
@@ -5,10 +5,10 @@ public class ClippedFolderIconLayoutRule {
|
||||
public static final int MAX_NUM_ITEMS_IN_PREVIEW = 4;
|
||||
private static final int MIN_NUM_ITEMS_IN_PREVIEW = 2;
|
||||
|
||||
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 float MIN_SCALE = 0.44f;
|
||||
private static final float MAX_SCALE = 0.54f;
|
||||
private static final float MAX_RADIUS_DILATION = 0.10f;
|
||||
private static final float ITEM_RADIUS_SCALE_FACTOR = 1.2f;
|
||||
|
||||
public static final int EXIT_INDEX = -2;
|
||||
public static final int ENTER_INDEX = -3;
|
||||
@@ -130,10 +130,8 @@ public class ClippedFolderIconLayoutRule {
|
||||
public float scaleForItem(int numItems) {
|
||||
// Scale is determined by the number of items in the preview.
|
||||
final float scale;
|
||||
if (numItems <= 2) {
|
||||
if (numItems <= 3) {
|
||||
scale = MAX_SCALE;
|
||||
} else if (numItems == 3) {
|
||||
scale = (MAX_SCALE + MIN_SCALE) / 2;
|
||||
} else {
|
||||
scale = MIN_SCALE;
|
||||
}
|
||||
|
||||
@@ -41,6 +41,7 @@ import android.graphics.Insets;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.Rect;
|
||||
import android.graphics.RectF;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.graphics.drawable.GradientDrawable;
|
||||
import android.os.Build;
|
||||
import android.text.InputType;
|
||||
@@ -67,6 +68,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
import androidx.annotation.RequiresApi;
|
||||
import androidx.core.content.res.ResourcesCompat;
|
||||
import androidx.core.graphics.ColorUtils;
|
||||
|
||||
import com.android.launcher3.AbstractFloatingView;
|
||||
@@ -250,6 +252,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
// so that we can cancel it when starting mColorChangeAnimator.
|
||||
private ObjectAnimator mOpenAnimationColorChangeAnimator;
|
||||
|
||||
private GradientDrawable mBackground;
|
||||
|
||||
/**
|
||||
* Used to inflate the Workspace from XML.
|
||||
*
|
||||
@@ -268,6 +272,12 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
// name is complete, we have something to focus on, thus hiding the cursor and giving
|
||||
// reliable behavior when clicking the text field (since it will always gain focus on click).
|
||||
setFocusableInTouchMode(true);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Drawable getBackground() {
|
||||
return mBackground;
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -276,6 +286,9 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
final DeviceProfile dp = mActivityContext.getDeviceProfile();
|
||||
final int paddingLeftRight = dp.folderContentPaddingLeftRight;
|
||||
|
||||
mBackground = (GradientDrawable) ResourcesCompat.getDrawable(getResources(),
|
||||
R.drawable.round_rect_folder, getContext().getTheme());
|
||||
|
||||
mContent = findViewById(R.id.folder_content);
|
||||
mContent.setPadding(paddingLeftRight, dp.folderContentPaddingTop, paddingLeftRight, 0);
|
||||
mContent.setFolder(this);
|
||||
@@ -1213,6 +1226,8 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
lp.x = left;
|
||||
lp.y = top;
|
||||
|
||||
mBackground.setBounds(0, 0, width, height);
|
||||
|
||||
if (mColorExtractor != null) {
|
||||
mColorExtractor.removeLocations();
|
||||
mColorExtractor.setListener(mColorListener);
|
||||
@@ -1714,14 +1729,16 @@ public class Folder extends AbstractFloatingView implements ClipPathView, DragSo
|
||||
}
|
||||
|
||||
@Override
|
||||
public void draw(Canvas canvas) {
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
if (mClipPath != null) {
|
||||
int count = canvas.save();
|
||||
canvas.clipPath(mClipPath);
|
||||
super.draw(canvas);
|
||||
mBackground.draw(canvas);
|
||||
canvas.restoreToCount(count);
|
||||
super.dispatchDraw(canvas);
|
||||
} else {
|
||||
super.draw(canvas);
|
||||
mBackground.draw(canvas);
|
||||
super.dispatchDraw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import android.view.animation.AnimationUtils;
|
||||
|
||||
import com.android.launcher3.BubbleTextView;
|
||||
import com.android.launcher3.CellLayout;
|
||||
import com.android.launcher3.DeviceProfile;
|
||||
import com.android.launcher3.R;
|
||||
import com.android.launcher3.ShortcutAndWidgetContainer;
|
||||
import com.android.launcher3.Utilities;
|
||||
@@ -80,6 +81,8 @@ public class FolderAnimationManager {
|
||||
|
||||
private ObjectAnimator mBgColorAnimator;
|
||||
|
||||
private DeviceProfile mDeviceProfile;
|
||||
|
||||
public FolderAnimationManager(Folder folder, boolean isOpening) {
|
||||
mFolder = folder;
|
||||
mContent = folder.mContent;
|
||||
@@ -89,7 +92,8 @@ public class FolderAnimationManager {
|
||||
mPreviewBackground = mFolderIcon.mBackground;
|
||||
|
||||
mContext = folder.getContext();
|
||||
mPreviewVerifier = new FolderGridOrganizer(folder.mActivityContext.getDeviceProfile().inv);
|
||||
mDeviceProfile = folder.mActivityContext.getDeviceProfile();
|
||||
mPreviewVerifier = new FolderGridOrganizer(mDeviceProfile.inv);
|
||||
|
||||
mIsOpening = isOpening;
|
||||
|
||||
@@ -211,8 +215,21 @@ public class FolderAnimationManager {
|
||||
play(a, getAnimator(mFolder.mContent, SCALE_PROPERTY, initialScale, finalScale));
|
||||
play(a, getAnimator(mFolder.mFooter, SCALE_PROPERTY, initialScale, finalScale));
|
||||
play(a, mFolderIcon.mFolderName.createTextAlphaAnimator(!mIsOpening));
|
||||
|
||||
// Create reveal animator for the folder background
|
||||
play(a, getShape().createRevealAnimator(
|
||||
mFolder, startRect, endRect, finalRadius, !mIsOpening));
|
||||
|
||||
// Create reveal animator for the folder content (capture the top 4 icons 2x2)
|
||||
int width = mContent.getPaddingLeft() + mDeviceProfile.folderCellLayoutBorderSpacingPx
|
||||
+ mDeviceProfile.folderCellWidthPx * 2;
|
||||
int height = mContent.getPaddingTop() + mDeviceProfile.folderCellLayoutBorderSpacingPx
|
||||
+ mDeviceProfile.folderCellHeightPx * 2;
|
||||
Rect startRect2 = new Rect(0, 0, width, height);
|
||||
play(a, getShape().createRevealAnimator(
|
||||
mFolder.getContent(), startRect2, endRect, finalRadius, !mIsOpening));
|
||||
|
||||
|
||||
// Fade in the folder name, as the text can overlap the icons when grid size is small.
|
||||
mFolder.mFolderName.setAlpha(mIsOpening ? 0f : 1f);
|
||||
play(a, getAnimator(mFolder.mFolderName, View.ALPHA, 0, 1),
|
||||
|
||||
@@ -614,10 +614,7 @@ public class FolderIcon extends FrameLayout implements FolderListener, IconLabel
|
||||
|
||||
if (mCurrentPreviewItems.isEmpty() && !mAnimating) return;
|
||||
|
||||
final int saveCount = canvas.save();
|
||||
canvas.clipPath(mBackground.getClipPath());
|
||||
mPreviewItemManager.draw(canvas);
|
||||
canvas.restoreToCount(saveCount);
|
||||
|
||||
if (!mBackground.drawingDelegated()) {
|
||||
mBackground.drawBackgroundStroke(canvas);
|
||||
|
||||
@@ -22,6 +22,7 @@ import static com.android.launcher3.AbstractFloatingView.TYPE_FOLDER;
|
||||
import android.annotation.SuppressLint;
|
||||
import android.content.Context;
|
||||
import android.graphics.Canvas;
|
||||
import android.graphics.Path;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.util.ArrayMap;
|
||||
import android.util.AttributeSet;
|
||||
@@ -49,6 +50,7 @@ import com.android.launcher3.touch.ItemClickHandler;
|
||||
import com.android.launcher3.util.Thunk;
|
||||
import com.android.launcher3.util.ViewCache;
|
||||
import com.android.launcher3.views.ActivityContext;
|
||||
import com.android.launcher3.views.ClipPathView;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Iterator;
|
||||
@@ -57,7 +59,7 @@ import java.util.Map;
|
||||
import java.util.function.ToIntFunction;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class FolderPagedView extends PagedView<PageIndicatorDots> {
|
||||
public class FolderPagedView extends PagedView<PageIndicatorDots> implements ClipPathView {
|
||||
|
||||
private static final String TAG = "FolderPagedView";
|
||||
|
||||
@@ -89,6 +91,8 @@ public class FolderPagedView extends PagedView<PageIndicatorDots> {
|
||||
|
||||
private Folder mFolder;
|
||||
|
||||
private Path mClipPath;
|
||||
|
||||
// If the views are attached to the folder or not. A folder should be bound when its
|
||||
// animating or is open.
|
||||
private boolean mViewsBound = false;
|
||||
@@ -128,8 +132,16 @@ public class FolderPagedView extends PagedView<PageIndicatorDots> {
|
||||
|
||||
@Override
|
||||
protected void dispatchDraw(Canvas canvas) {
|
||||
mFocusIndicatorHelper.draw(canvas);
|
||||
super.dispatchDraw(canvas);
|
||||
if (mClipPath != null) {
|
||||
int count = canvas.save();
|
||||
canvas.clipPath(mClipPath);
|
||||
mFocusIndicatorHelper.draw(canvas);
|
||||
super.dispatchDraw(canvas);
|
||||
canvas.restoreToCount(count);
|
||||
} else {
|
||||
mFocusIndicatorHelper.draw(canvas);
|
||||
super.dispatchDraw(canvas);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -628,4 +640,10 @@ public class FolderPagedView extends PagedView<PageIndicatorDots> {
|
||||
public int itemsPerPage() {
|
||||
return mOrganizer.getMaxItemsPerPage();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setClipPath(Path clipPath) {
|
||||
mClipPath = clipPath;
|
||||
invalidate();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -51,6 +51,7 @@ import com.android.launcher3.views.ActivityContext;
|
||||
public class PreviewBackground extends CellLayout.DelegatedCellDrawing {
|
||||
|
||||
private static final boolean DRAW_SHADOW = false;
|
||||
private static final boolean DRAW_STROKE = false;
|
||||
|
||||
private static final int CONSUMPTION_ANIMATION_DURATION = 100;
|
||||
|
||||
@@ -303,6 +304,10 @@ public class PreviewBackground extends CellLayout.DelegatedCellDrawing {
|
||||
}
|
||||
|
||||
public void animateBackgroundStroke() {
|
||||
if (!DRAW_STROKE) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (mStrokeAlphaAnimator != null) {
|
||||
mStrokeAlphaAnimator.cancel();
|
||||
}
|
||||
@@ -319,6 +324,9 @@ public class PreviewBackground extends CellLayout.DelegatedCellDrawing {
|
||||
}
|
||||
|
||||
public void drawBackgroundStroke(Canvas canvas) {
|
||||
if (!DRAW_STROKE) {
|
||||
return;
|
||||
}
|
||||
mPaint.setColor(setColorAlphaBound(mStrokeColor, mStrokeAlpha));
|
||||
mPaint.setStyle(Paint.Style.STROKE);
|
||||
mPaint.setStrokeWidth(mStrokeWidth);
|
||||
@@ -363,7 +371,7 @@ public class PreviewBackground extends CellLayout.DelegatedCellDrawing {
|
||||
}
|
||||
|
||||
mDrawingDelegate = null;
|
||||
isClipping = true;
|
||||
isClipping = false;
|
||||
invalidate();
|
||||
}
|
||||
|
||||
|
||||
@@ -156,19 +156,43 @@ public abstract class IconShape {
|
||||
}
|
||||
}
|
||||
|
||||
public static final class Circle extends SimpleRectShape {
|
||||
public static final class Circle extends PathShape {
|
||||
|
||||
@Override
|
||||
public void drawShape(Canvas canvas, float offsetX, float offsetY, float radius, Paint p) {
|
||||
canvas.drawCircle(radius + offsetX, radius + offsetY, radius, p);
|
||||
private final float[] mTempRadii = new float[8];
|
||||
|
||||
protected AnimatorUpdateListener newUpdateListener(Rect startRect, Rect endRect,
|
||||
float endRadius, Path outPath) {
|
||||
float r1 = getStartRadius(startRect);
|
||||
|
||||
float[] startValues = new float[] {
|
||||
startRect.left, startRect.top, startRect.right, startRect.bottom, r1, r1};
|
||||
float[] endValues = new float[] {
|
||||
endRect.left, endRect.top, endRect.right, endRect.bottom, endRadius, endRadius};
|
||||
|
||||
FloatArrayEvaluator evaluator = new FloatArrayEvaluator(new float[6]);
|
||||
|
||||
return (anim) -> {
|
||||
float progress = (Float) anim.getAnimatedValue();
|
||||
float[] values = evaluator.evaluate(progress, startValues, endValues);
|
||||
outPath.addRoundRect(
|
||||
values[0], values[1], values[2], values[3],
|
||||
getRadiiArray(values[4], values[5]), Path.Direction.CW);
|
||||
};
|
||||
}
|
||||
|
||||
private float[] getRadiiArray(float r1, float r2) {
|
||||
mTempRadii[0] = mTempRadii [1] = mTempRadii[2] = mTempRadii[3] =
|
||||
mTempRadii[6] = mTempRadii[7] = r1;
|
||||
mTempRadii[4] = mTempRadii[5] = r2;
|
||||
return mTempRadii;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void addToPath(Path path, float offsetX, float offsetY, float radius) {
|
||||
path.addCircle(radius + offsetX, radius + offsetY, radius, Path.Direction.CW);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected float getStartRadius(Rect startRect) {
|
||||
return startRect.width() / 2f;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user