From f93f5abe17d6ba47a8a37159e62da741fa2fd2ed Mon Sep 17 00:00:00 2001 From: gauthams Date: Tue, 23 Jan 2018 23:09:10 -0500 Subject: [PATCH] Update chip background and stroke drawing to no longer draw background outside stroke PiperOrigin-RevId: 183033077 --- .../support/design/chip/ChipDrawable.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/lib/java/android/support/design/chip/ChipDrawable.java b/lib/java/android/support/design/chip/ChipDrawable.java index 1040d6c32..9c4af57a6 100644 --- a/lib/java/android/support/design/chip/ChipDrawable.java +++ b/lib/java/android/support/design/chip/ChipDrawable.java @@ -534,15 +534,20 @@ public class ChipDrawable extends Drawable implements TintAwareDrawable, Callbac * that the stroke perfectly fills the bounds of the chip. */ private void drawChipStroke(@NonNull Canvas canvas, Rect bounds) { - chipPaint.setColor(currentChipStrokeColor); - chipPaint.setStyle(Style.STROKE); - chipPaint.setColorFilter(getTintColorFilter()); - rectF.set( - bounds.left + chipStrokeWidth / 2f, - bounds.top + chipStrokeWidth / 2f, - bounds.right - chipStrokeWidth / 2f, - bounds.bottom - chipStrokeWidth / 2f); - canvas.drawRoundRect(rectF, chipCornerRadius, chipCornerRadius, chipPaint); + if (chipStrokeWidth > 0) { + chipPaint.setColor(currentChipStrokeColor); + chipPaint.setStyle(Style.STROKE); + chipPaint.setColorFilter(getTintColorFilter()); + rectF.set( + bounds.left + chipStrokeWidth / 2f, + bounds.top + chipStrokeWidth / 2f, + bounds.right - chipStrokeWidth / 2f, + bounds.bottom - chipStrokeWidth / 2f); + // We need to adjust stroke's corner radius so that the corners of the background are not + // drawn outside stroke + float strokeCornerRadius = chipCornerRadius - chipStrokeWidth / 2f; + canvas.drawRoundRect(rectF, strokeCornerRadius, strokeCornerRadius, chipPaint); + } } private void drawCompatRipple(@NonNull Canvas canvas, Rect bounds) {