Add high-contrast shadow to the main text in DirectionDragButton

This commit is contained in:
Sergey Solovyev 2018-04-29 19:22:15 +02:00
parent 68cded37d9
commit a3c6d21a52
3 changed files with 11 additions and 5 deletions

View File

@ -90,5 +90,6 @@ public class DirectionDragButton extends DragButton implements DirectionDragView
@Override @Override
public void setHighContrast(boolean highContrast) { public void setHighContrast(boolean highContrast) {
textView.setHighContrast(highContrast); textView.setHighContrast(highContrast);
PaintCache.setHighContrast(getPaint(), highContrast, getTextColors().getDefaultColor());
} }
} }

View File

@ -5,6 +5,7 @@ import android.graphics.Canvas;
import android.graphics.Typeface; import android.graphics.Typeface;
import android.support.annotation.NonNull; import android.support.annotation.NonNull;
import android.support.annotation.Nullable; import android.support.annotation.Nullable;
import android.text.TextPaint;
import android.util.AttributeSet; import android.util.AttributeSet;
import android.widget.TextView; import android.widget.TextView;

View File

@ -191,11 +191,15 @@ class PaintCache {
paint.setTypeface(spec.typeface); paint.setTypeface(spec.typeface);
} }
paint.setTextSize(spec.textSize); paint.setTextSize(spec.textSize);
if (spec.highContrast && spec.needsShadow()) { setHighContrast(paint, spec.highContrast, spec.color);
paint.setShadowLayer(shadowRadius, 0, 0, BLACK);
} else {
paint.setShadowLayer(0, 0, 0, BLACK);
}
return paint; 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();
}
}
} }