From 6f9c4c5158495891829359d5daf081cf45144028 Mon Sep 17 00:00:00 2001 From: Tankery Chen Date: Wed, 14 Oct 2015 17:28:54 +0800 Subject: [PATCH] CheckBoxDrawable: Remove the sharp corner of check box animation Check box will has a sharp corner in animation when the widget's radius is too large. --- .../java/com/rey/material/drawable/CheckBoxDrawable.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/src/main/java/com/rey/material/drawable/CheckBoxDrawable.java b/lib/src/main/java/com/rey/material/drawable/CheckBoxDrawable.java index 4c7292a6..119b2441 100644 --- a/lib/src/main/java/com/rey/material/drawable/CheckBoxDrawable.java +++ b/lib/src/main/java/com/rey/material/drawable/CheckBoxDrawable.java @@ -175,11 +175,13 @@ private void drawChecked(Canvas canvas){ float progress = mAnimProgress / FILL_TIME; float fillWidth = (mBoxSize - mStrokeSize) / 2f * progress; float padding = mStrokeSize / 2f + fillWidth / 2f - 0.5f; + float radius = mCornerRadius * (mBoxSize - padding * 2f) / mBoxSize; + RectF fillRect = new RectF(mBoxRect.left + padding, mBoxRect.top + padding, mBoxRect.right - padding, mBoxRect.bottom - padding); mPaint.setColor(ColorUtil.getMiddleColor(mPrevColor, mCurColor, progress)); mPaint.setStrokeWidth(fillWidth); mPaint.setStyle(Paint.Style.STROKE); - canvas.drawRect(mBoxRect.left + padding, mBoxRect.top + padding, mBoxRect.right - padding, mBoxRect.bottom - padding, mPaint); + canvas.drawRoundRect(fillRect, radius, radius, mPaint); mPaint.setStrokeWidth(mStrokeSize); canvas.drawRoundRect(mBoxRect, mCornerRadius, mCornerRadius, mPaint); @@ -239,11 +241,13 @@ private void drawUnchecked(Canvas canvas){ float progress = (mAnimProgress + FILL_TIME - 1f) / FILL_TIME; float fillWidth = (mBoxSize - mStrokeSize) / 2f * (1f - progress); float padding = mStrokeSize / 2f + fillWidth / 2f - 0.5f; + float radius = mCornerRadius * (mBoxSize - padding * 2f) / mBoxSize; + RectF fillRect = new RectF(mBoxRect.left + padding, mBoxRect.top + padding, mBoxRect.right - padding, mBoxRect.bottom - padding); mPaint.setColor(ColorUtil.getMiddleColor(mPrevColor, mCurColor, progress)); mPaint.setStrokeWidth(fillWidth); mPaint.setStyle(Paint.Style.STROKE); - canvas.drawRect(mBoxRect.left + padding, mBoxRect.top + padding, mBoxRect.right - padding, mBoxRect.bottom - padding, mPaint); + canvas.drawRoundRect(fillRect, radius, radius, mPaint); mPaint.setStrokeWidth(mStrokeSize); canvas.drawRoundRect(mBoxRect, mCornerRadius, mCornerRadius, mPaint);