From e41dd483e63ec1aa241efb5005b11a2760800a9e Mon Sep 17 00:00:00 2001 From: Jon Miranda Date: Fri, 4 Jun 2021 17:31:02 -0700 Subject: [PATCH] New folder icon style (uncropped icons). - Switch Circle to PathShape as it allows for more flexibility on choosing what gets cropped. - Remove shadows, and stroke. Bug: 188095988 Test: manual Change-Id: I602b3efcd35c2c11dc3461f49099c2f2a56eae59 --- res/layout/user_folder_icon_normalized.xml | 1 - .../folder/ClippedFolderIconLayoutRule.java | 12 +++---- src/com/android/launcher3/folder/Folder.java | 23 +++++++++++-- .../folder/FolderAnimationManager.java | 19 ++++++++++- .../android/launcher3/folder/FolderIcon.java | 3 -- .../launcher3/folder/FolderPagedView.java | 24 +++++++++++-- .../launcher3/folder/PreviewBackground.java | 10 +++++- .../android/launcher3/graphics/IconShape.java | 34 ++++++++++++++++--- 8 files changed, 102 insertions(+), 24 deletions(-) diff --git a/res/layout/user_folder_icon_normalized.xml b/res/layout/user_folder_icon_normalized.xml index 8b188577a8..15131f11d7 100644 --- a/res/layout/user_folder_icon_normalized.xml +++ b/res/layout/user_folder_icon_normalized.xml @@ -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" > { +public class FolderPagedView extends PagedView implements ClipPathView { private static final String TAG = "FolderPagedView"; @@ -89,6 +91,8 @@ public class FolderPagedView extends PagedView { 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 { @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 { public int itemsPerPage() { return mOrganizer.getMaxItemsPerPage(); } + + @Override + public void setClipPath(Path clipPath) { + mClipPath = clipPath; + invalidate(); + } } diff --git a/src/com/android/launcher3/folder/PreviewBackground.java b/src/com/android/launcher3/folder/PreviewBackground.java index 4eab63e54f..204decbee4 100644 --- a/src/com/android/launcher3/folder/PreviewBackground.java +++ b/src/com/android/launcher3/folder/PreviewBackground.java @@ -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(); } diff --git a/src/com/android/launcher3/graphics/IconShape.java b/src/com/android/launcher3/graphics/IconShape.java index 2da679c422..f82b07ebfa 100644 --- a/src/com/android/launcher3/graphics/IconShape.java +++ b/src/com/android/launcher3/graphics/IconShape.java @@ -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; }