From a3c6d21a52e8fc16a97821b15a2ede4a2ee3dbaa Mon Sep 17 00:00:00 2001 From: Sergey Solovyev Date: Sun, 29 Apr 2018 19:22:15 +0200 Subject: [PATCH] Add high-contrast shadow to the main text in DirectionDragButton --- .../views/dragbutton/DirectionDragButton.java | 1 + .../views/dragbutton/DirectionDragImageButton.java | 1 + .../android/views/dragbutton/PaintCache.java | 14 +++++++++----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java index f01e1ab4..b199fbf7 100644 --- a/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragButton.java @@ -90,5 +90,6 @@ public class DirectionDragButton extends DragButton implements DirectionDragView @Override public void setHighContrast(boolean highContrast) { textView.setHighContrast(highContrast); + PaintCache.setHighContrast(getPaint(), highContrast, getTextColors().getDefaultColor()); } } diff --git a/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java index 4a59e7f3..d6c3a3ca 100644 --- a/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/DirectionDragImageButton.java @@ -5,6 +5,7 @@ import android.graphics.Canvas; import android.graphics.Typeface; import android.support.annotation.NonNull; import android.support.annotation.Nullable; +import android.text.TextPaint; import android.util.AttributeSet; import android.widget.TextView; diff --git a/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/PaintCache.java b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/PaintCache.java index 2976ef57..0fa57f4d 100644 --- a/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/PaintCache.java +++ b/dragbutton/src/main/java/org/solovyev/android/views/dragbutton/PaintCache.java @@ -191,11 +191,15 @@ class PaintCache { paint.setTypeface(spec.typeface); } paint.setTextSize(spec.textSize); - if (spec.highContrast && spec.needsShadow()) { - paint.setShadowLayer(shadowRadius, 0, 0, BLACK); - } else { - paint.setShadowLayer(0, 0, 0, BLACK); - } + setHighContrast(paint, spec.highContrast, spec.color); return paint; } + + public static void setHighContrast(@NonNull Paint paint, boolean highContrast, @ColorInt int color) { + if (highContrast && Spec.needsShadow(color)) { + paint.setShadowLayer(get().shadowRadius, 0, 0, BLACK); + } else { + paint.clearShadowLayer(); + } + } }