Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

CheckBoxDrawable: Remove the sharp corner of check box animation #275

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down