From 4f5e573d3a0084e6a76354ded00ab57fe4aa2fdf Mon Sep 17 00:00:00 2001 From: Federico Baron Date: Wed, 21 Sep 2022 17:58:34 -0700 Subject: [PATCH] Replace drawRect with drawable for delightful pagination In order to eventually use the shape referenced in the task (https://docs.google.com/presentation/d/1V9-1C3mJ3zRGsuzzzYExisr9vLYecgADa1FucMoW_aw/edit#slide=id.g14256d0c614_0_311) we need to use a drawable. This CL adds the drawable that will be changed to that shape and uses it in PageIndicatorDots.java instead of using drawRect. Bug: 247561880 Test: manual Change-Id: I01e10bd9ddc7e378f2dcfdee0f84ba7443c3b9d3 --- res/drawable/page_indicator.xml | 6 ++++ res/values/dimens.xml | 2 +- .../pageindicators/PageIndicatorDots.java | 29 ++++++++++++++----- 3 files changed, 29 insertions(+), 8 deletions(-) create mode 100644 res/drawable/page_indicator.xml diff --git a/res/drawable/page_indicator.xml b/res/drawable/page_indicator.xml new file mode 100644 index 0000000000..c0ccc49250 --- /dev/null +++ b/res/drawable/page_indicator.xml @@ -0,0 +1,6 @@ + + + + + \ No newline at end of file diff --git a/res/values/dimens.xml b/res/values/dimens.xml index 5dae9f2ac4..47584e2baf 100644 --- a/res/values/dimens.xml +++ b/res/values/dimens.xml @@ -248,7 +248,7 @@ 8dp - 10dp + 10dp 9dp diff --git a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java index 439e1c7a45..262437981f 100644 --- a/src/com/android/launcher3/pageindicators/PageIndicatorDots.java +++ b/src/com/android/launcher3/pageindicators/PageIndicatorDots.java @@ -30,6 +30,7 @@ import android.graphics.Outline; import android.graphics.Paint; import android.graphics.Paint.Style; import android.graphics.RectF; +import android.graphics.drawable.Drawable; import android.util.AttributeSet; import android.util.Property; import android.view.View; @@ -84,9 +85,11 @@ public class PageIndicatorDots extends View implements PageIndicator { }; private final Paint mPaginationPaint; + private final Drawable mPageIndicatorDrawable; private final float mDotRadius; private final float mCircleGap; private final float mPageIndicatorSize; + private final float mPageIndicatorRadius; private final boolean mIsRtl; private int mNumPages; @@ -125,13 +128,22 @@ public class PageIndicatorDots extends View implements PageIndicator { mPaginationPaint.setColor(Themes.getAttrColor(context, R.attr.folderPaginationColor)); mDotRadius = getResources().getDimension(R.dimen.page_indicator_dot_size) / 2; + if (SHOW_DELIGHTFUL_PAGINATION_FOLDER.get()) { + mPageIndicatorSize = getResources().getDimension( + R.dimen.page_indicator_size); + mPageIndicatorRadius = mPageIndicatorSize / 2; + mPageIndicatorDrawable = context.getDrawable(R.drawable.page_indicator); + mPageIndicatorDrawable.setBounds(0, 0, (int) mPageIndicatorSize, + (int) mPageIndicatorSize); mCircleGap = DOT_GAP_FACTOR_FLOAT * mDotRadius; + } else { + mPageIndicatorSize = 0; + mPageIndicatorRadius = 0; + mPageIndicatorDrawable = null; mCircleGap = DOT_GAP_FACTOR * mDotRadius; } - mPageIndicatorSize = getResources().getDimension( - R.dimen.page_indicator_current_page_indicator_size); if (!SHOW_DELIGHTFUL_PAGINATION_FOLDER.get()) { setOutlineProvider(new MyOutlineProver()); } @@ -307,16 +319,19 @@ public class PageIndicatorDots extends View implements PageIndicator { if (SHOW_DELIGHTFUL_PAGINATION_FOLDER.get()) { RectF currRect = getActiveRect(); - int scrollPerPage = getScrollPerPage(); + // Moves the canvas to start at the top left corner of the page indicator + canvas.translate(currRect.left, currRect.top); + + int scrollPerPage = getScrollPerPage(); // This IF is to avoid division by 0 if (scrollPerPage != 0) { int delta = mCurrentScroll % scrollPerPage; canvas.rotate((INDICATOR_ROTATION * delta) / scrollPerPage, - currRect.centerX(), currRect.centerY()); + mPageIndicatorRadius, mPageIndicatorRadius); } - canvas.drawRect(currRect, mPaginationPaint); + mPageIndicatorDrawable.draw(canvas); } else { canvas.drawRoundRect(getActiveRect(), mDotRadius, mDotRadius, mPaginationPaint); } @@ -333,7 +348,7 @@ public class PageIndicatorDots extends View implements PageIndicator { float startXIndicator = ((getWidth() - (mNumPages * mCircleGap) + mDotRadius) / 2) - getOffset(); float indicatorPosition = startXIndicator + getIndicatorScrollDistance() - + (mPageIndicatorSize / 2); + + mPageIndicatorRadius; // If the indicator gets close enough to a dot then we change the radius // of the dot based on how close the indicator is to it. @@ -390,7 +405,7 @@ public class PageIndicatorDots extends View implements PageIndicator { * the indicator is centered in with the indicator circles */ private float getOffset() { - return (mPageIndicatorSize / 2) - mDotRadius; + return mPageIndicatorRadius - mDotRadius; } /**